473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

WebClient.UploadFile

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.

Nov 23 '05 #1
1 14335
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");

"JoshP" wrote:
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.

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: belfast neil | last post by:
Hey guys, I've seen alot of questions out there about webclient.uploadfile, my question is slightly different.......... I have a rich client app and I want to upload files to a server....
0
by: David W | last post by:
I am trying to upload a file from a user's system to my web server. I found code using the WebClient.UploadFile method. However, the uploaded file is from the server's hard drive not the user's...
0
by: Saverio Tedeschi | last post by:
Hi all gurus, forgive me if I submit a 2nd post, but I'm no more able to see my question. So: I wrote an Win app with embedded FTP client (well, made some cut and paste from others' projects :-))...
1
by: Phillip N Rounds | last post by:
I'm having problems using the WebClient.UploadFile() command. I have MySender.ASPX which is supposed to upload two files to the server. There is also ConsumeFileUpload.aspx which is intended to...
5
by: linn | last post by:
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...
2
by: UJ | last post by:
I'm trying to upload stuff using the UploadFile from WebClient and I've noticed that it adds header and footers to the stream. Is there any way to get rid of that automatically? I'm using...
0
by: Mihaly | last post by:
I have a WinForms 1.1 application and I want to post some files on the webserver, using WebClient.UploadFile() method. I try the solution from MSDN site -...
5
by: Svinja | last post by:
Hi, i am using WebClient.UploadFile to upload a file on my web page, code: WebClient webClient = new WebClient(); webClient.Credentials = new NetworkCredential(userName, pass);...
6
by: =?Utf-8?B?U2NvdHQgVHJpY2s=?= | last post by:
I followed the instructions from MSDN for Webclient UploadFile and I get an error: Could not find file 'C:\testfile.xls'. If I add the file (c:\testfile.xls) to the server I do not get the error...
5
by: benmess | last post by:
This code snippet works fine on a localhost because the file you upload resides on the host machine (where FileServer.aspx is a new page invoked from the UploadFile call) function...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.