Address parameter in WebClient.UploadFile?

  • Thread starter Thread starter linn
  • Start date Start date
L

linn

The 'Address' parameter in the WebClient.UploadFile usually comes in
the form of ie. http://server/Upload_File.aspx

Hence my question, what is exactly the content of this
Upload_File.aspx? 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.
 
Play with this.....

Friend Function UploadFile(ByVal SourceLocation As String, ByVal
DestinationLocation As String, ByRef ProgressBar As
System.Windows.Forms.ProgressBar) 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
DestinationLocation.ToString.Trim <> "" Then
'To set Upload settings
Dim UploadRequest As System.Net.HttpWebRequest =
CType(System.Net.WebRequest.Create(New
Uri(DestinationLocation.ToString.Trim)), System.Net.HttpWebRequest)
UploadRequest.Timeout = 60000000
UploadRequest.Method = "PUT"
UploadRequest.ContentLength = New
System.IO.FileInfo(SourceLocation.ToString.Trim).Length
FileSize = UploadRequest.ContentLength.ToString.Trim
'To set Upload Stream settings
Dim SourceStream As New
System.IO.FileStream(SourceLocation.ToString.Trim, System.IO.FileMode.Open,
System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite)
Dim RequestStream As System.IO.Stream =
UploadRequest.GetRequestStream()
Dim Buffer(4095) As Byte
Dim Position As Integer = 0, ivlLoop As Integer = 0,
CurLocation As Integer = 0
Position = SourceStream.Read(Buffer, 0, Buffer.Length)
ProgressBar.Visible = True
ProgressBar.Value = 0
ProgressBar.Maximum = 100
While Position <> 0
RequestStream.Write(Buffer, 0, Position)
Position = SourceStream.Read(Buffer, 0, Buffer.Length)
CurLocation += Position
ProgressBar.Value = CInt((CurLocation / FileSize) * 100)
ProgressBar.Refresh()
End While


Dim WebResponse As System.Net.HttpWebResponse =
CType(UploadRequest.GetResponse(), System.Net.HttpWebResponse)
Dim ResponseReader As New
System.IO.StreamReader(WebResponse.GetResponseStream())
Response = ResponseReader.ReadToEnd()
UploadFile = True
RequestStream.Close()
UploadRequest = Nothing
SourceStream = Nothing
RequestStream = Nothing
WebResponse = Nothing
ResponseReader = Nothing
ElseIf SourceLocation.ToString.Trim = "" Then
MsgBox("Source Location is missing", "UploadFile")
ElseIf DestinationLocation.ToString.Trim = "" Then
MsgBox("Destination Location is missing", "UploadFile")
End If
Catch ex As Exception
MsgBox(ex.ToString)
Exit Function
End Try
'ProgressBar.Visible = False
End Function
 
Thanks for your help.

However, for the input parameter --> 'DestinationLocation' , I have
supplied something like 'http://127.0.0.1/temp/' and I received a
remote server returned an error: 405 Method not allowed.

Is my DestinationLocation --> 'http://127.0.0.1/temp/' wrongly
specified or could it be due to some other reason.

Appreciate your advice.

Thanks.
 
Try using your actual IP address instead.

Here are some steps to see if IIS is configured properly.

Go to "Control Panel"-"Administrative Tools"-"Internet Information
Services".

Expand the tree to "COMPUTERNAME"-"Web Sites"-"Default Web Site".

Right-click on "Default Web Site" and select "Properties".

Select the "Home Directory" tab.

Click the "Configuration" button.

From the "Mappings" tab, select the "Add" button.

Click the "Browse..." button, choose "Dynamic Link Libraries *.dll" from the
"Files of Type" dropdown, and select c:\WINDOWS\System32\inetsrv\asp.dll.

Type ".html" (without quotes) in the "Extension" box.

Select the "Limit to:" radio button, and type in "GET, POST" (without
quotes) in the box next to it.

Click the "OK" button and close all the dialogs. (If the "OK" button is
greyed out, then make sure all the entries are correct and try clicking in
the file name box.)
 
OK. Contact me on my site (my email link is there) and I will arrange a app
sharing with you to see if we cna get to the bottom of this.
 
Back
Top