473,495 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 14358
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
1573
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
1454
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
1813
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
5203
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
4661
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
3945
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
768
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
10674
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
4882
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
4979
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
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.