Calling Url with form parameters in c# ?

  • Thread starter Thread starter WJ
  • Start date Start date
W

WJ

1. I have an ASP.Net web site that does nothing but accept files to be
uploaded manually. It has one simple page that asks users to specify a file
to be uploaded.

2. I also have a Windows Form application in c# that needs to send files
automatically to the web site folder.

So far, I got the code to activate the client's MS/IE program (
http://MyFileUploadSite.Com) ok. However, I need to send the file straight
to the site without showing MSIE and without user's intervention.

Thanks for your help.

John
 
Hi John,

You can use WebClient.UploadFile to send the file. See "WebClient.UploadFile
Method" topic in MSDN for more information and examples.
 
Dmitriy Lapshin said:
Hi John,

You can use WebClient.UploadFile to send the file. See "WebClient.UploadFile
Method" topic in MSDN for more information and examples.
Thanks Dmitriy. I donot think it works. I tried it and it gave no error,
however, it never uploaded the file. IIS log said it got a 200 message,
means it contacted the server OK. I think there is problem with this method
(WebClient.UploadFile).

John
 
Dmitriy Lapshin said:
Ensure you have specified the POST method which is the one the web server
expects.

Here is my code. The site is local and allows "full access" to "Everyone"
group.

private void button1_Click(object sender, System.EventArgs e)
{
string s="c:\\Test\\TestUploadFile.TXT";
string
Uri="http://localhost/AspNetFileUploadFolder/AspNetFileUpload.aspx";

WebClient wc=new WebClient();
byte[] ra=wc.UploadFile(Uri,"POST",s);

MessageBox.Show("File: "+s+";
"+Uri+"***"+Encoding.ASCII.GetString(ra),"FYI",
MessageBoxButtons.OK,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
}

Entries in C:\Inetpub\Logs\W3SVC1\ex040219.log:

The 1st line was done thru MSIE manual upload (worked)
and the 2nd line was done via Windows Form app (c#: no file uploaded):
(I broke the lines by "fields" so that MS/OE will not wrap text).

The status codes for both methods are the same (200,0).
Sites

******************************************************
#Software: Microsoft Internet Information Services 5.1
#Version: 1.0
#Date: 2004-02-19 11:52:06
#Fields: date,time,
c-ip,cs-username,s-sitename,s-computername,s-ip,s-port,
cs-method,cs-uri-stem,
cs-uri-query,
sc-status,sc-win32-status,
sc-bytes,cs-bytes,time-taken,cs-version,cs-host,
cs(User-Agent),
cs(Cookie),
cs(Referer)


(Line# 1: Sent by MS/IE6.1: Manual upload. Worked)

2004-02-19,11:53:03,
127.0.0.1,-,W3SVC1,MyComputer,127.0.0.1,80,
POST,/AspNetFileUpload/AspNetFileUpload.aspx,
-,
200,0,
1655,1288,125,HTTP/1.1,localhost,
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+.NET+CLR+1.1.4322),
ASP.NET_SessionId=0d0yexsxsxsx45orkxyx55,
http://localhost/AspNetFileUpload/AspNetFileUpload.aspx


(Line# 2: Sent by Windows Form c# app. No file uploaded)

2004-02-19,12:19:12,
127.0.0.1,-,W3SVC1,MyComputer,127.0.0.1,80,
POST,/AspNetFileUpload/AspNetFileUpload.aspx,
-,
200,0,
1675,2830,0,HTTP/1.1,localhost,
-,
-,
-
******************************************************

Thanks

John
 
Back
Top