472,778 Members | 2,514 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,778 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 14222
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.