file upload

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2007
Posts: 192
Reputation: plusplus is an unknown quantity at this point 
Solved Threads: 16
plusplus plusplus is offline Offline
Junior Poster

file upload

 
0
  #1
Jun 30th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 51
Reputation: martonx is an unknown quantity at this point 
Solved Threads: 8
martonx martonx is offline Offline
Junior Poster in Training

Re: file upload

 
0
  #2
Jun 30th, 2009
You should use only this line:

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

:-)
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 493
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: file upload

 
0
  #3
Jul 1st, 2009
plusplus & martonx.

You are requested to use BB code tags.

  1. My.Computer.Network.UploadFile("source file path","destination address")
Last edited by adatapost; Jul 1st, 2009 at 4:14 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 192
Reputation: plusplus is an unknown quantity at this point 
Solved Threads: 16
plusplus plusplus is offline Offline
Junior Poster

Re: file upload

 
0
  #4
Jul 1st, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 192
Reputation: plusplus is an unknown quantity at this point 
Solved Threads: 16
plusplus plusplus is offline Offline
Junior Poster

Re: file upload

 
0
  #5
Jul 1st, 2009
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

  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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC