0

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?

2
  • From folder in desktop to the another folder in disc D:\ . Commented Jul 28, 2012 at 11:49
  • 2
    File.Copy should do. Select the file using FileDialog. Commented Jul 28, 2012 at 11:51

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Hmm.. I hope you were referring to UPLOADING a file and not Loading a file from the local computer ;)
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.