Reputation: 13636
Hello I'm newer in VB net and in WinForms so maybe my question will seem naive.
I am using .net2.
I need to upload a file to the WinForms application and store it in specific folder. In Web application I implemented it with help of the fileUpload Control.
Any idea how can I implement this in a WinForms application?
Upvotes: 0
Views: 2587
Reputation: 27342
Your question is confusing because you mentioned uploading whih would indicate transfer to/from an internet location but in your comment it appears you just want to copy a file from the desktop to the D drive.
This code should do what you want:
Dim sourceFile As String = Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "foo.txt")
Dim destinationFile As String = "D:\folder\foo.txt"
File.Copy(sourceFile, destinationFile)
Note: You can use the same code to copy a file in a web application you do not need to use a FileUpload control
Upvotes: 1
Reputation: 8031
A Simple way to Upload a file to a target URL is by using the UploadFIleAsync
function which can be found in System.Net.WebClient()
.
For example:
Dim WithEvents myClient As New System.Net.WebClient()
Public Function Upload(ByVal tURL As String, ByVal file As String) As Boolean
Dim uri As New System.Uri(tURL)
Me.myClient.UploadFileAsync(uri, file)
Return true 'Needs some modification, this is a simple code, but should work as it is
End Function
Upvotes: 2