File Upload issues with WebClient.UploadFile

  • Thread starter Phillip N Rounds
  • Start date
P

Phillip N Rounds

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();
}
 
B

Bruce Barker

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 said:
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();
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top