I'm having problems using the WebClient.Uploa dFile() command.
I have MySender.ASPX which is supposed to upload two files to the server.
There is also ConsumeFileUplo ad.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.jp g";
string Large = "c:\\MyBgPictur e.jpg";
System.Net.WebC lient MyWebClient = new System.Net.WebC lient();
string URI="";
string SUBDIR = "";
util.GetLocatio nSettings( ref URI, ref SUBDIR);
string uri = URI + "/" + SUBDIR + "/ConsumeFileUplo ad.aspx";
uri.Replace("//","/");
try
{
byte[] by = MyWebClient.Upl oadFile( uri , "POST", this.Small);
byte[] by2 = MyWebClient.Upl oadFile( uri , "POST", this.Large);
}
catch ( Exception ex )
{
EventLog log = new System.Diagnost ics.EventLog();
log.Source="LGS .AddProducts";
log.WriteEntry( ex.Message);
log.Close();
}
}
Page_Load code in my ConsumeFileUplo ad.ASPX
if ( util==null ) util = new Utilities();
string URI = "";
string SUBDIR = "";
util.GetLocatio nSettings( ref URI, ref SUBDIR ); //
Util.GetLocatio nSettings 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.
HttpFileCollect ion files;
files = Page.Request.Fi les;
for(int index=0; index < files.AllKeys.L ength; index++)
{
HttpPostedFile postedFile = files[index];
string fileName = null;
int lastPos = postedFile.File Name.LastIndexO f("\\");
if ( lastPos < 0) fileName = postedFile.File Name;
else { fileName = postedFile.File Name.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\wwwro ot\MySite\Image s\MyPicure.jpg
EventLog log = new System.Diagnost ics.EventLog();
log.Source="LGS .ConsumeUpload" ;
log.Log = "Applicatio n Log";
log.MachineName ="CGIRemote2 ";
log.WriteEntry( "Saving: " + sMapPath, EventLogEntryTy pe.Information) ;
sMapPath = sMapPath.Trim() ;
try
{ postedFile.Save As( MapPath( fileName ) ); }
catch ( Exception ex )
{
log.Source="MyI dentifier";
log.Log = "Applicatio n Log";
log.MachineName ="MyHostName ";
log.WriteEntry( "Exception: " + ex.Message, EventLogEntryTy pe.Error);
log.WriteEntry( "MapPath: " + sMapPath, EventLogEntryTy pe.Error );
}
log.Close();
} 1 5241
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*****@cassan dragroup.com> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. . I'm having problems using the WebClient.Uploa dFile() command. I have MySender.ASPX which is supposed to upload two files to the server. There is also ConsumeFileUplo ad.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.jp g"; string Large = "c:\\MyBgPictur e.jpg"; System.Net.WebC lient MyWebClient = new System.Net.WebC lient(); string URI=""; string SUBDIR = ""; util.GetLocatio nSettings( ref URI, ref SUBDIR); string uri = URI + "/" + SUBDIR + "/ConsumeFileUplo ad.aspx"; uri.Replace("//","/"); try { byte[] by = MyWebClient.Upl oadFile( uri , "POST", this.Small); byte[] by2 = MyWebClient.Upl oadFile( uri , "POST", this.Large); } catch ( Exception ex ) { EventLog log = new System.Diagnost ics.EventLog(); log.Source="LGS .AddProducts"; log.WriteEntry( ex.Message); log.Close(); } }
Page_Load code in my ConsumeFileUplo ad.ASPX
if ( util==null ) util = new Utilities(); string URI = ""; string SUBDIR = ""; util.GetLocatio nSettings( ref URI, ref SUBDIR ); // Util.GetLocatio nSettings 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. HttpFileCollect ion files; files = Page.Request.Fi les; for(int index=0; index < files.AllKeys.L ength; index++) { HttpPostedFile postedFile = files[index]; string fileName = null; int lastPos = postedFile.File Name.LastIndexO f("\\"); if ( lastPos < 0) fileName = postedFile.File Name; else { fileName = postedFile.File Name.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\wwwro ot\MySite\Image s\MyPicure.jpg
EventLog log = new System.Diagnost ics.EventLog(); log.Source="LGS .ConsumeUpload" ; log.Log = "Applicatio n Log"; log.MachineName ="CGIRemote2 "; log.WriteEntry( "Saving: " + sMapPath, EventLogEntryTy pe.Information) ; sMapPath = sMapPath.Trim() ; try { postedFile.Save As( MapPath( fileName ) ); } catch ( Exception ex ) { log.Source="MyI dentifier"; log.Log = "Applicatio n Log"; log.MachineName ="MyHostName "; log.WriteEntry( "Exception: " + ex.Message, EventLogEntryTy pe.Error); log.WriteEntry( "MapPath: " + sMapPath, EventLogEntryTy pe.Error ); } log.Close(); } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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) I have a
simple php script, getFile.php to receive the file. The script look
like this:
<?php
$uploadDir = '/var/www/Incoming/';
$uploadFile = $uploadDir . $_FILES;
print "<pre>";
|
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) I have a
simple php script, getFile.php to receive the file. The script look
like this:
<?php
$uploadDir = '/var/www/Incoming/';
$uploadFile = $uploadDir . $_FILES;
|
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 WebClient class for C#, but it
isn't explained in which variable i can find the file on the server side.
Can you help me? thank you! Federico.
|
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 this
class to post a file to a specified website. In some documentation I have,
it also specifies the Request Header must be: Content-type:
application/octet-stream
here is the web site html code:
<form action=post method=post...
|
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 it is shown in the following
link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetwebclientclassuploadfiletopic.asp
The only thing I did differently is that I also set the BaseAddress property
of the...
| |
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
webclient.UploadFile("http://127.0.0.1/ECSWebServices/UploadItem.aspx",
"POST", "C:\Test.txt")
and the file ends up looking like:
|
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
regards
shantanu
|
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 and
the file is copied from the server to the server, rather than from the web
client to the server.
Please help!!!
|
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 UploadGeneralFile(ByVal sURL as string,ByVal sFilename As String)
Dim client As New System.Net.WebClient
Dim sHTTPURL As String
Dim req As New Uri(sURL)
Dim respponse As Byte()
sHTTPURL = req.Scheme() & "://" &...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |