Play with this.....
Friend Function UploadFile(ByVa l SourceLocation As String, ByVal
DestinationLoca tion As String, ByRef ProgressBar As
System.Windows. Forms.ProgressB ar) As Boolean
Dim StartTime As DateTime = DateTime.Now()
Dim Response As String = Nothing, FileSize As Double = 0
Try
UploadFile = False
If SourceLocation. ToString.Trim <> "" And
DestinationLoca tion.ToString.T rim <> "" Then
'To set Upload settings
Dim UploadRequest As System.Net.Http WebRequest =
CType(System.Ne t.WebRequest.Cr eate(New
Uri(Destination Location.ToStri ng.Trim)), System.Net.Http WebRequest)
UploadRequest.T imeout = 60000000
UploadRequest.M ethod = "PUT"
UploadRequest.C ontentLength = New
System.IO.FileI nfo(SourceLocat ion.ToString.Tr im).Length
FileSize = UploadRequest.C ontentLength.To String.Trim
'To set Upload Stream settings
Dim SourceStream As New
System.IO.FileS tream(SourceLoc ation.ToString. Trim, System.IO.FileM ode.Open,
System.IO.FileA ccess.Read, System.IO.FileS hare.ReadWrite)
Dim RequestStream As System.IO.Strea m =
UploadRequest.G etRequestStream ()
Dim Buffer(4095) As Byte
Dim Position As Integer = 0, ivlLoop As Integer = 0,
CurLocation As Integer = 0
Position = SourceStream.Re ad(Buffer, 0, Buffer.Length)
ProgressBar.Vis ible = True
ProgressBar.Val ue = 0
ProgressBar.Max imum = 100
While Position <> 0
RequestStream.W rite(Buffer, 0, Position)
Position = SourceStream.Re ad(Buffer, 0, Buffer.Length)
CurLocation += Position
ProgressBar.Val ue = CInt((CurLocati on / FileSize) * 100)
ProgressBar.Ref resh()
End While
Dim WebResponse As System.Net.Http WebResponse =
CType(UploadReq uest.GetRespons e(), System.Net.Http WebResponse)
Dim ResponseReader As New
System.IO.Strea mReader(WebResp onse.GetRespons eStream())
Response = ResponseReader. ReadToEnd()
UploadFile = True
RequestStream.C lose()
UploadRequest = Nothing
SourceStream = Nothing
RequestStream = Nothing
WebResponse = Nothing
ResponseReader = Nothing
ElseIf SourceLocation. ToString.Trim = "" Then
MsgBox("Source Location is missing", "UploadFile ")
ElseIf DestinationLoca tion.ToString.T rim = "" Then
MsgBox("Destina tion Location is missing", "UploadFile ")
End If
Catch ex As Exception
MsgBox(ex.ToStr ing)
Exit Function
End Try
'ProgressBar.Vi sible = False
End Function
--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com
"linn" <ta***@ccn.com. sg> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
The 'Address' parameter in the WebClient.Uploa dFile usually comes in
the form of ie. http://server/Upload_File.aspx
Hence my question, what is exactly the content of this
Upload_File.asp x? Am i supposed to create this file with some specific
codes?
Can't seems to get this method working for me in framework 2.0..
Thanks for any help.