943,568 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 5943
  • VB.NET RSS
Jun 30th, 2009
0

file upload

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Jun 30th, 2009
0

Re: file upload

You should use only this line:

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

:-)
Reputation Points: 10
Solved Threads: 8
Junior Poster in Training
martonx is offline Offline
51 posts
since May 2008
Jul 1st, 2009
0

Re: file upload

plusplus & martonx.

You are requested to use BB code tags.

VB.NET Syntax (Toggle Plain Text)
  1. My.Computer.Network.UploadFile("source file path","destination address")
Last edited by adatapost; Jul 1st, 2009 at 4:14 am.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 1st, 2009
0

Re: file upload

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?
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Jul 1st, 2009
0

Re: file upload

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

VB.NET Syntax (Toggle Plain Text)
  1. 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?
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Mar 10th, 2010
0
Re: file upload
Click to Expand / Collapse  Quote originally posted by adatapost ...
plusplus & martonx.

You are requested to use BB code tags.

VB.NET Syntax (Toggle Plain Text)
  1. 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
Last edited by bhagyeshsc; Mar 10th, 2010 at 2:25 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bhagyeshsc is offline Offline
1 posts
since Mar 2010
Mar 10th, 2010
0
Re: file upload
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.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in VB.NET Forum Timeline: Make a 2D Array from Ms Access Table
Next Thread in VB.NET Forum Timeline: sql connectivity problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC