WebClient.UploadFile

G

Guest

Hi All, I am attemting to setup an file upload page in asp.net C# 2005 .net
2.0. I am receiving an "The remote server returned an error: (401)
Unauthorized." error when uploading. Here is my code:

System.Net.WebClient oWebClient = new System.Net.WebClient();
byte[] btResponse =
oWebClient.UploadFile("http://localhost/foo/getupload.aspx", "POST",
"c:\\test.txt");


*****And the receiving code*******
protected void Page_Load(object sender, EventArgs e)
{
foreach (string f in Request.Files.AllKeys)
{
HttpPostedFile file = Request.Files[f];
file.SaveAs("C:\\inetpub\\wwwroot\\foo\\upload\\" +
file.FileName);
}
}

I have given "everyone" full control and write permissions within IIS to the
"upload" folder located at C:\inetpub\wwwroot\foo\upload\. Please help. I
have spent hours online trying to figure out what I am doing wrong. Thanks.
 
G

Guest

I was able to figure this one out (after hours). I Should have known to use
<identity impersonate="true" userName="joeblow" password="123456" /> and
System.Net.NetworkCredential oNC = new
System.Net.NetworkCredential("username", "password", "domain name");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top