I want to open the directory of server computer using FolderBrowserDialog from the client machine.
Is it possible?
I have searched for it n haven't found the solution.
I have found others such as to browse Network Folders, here: How-to-Browse-Network-Folders-using-Folder-Dialog .
But i am looking for to browse the directory of server from the client.
here is a snippet that works fine with .net 4:
Dim dlg As New FolderBrowserDialog()
dlg.SelectedPath = "\\yourServer\share"
If dlg.ShowDialog() = DialogResult.OK Then
Dim selected = dlg.SelectedPath
' ...
End If
no need for RootFolder or any hacking - this will open the dialog on my computer (both client/server are windows-OS in a windows-domain) at the network-share and let my trill down into the folders there - at the end you will get a string like \\yourServer\share\selected\path back
Related
I have just installed the WinSCP library inside my VB project so I can use FTPS to transfer application files to/from a server.
However, and I apologize for my lack of knowledge, but how do I get their example code working in a practical setting?
I need to modify their code to use FTP with TLS instead of FTP over SSH as seen in their example code below.
Imports WinSCP
Friend Class Example
Public Shared Function Main() As Integer
Try
' Setup session options
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
.HostName = "example.com"
.UserName = "user"
.Password = "mypassword"
.SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...="
End With
Using session As New Session
' Connect
session.Open(sessionOptions)
' Download files
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Binary
Dim transferResult As TransferOperationResult
transferResult =
session.GetFiles("/home/user/*", "d:\download\", False, transferOptions)
' Throw on any error
transferResult.Check()
' Print results
For Each transfer In transferResult.Transfers
Console.WriteLine("Download of {0} succeeded", transfer.FileName)
Next
End Using
Return 0
Catch e As Exception
Console.WriteLine("Error: {0}", e)
Return 1
End Try
End Function
End Class
This should work:
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Ftp
.HostName = "example.com"
.UserName = "user"
.Password = "mypassword"
.FtpSecure = FtpSecure.Explicit
End With
There seem to be no YouTube videos/forum posts on a good solution for this.
So here is my solution!
This is for all the current/future programmers!
In Visual Studio, go to Tools > Extension Manager... then install NuGet Package Manager, Restart Visual Studio.
Download and install WinSCP, then download the WinSCP NuGet package from HERE.
In Visual Studio right click on your project in the Solution Explorer then click on Manage NuGet Packages... then click on Settings in the bottom left.
Add the source (folder where you downloaded the WinSCP NuGet Package) then click OK.
Next, you will see WinSCP .NET assembly show up, click on it and hit Install.
Then make sure to add Imports WinSCP to the top of your project code.
After that you can code the functions for Connecting, Uploading, and Downloading.
Use their examples provided HERE
MASSIVE TIP: Use WinSCP to connect to your FTPS server, then click on the Session tab and click on Generate session URL/code.
Inside the new window that appears, select the .NET assembly code tab. Then make sure your programming language is selected in the Language drop down.
There it is! It will show you the session connection code for your FTPS server, just copy and paste that into Visual Studio.
From there, you will have to do the rest to modify their example code, and combine it with the session connection code that WinSCP gave you.
Happy Coding!
I'm trying to create a button in MS Access to open a Sharepoint folder in Windows Explorer, not Internet Explorer. I had it working momentarily, and don't know what broke. This currently opens the sharepoint folder in Internet Explorer.
Dim Foldername As String
Foldername = "http://vaww.visn21.portal.va.gov/sanfrancisco/education/EDADMIN/Service Timekeeping Records\"
Shell "C:\WINDOWS\explorer.exe """ & Foldername & "", vbNormalFocus
Edit: I have also tried this code, same effect where it opens it in internet explorer, not windows explorer.
Dim path As String
path = "http://vaww.visn21.portal.va.gov/sanfrancisco/education/EDADMIN/Service Timekeeping Records\"
Shell "cmd /C start """" /max """ & path & """", vbHide
End Sub
Edit 2 : Tried this code, still just opens internet explorer instead of windows explorer
Call Shell("explorer """"" & "http://vaww.visn21.portal.va.gov/sanfrancisco/education/EDADMIN/Service Timekeeping Records\" & """""", vbNormalFocus)
Ideally this will be used as the primary interface to access these folders once their names are changed to program numbers instead of program names (And thus the links won't break every time a program name changes).
So I don't know WHY this works, I think it has something to do with the difference between forward slashes and backslashes, but here's the code that wound up working. This code checks to see if a particular folder exists, creates the folder if it does not, and then tries to open the folder in Windows Explorer, not internet explorer.
Private Sub ButtonMkDirTest_Click()
myWorkBookBasePath = "\\vaww.visn21.portal.va.gov\sanfrancisco\education\EDADMIN\TESTFOLDER"
If Len(Dir(myWorkBookBasePath, vbDirectory)) = 0 Then
MkDir myWorkBookBasePath
End If
Dim path As String
path = myWorkBookBasePath
Shell "cmd /C start """" /max """ & path & """", vbHide
End Sub
Watch out for that http protocol, it'll kill you every time!
No one else seems interested in this topic, probably for the best of reasons. You have to be - politely put - eccentric to try to open an internet address with a local disk utility.
Windows Explorer is designed to open local folders only. Windows is designed around a series of protocols, principally the http: protocol, but also the file: protocol. There are others, but for the current topic those are the important two.
The http: protocol is designed to open Internet Explorer, and the file: protocol is designed to open Windows Explorer. There are a whole bunch of Registry keys which control this behaviour.
In the current question, the poster has specified http: as part of the target address, in the case which resulted in Internet Explorer opening. That occurred even though Internet Explorer was not specified on the command line, because when Windows encounters a http: address, the Registry is set up to cause Internet Explorer to run.
In the second case, where the o/p was puzzled by Windows Explorer opening, if you look closely at his second command you'll notice that this 2nd command does not expressly mention http: in the command, which was why the http: protocol did not take over the handling of the command (so Internet Explorer was not called).
I have following network location
Dim myfolder As String = "\\10.0.0.90\myfolder\"
I am able to create a new file in this folder using following code:
File.Create (myfolder)
But when I try to read contents of this folder using code below I get error.
Code
Dim orderedFiles = New System.IO.DirectoryInfo(myfolder).GetFiles()
Error
The system detected a possible attempt to compromise security. Please
ensure that you can contact the server that authenticated you.
File writing is being done by ASP.Net page while reading is done from Windows Service. Could this be the issue?
Windows Service was running as "Local System". I right click on it, went into properties and changed the "Log on as" to some user account and now it can access network folder.
I have a particular file which needs to be sent to a share drive location through FTP.
I know there is a method by writing contents on a flat file and executing with shell script. Sadly that is not working since my send location is weird and I don't know how to interpret it, its like this.
//corporate.abc.com/data/ac/ny/log
I have no idea what the above thing means. Is there any way to send data to that location?
PS: I opened it through my Windows Run command and its opening up. It is not asking for any user authentication.
Update: I tried to open using explorer but I am getting error" runtime error 75 , path/file access error"
Sub FtpFileto()
Dim vFile As String
Dim vFTPServ As String
Dim fNum As Long
vPath = "C:\macro/pop.txt"
vFile = "C:\macro/post.xlsx"
vFTPServ = "corporate.abc.com"
Open "//corporate.abc.com/data/NA/US/OC/Common/HOSTDL/CatSpec" For Output As #1
Close
Shell "ftp -n -i -g -s:" & vPath & "\FtpComm.txt " & vFTPServ, vbNormalNoFocus
End Sub
If the UNC path can be opened in Windows Explorer, it means that it is directly accessible and can be worked with as if it were a local path.
Open "\\corporate.abc.com\data\ac\ny\log\test.ext" For Output As #1
Write #1, Data
Close #1
You do not need (cannot) use FTP to work with it.
Note that the UNC is a Windows convention, so it uses backslashes, not forward slashes (though in many cases Windows will accept the forward slashes too).
I am currently trying to open a file on my web app by retrieving the file path from a sql database
here is my code that will open the file when I double click an index in a listbox.
Protected Sub userdoubleClick()
Dim selectedPath As String
Try
fileConnection.Open()
selectedFile = FileListBox.SelectedValue
'takes the selected items from the listbox and searches the database for the file
'and will open the file for the user
fileCommand.CommandText = "SELECT filePath FROM ImportedFiles WHERE FileName = '" & selectedFile & "'"
fileDataReader = fileCommand.ExecuteReader
Do While fileDataReader.Read
selectedPath = fileDataReader.GetValue(0)
Loop
System.Diagnostics.Process.Start(selectedPath)
Catch ex As Exception
End Try
fileConnection.Close()
End Sub
When I run this on my local PC it works fine but then when I publish it to a server it wont open the file.
System.Diagnostics.Process.Start(selectedPath) will open the file on the machine running the web application; in other words, it is opening it on your local machine when running locally, but opening on the server when deployed. This just isn't going to work.
See ASP.Net Download file to client browser
If you're accessing the files from a web application, then the user identity under which the file is opened is not that of the user logged into your application. It's the user under which the IIS application pool is running. That's the user that needs to have permission granted to your shared drive.
There are many solutions to this problem, including changing the context under which the application pool is running or making the files local.