how to browse folder inside my project and explorer it - vb.net

I have a 2form windows application one of them I want to use it like a Cylinder
(Programs and tools)
I am succeeded to add my file(and his sub folders) to my Resources
I named the button (ExeinfoPe
and these in Event of the button:
My.Computer.Audio.Play(My.Resources.Click1, AudioPlayMode.Background)
Dim appPath As String = My.Application.Info.DirectoryPath & "\" & "ExeinfoPe"
My.Computer.FileSystem.WriteAllBytes(appPath, My.Resources.ExeinfoPe, True)
Process.Start("ExeinfoPe\")
and this is the result is browser came with choose the application extension
and refused to browsed with explorer.exe
how can I explorer this folder who is inside my application
and can I moved in different application directory like (bin-release)

Related

Saving image from php id URL using webbrowser in VB.net

I am trying to save a image from webbrowser but can't find an answer for it.
Example of the problem is the URL is hxxp://domain[.]com/image/?img=1234 on webbrowser it shows the image and the source is <img src='hxxp://domain[.]com/image/?img=1234'>..
I was unable to save it using the My.Computer.Network.DownloadFile and MemoryStream(tClient.DownloadData methods.
In order to download the file, I will need to session cookie also?
How can I do this?
Any image that you see in the WebBrowser has already been downloaded to your computer. It is normally cached in the folder:
C:\Users\<username>\AppData\Local\Microsoft\Windows\Temporary Internet Files
or whatever other folder is set in Internet Options. You can get your image from that folder.
The following program shows how to copy file TDAssurance_Col.png from the Temporary Internet Files folder to the C:\Temp folder.
Module Module1
Sub Main()
CopyFileFromTemporaryInternetFolder("TDAssurance_Col.png", "C:\Temp")
End Sub
Public Sub CopyFileFromTemporaryInternetFolder(filename As String, destinationFolder As String)
' Search actual path of filename.
Dim temporaryInternetFilesFolder As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), "Content.IE5")
Dim pattern As String = Path.GetFileNameWithoutExtension(filename) & "*" & Path.GetExtension(filename)
Dim pathnames() As String = Directory.GetFiles(temporaryInternetFilesFolder, pattern, SearchOption.AllDirectories)
' If file found, copy it.
If pathnames.Count > 0 Then
File.Copy(pathnames(0), Path.Combine(destinationFolder, filename))
End If
End Sub
End Module

VB.NET How to Get Path of Opened Folder?

I'm trying to implement a VB.NET script which shows the full path of the opened folder when clicking right click inside it (not selecting its name),
I attached a screenshot to explain myself.
Now, I already know how to do it when selecting either a file or a folder,,
I found questions here about getting all active/opened windows, but that's not my target. I just want the full path of a specific folder where I right clicked.
So for example, If I click the option "sPaste", I should get a messagebox with the text "C:\test"
Sub Main(ByVal args As String())
Dim path as a String = ""
For Each arg As String In args
path = path & " " & arg & ""
Next arg
Messagebox.show(path)
End Sub
Sending the argument %1 to my app as it for the filename or the folder would not work here because there is nothing selected.
Thanks.

VBA: Get Excel FileDialogOpen to point to "My Computer" by default

I'm trying to get excels save and open dialog boxes to open to "my computer" by default so the user can select a drive from there.
I have got the dialog boxes to open to any path on any drive or my documents etc but can't seem to find a way for it to open to my computer.
This is the code i'm using at the moment and it works fine for a known path:
MsgBox objFolders("desktop")
ChDrive objFolders("desktop")
ChDir objFolders("desktop")
strFileName = appRemoteApp.Workbooks("Export Template.xlsm").Application.GetSaveAsFilename(objFolders("desktop") & "\Replica Export " & UserName & " " & Format(Date, "yymmdd") & ".xlsm", FileFilter:="Excel Macro Enabled Workbook (*.xlsm), *.xlsm,")
Also, I have found this from this site.
If you paste ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} into windows explorers address bar it takes you to my computer but if I use this in my VBA code
ChDir "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
it says it cant find the directory or something. So not sure if there is a work around for this or something.
This did not work either:
ChDir "C:\WINDOWS\explorer.exe /root,,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
The reason i'm wanting to have the dialog boxs open to computer is that we will be hosting the excel doc on a windows server with access though RemoteApp and remote desktop. The users will not have access (rights) to the servers drives and folders etc, they will only have access to their own drives on their local machines which will be mapped and are visible under the servers "My Computer" folder for lack of a better word. The master document on the server generates a replica using VBA code and is then saved to the users local hard drive.
AFAIK there is no pure VBA solution to override the original behaviour. You can use an alternative from Robert Mearns answer but it doesn't show the windows form so it's less customizable.
Follow this answer if you want to achieve the exact effect - FileOpenDialog.
You can print all the environmental variables using the Environ$() function. This will not show any variable directly pointing to MyComputer therefore you can't pass it to the .InitialFileName property.
MyComputer is not a physical location that you can access through cmd. I think of it as an abstract Interface and it's quite difficult to explain how VBA and .InitialFileName uses a string to access a location.
Well, the only workaround the problem I can think of it's to use an external library written in for example C# that can access the MyComputer.
It's easier than it sounds!
Follow the below steps to create your Custom OpenFileDialog.
You need a Visual Studio Express For Desktop - it's free to download and use.
After installation - run as Administrator! (it's necessary for the libraries to get registered)
Select File and New Project. Rename it to CustomOFD and and hit the OK.
Right-click the CustomOFD Project in the Solution Explorer and Select Add References
Add references to the System.Windows.Forms as shown in the below img
Right-click Class1.cs in the Solution Explorer and rename it to CustomOFD.cs.
Double click your CustomOFD and replace the code with the one from below
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CustomOpenFileDialog
{
[InterfaceType(ComInterfaceType.InterfaceIsDual),
Guid("541EDD34-4CDC-4991-82E9-6FC23F904B5B")]
public interface ICustomOFD
{
DialogResult ShowDialog();
string FileName();
}
[ClassInterface(ClassInterfaceType.None)]
[Guid("E33102F0-B3C0-441C-8E7A-B9D4155A0D91")]
public class CustomOFD : ICustomOFD
{
private OpenFileDialog box = new OpenFileDialog();
public CustomOFD()
{
box.Multiselect = false;
box.Title = "Select file";
box.InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
}
public DialogResult ShowDialog()
{
return box.ShowDialog();
}
public string FileName()
{
return box.FileName;
}
}
}
Note: you can generate a new GUID for your own class using the Tools => Create GUID and replace it with your own, if you wanted to...
Right-click the CustomFileOpenDialog in the Solution Explorer and select Properties
In the Properties window go to Application tab and click Assembly Info and tick the Make COM-Visible box
Then go to the Build tab and tick Register for COM interop
Right-click the project and select Build from the menu
Now look in the Output tab as it shows you where the library was compiled to
usually its
c:\users\administrator\documents\visual studio 2012\Projects\CustomOpenFileDialog\CustomOpenFileDialog\bin\Debug\CustomOpenFileDialog.dll
Ok. Now save and close VS.
Open Excel and go into VBE ALT+F11 and insert a standard module
Click Tools on the menu bar and select References
Click the Browse button and navigate to the CustomOpenFileDialog.tlb file and click OK add to the list of references
Copy paste the code for module
Option Explicit
Sub Main()
Dim ofd As New CustomOFD
Set ofd = New CustomOFD
ofd.ShowDialog
Debug.Print ofd.Filename
End Sub
finally, run the sub and enjoy the computer as the default location for the customized OpenFileDialog box!
I cannot see a way to use the GetSaveAsFilename or similar dialogs to open on Computer or My Computer.
It is possible to prompt the user to select a folder using VB Script.
The root displayed is Computer and the user can select a folder.
The file can then be saved to the selected folder programatically.
Sub Test()
MsgBox BrowseForFolder(MyComputer)
End Sub
http://technet.microsoft.com/library/ee176604.aspx
Function MyComputer() As Variant
Dim objShell As Object, objFolder As Object
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(&H11&)
MyComputer = objFolder.self.Path
Set objShell = Nothing
Set objFolder = Nothing
End Function
http://www.vbaexpress.com/kb/getarticle.php?kb_id=405
Function BrowseForFolder(Optional OpenAt As Variant) As Variant
Dim ShellApp As Object
Set ShellApp = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please choose a folder", 0, OpenAt)
On Error Resume Next
BrowseForFolder = ShellApp.self.Path
On Error GoTo 0
Set ShellApp = Nothing
End Function
.InitialFileName = "Computer"
Works for me with FileDialog(msoFileDialogFolderPicker)
Tested on Windows Vista - Excel 2007

How to open file located inside winform project

I have a project that requires some pdf reports to be opened from my forms. Since the program can be installed in any drive, I used the winform location directory as my path. I reports are located on a directory called Reports. It works well under development becuase I the winform is under bin\debug, but when I deploy my solution and try the procedure, it does not work, the file cannot be found. I created a Reports directory after deployment, but still did not find my pdf.
Here is the code:
'Open the requested file name. The files are stored in the
'same path as the main workbook.
'#param filename file to be opened
Function OpenReports(strFileName As String) As String
Dim reportFolder As String
Try
reportFolder = Path.Combine(Directory.GetCurrentDirectory(), "Reports")
System.Diagnostics.Process.Start(reportFolder & "\" & strFileName)
Catch ex As Exception
MsgBox("The " & strFileName & " is not found on directory")
End Try
Return strFileName
End Function
Private Sub btnRptRangesToMarket_Click(sender As Object, e As EventArgs) Handles btnRptRangesToMarket.Click
'This procedure runs when the btnRptRangesToMarket is clicked
'the procedure opens the pdf below by running the OpenReports Function
OpenReports("Ranges to Market.pdf")
End Sub
Try Application.StartupPath instead of Directory.GetCurrentDirectory(). I always get good results with that property.
This is from MSDN:
The current directory is distinct from the original directory, which is the one from which the process was started.

VB.net Save File Dialogue error - Could not find special directory 'Desktop'

I have a fairly straight forward peice of code that just tries to set the default saved directory for a standard .net save dialogue to a specific folder. If that folder doesn't exist, it sets it to the desktop.
This works fine for everyone but one user who is getting the following error:
Could not find special directory 'Desktop'
How is that even possible?
'Check if folder exists
If Not IO.Directory.Exists(strDirectory) Then
strDirectory = FileIO.SpecialDirectories.Desktop
If Not IO.Directory.Exists(strDirectory) Then
strDirectory = IO.Directory.GetCurrentDirectory
End If
End If
'Show save file dialogue.
Dim folderDlg As New Windows.Forms.FolderBrowserDialog
folderDlg.RootFolder = Environment.SpecialFolder.Desktop
folderDlg.SelectedPath = strDirectory
folderDlg.ShowNewFolderButton = True
How about:
strDirectory = _
Environment.GetFolderPath(Environment.SpecialFolder.Desktop).ToString()
I use GetFolderPath() to get "My Documents" and it works fine (I don't ever have to think about it).