954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

file upload

In my code I want to upload a file to my project(named Musiker), under the folder music. Here is what I did so far, it's not working.

'to get the path where to upload it, I did the following

Dim strpath As String = Application.StartupPath
Dim num As Integer = strpath.IndexOf("Musiker")
strpath = strpath.Remove(num + 7) & "\music"

'now I want to upload a file

Dim clsRequest As System.Net.FileWebRequest = (System.Net.WebRequest.Create(strpath))
clsRequest.Method = System.Net.WebRequestMethods.File.UploadFile

' read in file...
Dim bFile() As Byte = System.IO.File.ReadAllBytes("pathofFile")

' upload file...
Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Close()
clsStream.Dispose()

It gives me an error, access not allowed or something like that.

plusplus
Posting Whiz in Training
207 posts since Jul 2007
Reputation Points: 10
Solved Threads: 16
 

You should use only this line:

My.Computer.Network.UploadFile("source file path","destination address")

:-)

martonx
Junior Poster in Training
51 posts since May 2008
Reputation Points: 10
Solved Threads: 8
 

plusplus & martonx.

You are requested to use BB code tags.

My.Computer.Network.UploadFile("source file path","destination address")
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Let me change my question. Since I am new to vb.net, but worked in asp.net, I thought I have to upload the file. But really what I have to do, is save it to my project. So what I really needed was

File.Copy(sourceFile, destinationFile)

My question is, when using a path for the destination file, where would I put it, so that it should be part of my project?

plusplus
Posting Whiz in Training
207 posts since Jul 2007
Reputation Points: 10
Solved Threads: 16
 

Sorry, here with code tags

Let me change my question. Since I am new to vb.net, but worked in asp.net, I thought I have to upload the file. But really what I have to do, is save it to my project. So what I really needed was

File.Copy(sourceFile, destinationFile)


My question is, when using a path for the destination file, where would I put it, so that it should be part of my project?

plusplus
Posting Whiz in Training
207 posts since Jul 2007
Reputation Points: 10
Solved Threads: 16
 

plusplus & martonx.

You are requested to use BB code tags.

My.Computer.Network.UploadFile("source file path","destination address")


Can you give us example of the destination address with IP
as i am doing a project

bhagyeshsc
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

Welcome bhagyeshsc.

Have a look at MSDN article - http://msdn.microsoft.com/en-us/library/ms127893.aspx

Please read before posting - http://www.daniweb.com/forums/thread78223.html

Thread Closed.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You