Uploading file problem [modified]
-
Hi everyone, I'm trying to upload an *.xml file to my server and this is the code I'm using. The problem I have is that I get a 403 error every time, even though my folder permissions are correct and my authentications are correct as well. Just wondering if I'm doing something wrong with my code.
If File.Exists("C:\Documents and Settings\Denis\Desktop\GetFileTest\test.xml") Then
Dim remoteUri As String = "http://www.site.com/folder/"
Dim fileName As String = "C:\Documents and Settings\Denis\Desktop\GetFileTest\test.xml"
' Create a new WebClient instance.
Dim myWebClient As New WebClient
myWebClient.Credentials = New NetworkCredential("username", "password", "http://www.site.com/")
Try
' The UploadFile() method uploads the current file to the Web resource-system folder.
myWebClient.UploadFile(remoteUri, fileName)
Label.Text = "Done!"
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
Label.Text = "No Go!"
End IfThanks for any help ~D~
modified on Friday, February 22, 2008 11:33 AM
-
Hi everyone, I'm trying to upload an *.xml file to my server and this is the code I'm using. The problem I have is that I get a 403 error every time, even though my folder permissions are correct and my authentications are correct as well. Just wondering if I'm doing something wrong with my code.
If File.Exists("C:\Documents and Settings\Denis\Desktop\GetFileTest\test.xml") Then
Dim remoteUri As String = "http://www.site.com/folder/"
Dim fileName As String = "C:\Documents and Settings\Denis\Desktop\GetFileTest\test.xml"
' Create a new WebClient instance.
Dim myWebClient As New WebClient
myWebClient.Credentials = New NetworkCredential("username", "password", "http://www.site.com/")
Try
' The UploadFile() method uploads the current file to the Web resource-system folder.
myWebClient.UploadFile(remoteUri, fileName)
Label.Text = "Done!"
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
Label.Text = "No Go!"
End IfThanks for any help ~D~
modified on Friday, February 22, 2008 11:33 AM
Darshon wrote:
myWebClient.Credentials = New NetworkCredential("username", "password", "http://www.site.com/")
You're specifying the domain as a URI. What this parameter should contain in the domain of the credentials you type into the Username/Password/Domain box when it shows up, if you did this manually. The domain it wants is the Windows domain where the User account is stored, not a URI. For most public websites, the domain box is left blank. So, try it without the domain parameter.
myWebClient.Credentials = New NetworkCredential("username", "password")
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Darshon wrote:
myWebClient.Credentials = New NetworkCredential("username", "password", "http://www.site.com/")
You're specifying the domain as a URI. What this parameter should contain in the domain of the credentials you type into the Username/Password/Domain box when it shows up, if you did this manually. The domain it wants is the Windows domain where the User account is stored, not a URI. For most public websites, the domain box is left blank. So, try it without the domain parameter.
myWebClient.Credentials = New NetworkCredential("username", "password")
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Hi Dave, Thanks for the explaination. :) I did try it without the domain but it still gave me the same 403 error. I'm quite puzzled, this should work. Could it be something wrong with my server? I can upload files through an ftp program, is there a way to upload a file through ftp within the 1.1 framework? ~D~