473,395 Members | 1,931 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,395 software developers and data experts.

File Upload issues with WebClient.UploadFile

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 handle receipt of
the files. Pertinent code for each is below.

When I run the process locally in debug mode, everything works great (
VS.NET 2003 , ASP 1.1 ).
When I run locally on the server, everything works great.
When I try to remotely upload files, I get an error: THE REMOTE SERVER
RETURNED AN ERROR: (500) INTERNAL SERVER ERROR

I have given both ASPNET & NETWORK SERVICE Write/Modify permissions in the
target directory.

Any Suggestions

Button_Click in MySender.ASPX
{
string Small = "c:\\MySmall.jpg";
string Large = "c:\\MyBgPicture.jpg";
System.Net.WebClient MyWebClient = new System.Net.WebClient();
string URI="";
string SUBDIR = "";
util.GetLocationSettings( ref URI, ref SUBDIR);
string uri = URI + "/" + SUBDIR + "/ConsumeFileUpload.aspx";
uri.Replace("//","/");
try
{
byte[] by = MyWebClient.UploadFile( uri , "POST", this.Small);
byte[] by2 = MyWebClient.UploadFile( uri , "POST", this.Large);
}
catch ( Exception ex )
{
EventLog log = new System.Diagnostics.EventLog();
log.Source="LGS.AddProducts";
log.WriteEntry( ex.Message);
log.Close();
}
}

Page_Load code in my ConsumeFileUpload.ASPX

if ( util==null ) util = new Utilities();
string URI = "";
string SUBDIR = "";
util.GetLocationSettings( ref URI, ref SUBDIR ); //
Util.GetLocationSettings gets the Host Location Info, ultimately giving the
directory to save the file in. This is OK
SUBDIR = SUBDIR.Trim();
string path = "/" + SUBDIR + "/images/";
path.Replace("//","/");
// path is the path, relative to the host site, into which to put the
pictures.
HttpFileCollection files;
files = Page.Request.Files;
for(int index=0; index < files.AllKeys.Length; index++)
{
HttpPostedFile postedFile = files[index];
string fileName = null;
int lastPos = postedFile.FileName.LastIndexOf("\\");
if ( lastPos < 0) fileName = postedFile.FileName;
else { fileName = postedFile.FileName.Substring(++lastPos); }
// This gives us simply MyPicture.jpg
path = path.Trim();
fileName = fileName.Trim();
fileName = path + fileName;
string sMapPath = MapPath( fileName );
// This is where it tis to be saved, and gives the correct spot
:\inetpub\wwwroot\MySite\Images\MyPicure.jpg

EventLog log = new System.Diagnostics.EventLog();
log.Source="LGS.ConsumeUpload";
log.Log = "Application Log";
log.MachineName="CGIRemote2";
log.WriteEntry( "Saving: " + sMapPath, EventLogEntryType.Information);
sMapPath = sMapPath.Trim();
try
{ postedFile.SaveAs( MapPath( fileName ) ); }
catch ( Exception ex )
{
log.Source="MyIdentifier";
log.Log = "Application Log";
log.MachineName="MyHostName";
log.WriteEntry( "Exception:" + ex.Message, EventLogEntryType.Error);
log.WriteEntry( "MapPath: " + sMapPath, EventLogEntryType.Error );
}
log.Close();
}
Feb 2 '06 #1
1 5194
your remote server probably requires nt authenication. if you conect to your
webserver locally, it can use your network creditials because it has a
primary token. if it is not a local connection, then is has a secondary
token which can not be used for any network resource.

set you webserver to use a known domain accout with permission to the remote
server,. or switch to kerberos.

-- bruce (sqlwork.com)
"Phillip N Rounds" <pr*****@cassandragroup.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
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 handle receipt
of the files. Pertinent code for each is below.

When I run the process locally in debug mode, everything works great (
VS.NET 2003 , ASP 1.1 ).
When I run locally on the server, everything works great.
When I try to remotely upload files, I get an error: THE REMOTE SERVER
RETURNED AN ERROR: (500) INTERNAL SERVER ERROR

I have given both ASPNET & NETWORK SERVICE Write/Modify permissions in
the target directory.

Any Suggestions

Button_Click in MySender.ASPX
{
string Small = "c:\\MySmall.jpg";
string Large = "c:\\MyBgPicture.jpg";
System.Net.WebClient MyWebClient = new System.Net.WebClient();
string URI="";
string SUBDIR = "";
util.GetLocationSettings( ref URI, ref SUBDIR);
string uri = URI + "/" + SUBDIR + "/ConsumeFileUpload.aspx";
uri.Replace("//","/");
try
{
byte[] by = MyWebClient.UploadFile( uri , "POST", this.Small);
byte[] by2 = MyWebClient.UploadFile( uri , "POST", this.Large);
}
catch ( Exception ex )
{
EventLog log = new System.Diagnostics.EventLog();
log.Source="LGS.AddProducts";
log.WriteEntry( ex.Message);
log.Close();
}
}

Page_Load code in my ConsumeFileUpload.ASPX

if ( util==null ) util = new Utilities();
string URI = "";
string SUBDIR = "";
util.GetLocationSettings( ref URI, ref SUBDIR ); //
Util.GetLocationSettings gets the Host Location Info, ultimately giving
the directory to save the file in. This is OK
SUBDIR = SUBDIR.Trim();
string path = "/" + SUBDIR + "/images/";
path.Replace("//","/"); // path is the path, relative to the host site,
into which to put the pictures.
HttpFileCollection files;
files = Page.Request.Files;
for(int index=0; index < files.AllKeys.Length; index++)
{
HttpPostedFile postedFile = files[index];
string fileName = null;
int lastPos = postedFile.FileName.LastIndexOf("\\");
if ( lastPos < 0) fileName = postedFile.FileName;
else { fileName = postedFile.FileName.Substring(++lastPos); } //
This gives us simply MyPicture.jpg
path = path.Trim();
fileName = fileName.Trim();
fileName = path + fileName;
string sMapPath = MapPath( fileName ); // This is where it tis to be
saved, and gives the correct spot
:\inetpub\wwwroot\MySite\Images\MyPicure.jpg

EventLog log = new System.Diagnostics.EventLog();
log.Source="LGS.ConsumeUpload";
log.Log = "Application Log";
log.MachineName="CGIRemote2";
log.WriteEntry( "Saving: " + sMapPath, EventLogEntryType.Information);
sMapPath = sMapPath.Trim();
try
{ postedFile.SaveAs( MapPath( fileName ) ); }
catch ( Exception ex )
{
log.Source="MyIdentifier";
log.Log = "Application Log";
log.MachineName="MyHostName";
log.WriteEntry( "Exception:" + ex.Message,
EventLogEntryType.Error);
log.WriteEntry( "MapPath: " + sMapPath, EventLogEntryType.Error );
}
log.Close();
}

Feb 2 '06 #2

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

Similar topics

3
by: brianinbox | last post by:
Hi, I've been trying to upload file using webclient.uploadfile method from my IIS webserver to an Apache webserver without any success. On the Apache server (server that receives the incoming file)...
4
by: brianinbox | last post by:
Hi, I've been trying to upload file using webclient.uploadfile method from my IIS webserver to an Apache webserver without any success. On the Apache server (server that receives the incoming...
2
by: Federico Bari | last post by:
I have the necessity to send an xml file to a CGI application using the https protocol (then the CGI application have to store the datas of the xml file in a mySQL database). I saw the useful...
4
by: Shawn Mesiatowsky | last post by:
I have an html form that accepts a file for uploading, but I wanted to create a program to automate the upload procedure. I beileive you use the Webresponse class, but I was not sure how to use...
4
by: Grant Harmeyer | last post by:
When I try to upload a file to a resource on my local webserver, my code catches an exception that a 405 error (method not supported) has occured on the server. I set the code up nearly exactly as...
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...
5
by: shantanu | last post by:
Hi i am trying to upload a txt file thru this code, but its not updating the data. is this code fine. Or can anybody please suggest me some other meathod to do the same. its urgent please help ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...

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.