Upload a text file thru webclient

S

shantanu

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

WebClient client = new WebClient();
client.Credentials = netCred;
client.Headers.Add("Content-Type","application/x-www-form-
urlencoded");
client.UploadFile("http://aww.ngn.bel.alcatel.be/prp/cgi-bin/secure/
ImportForm.cgi","POST",@"C:\PRP\PRPTemp.txt");
 
S

shantanu

Hi,

It seems fine to me , what problems are you getting?






- Show quoted text -

hi thanx for the reply
i am really confused it is giving no error
can there be any posibility of acess rights
the link has GUI with a file upload option ans a import button.
regards
shantanu
 
M

Marc Gravell

From your description, this is a standard user page (since you mention
GUI); I'd be inclined to upload a file via a browser, with "fiddler"
running to see what gets sent - looking in particular at any
additional form variables, cookies, etc. You can probably get as much
by looking at the form, but "fiddler" may be easier, especially since
this is http not https (although fiddler 2 works with SSL in IE)

Marc
 
S

shantanu

From your description, this is a standard user page (since you mention
GUI); I'd be inclined to upload a file via a browser, with "fiddler"
running to see what gets sent - looking in particular at any
additional form variables, cookies, etc. You can probably get as much
by looking at the form, but "fiddler" may be easier, especially since
this is http not https (although fiddler 2 works with SSL in IE)

Marc

Hi thanks for the reply but i actually did not get the answer, what is
fiddler ????
is it any tool that give me a strack trace of the communication?????

thanks shantanu
 
S

shantanu

hi i tried with the fiddler tool
i am posting the trace can u tell whats the diffrence as i am not
getting it
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++
From Excel

POST /prp/cgi-bin/secure/ImportForm.cgi HTTP/1.1

Content-Type: multipart/form-data;
boundary=---------------------8c981ff4727edcc

Content-Length: 1770

Expect: 100-continue

Host: aww.ngn.bel.alcatel.be



HTTP/1.1 100 Continue



-----------------------8c981ff4727edcc

Content-Disposition: form-data; name="file"; filename="PRPTemp.txt"

Content-Type: application/x-www-form-urlencoded



number.name.content.original.content.approved.content.planned.contentdeleted.original.contentdeleted.approved.contentdeleted.planned.contentchange.original.contentchange.approved.contentchange.planned.defectsdoc.original.defectsdoc.approved.defectsdoc.planned.defectscode.original.defectscode.approved.defectscode.planned.defectstest.original.defectstest.approved.defectstest.planned.defectsval.original.defectsval.approved.defectsval.planned.defectsfieldsw.original.defectsfieldsw.approved.defectsfieldsw.planned.effort.original.effort.approved.effort.planned.effortdr1dr5.original.effortdr1dr5.approved.effortdr1dr5.planned.defectsfielddr5.original.defectsfielddr5.approved.defectsfielddr5.planned.nrcustomers.original.nrcustomers.approved.nrcustomers.planned.salesvalue.original.salesvalue.approved.salesvalue.planned.margin.original.margin.approved.margin.planned.dr0p.original.dr0p.approved.dr0p.planned.dr0p.status.dr1.original.dr1.approved.dr1.planned.dr1.status.dr3.original.dr3.approved.dr3.planned.dr3.status.dr4.original.dr4.approved.dr4.planned.dr4.status.dr5.original.dr5.approved.dr5.planned.dr5.status.dr6.original.dr6.approved.dr6.planned.dr6.status.dr0.original.dr0.approved.dr0.planned.dr0.status.dr2.original.dr2.approved.dr2.planned.dr2.status.ci.original.ci.approved.ci.planned.ci.status.obr.original.obr.approved.obr.planned.obr.status.releasetype.location.locationlead.pl.

9YZ-00490-
AAAA.TestProject.........................................................
2009-02-04....2009-12-12....2009-08-21....2009-09-19....2009-03-27.............L36051.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++
From Portal

POST /prp/cgi-bin/secure/Import.cgi HTTP/1.1

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-powerpoint,
application/vnd.ms-excel, application/msword, application/xaml+xml,
application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-
ms-application, */*

Referer: http://aww.ngn.bel.alcatel.be/prp/cgi-bin/secure/ImportForm.cgi?PL=L36051&root=AL

Accept-Language: en-us

Content-Type: multipart/form-data;
boundary=---------------------------7d722727054c

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)

Host: aww.ngn.bel.alcatel.be

Content-Length: 2155

Connection: Keep-Alive

Cache-Control: no-cache

Authorization: Basic c2hhbnRhbnUgc2VuOnN1bm55IzAwMw==



-----------------------------7d722727054c

Content-Disposition: form-data; name="file"; filename="C:\PRP
\PRPTemp.txt"

Content-Type: text/plain



number.name.content.original.content.approved.content.planned.contentdeleted.original.contentdeleted.approved.contentdeleted.planned.contentchange.original.contentchange.approved.contentchange.planned.defectsdoc.original.defectsdoc.approved.defectsdoc.planned.defectscode.original.defectscode.approved.defectscode.planned.defectstest.original.defectstest.approved.defectstest.planned.defectsval.original.defectsval.approved.defectsval.planned.defectsfieldsw.original.defectsfieldsw.approved.defectsfieldsw.planned.effort.original.effort.approved.effort.planned.effortdr1dr5.original.effortdr1dr5.approved.effortdr1dr5.planned.defectsfielddr5.original.defectsfielddr5.approved.defectsfielddr5.planned.nrcustomers.original.nrcustomers.approved.nrcustomers.planned.salesvalue.original.salesvalue.approved.salesvalue.planned.margin.original.margin.approved.margin.planned.dr0p.original.dr0p.approved.dr0p.planned.dr0p.status.dr1.original.dr1.approved.dr1.planned.dr1.status.dr3.original.dr3.approved.dr3.planned.dr3.status.dr4.original.dr4.approved.dr4.planned.dr4.status.dr5.original.dr5.approved.dr5.planned.dr5.status.dr6.original.dr6.approved.dr6.planned.dr6.status.dr0.original.dr0.approved.dr0.planned.dr0.status.dr2.original.dr2.approved.dr2.planned.dr2.status.ci.original.ci.approved.ci.planned.ci.status.obr.original.obr.approved.obr.planned.obr.status.releasetype.location.locationlead.pl.

9YZ-00490-
AAAA.TestProject.........................................................
2009-02-04....2009-12-12....2009-08-21....2009-09-19....2009-03-27.............L36051.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++
 
M

Marc Gravell

The top one (I assume this is the one that doesn't work?) has no
Authorization header... this would be my first guess (although you
have set credentials...)

I was mainly looking for cookies and other form variables, but there
don't appear to be any in either ;-(

Marc
 
S

shantanu

The top one (I assume this is the one that doesn't work?) has no
Authorization header... this would be my first guess (although you
have set credentials...)

I was mainly looking for cookies and other form variables, but there
don't appear to be any in either ;-(

Marc

ya its really confusing
 
S

shantanu

ya its really confusing
Hi i got a stack trace related to uploading the data
HTTP/1.1 401 Authorization Required

Date: Fri, 22 Jun 2007 03:19:27 GMT

Server: Apache/2.0.49 (Unix) mod_perl/1.99_13 Perl/v5.8.4 PHP/4.3.7
DAV/2 mod_ssl/2.0.49 OpenSSL/0.9.7d

WWW-Authenticate: Basic realm="Corporate Internet Login "

Content-Length: 564

Content-Type: text/html; charset=iso-8859-1



<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<hr />
<address>Apache/2.0.49 (Unix) mod_perl/1.99_13 Perl/v5.8.4 PHP/4.3.7
DAV/2 mod_ssl/2.0.49 OpenSSL/0.9.7d Server at aww.ngn.bel.alcatel.be
Port 80</address>
</body></html>

but i am already using the code
WebClient client = new WebClient();
client.Headers.Add("Authorization","Basic
"+Convert.ToBase64String(Encoding.ASCII.GetBytes("user:pass")));

client.Credentials = netCred;
client.Headers.Add("PreAuthenticate","true");
client.Headers.Add("Content-Type","application/x-www-form-
urlencoded");
client.UploadFile("http://aww.ngn.bel.alcatel.be/prp/cgi-bin/
secure/ImportForm.cgi?PL=L36051&root=AL","POST",@"C:\PRP
\PRPTemp.txt");

regards
shantanu
 
M

Marc Gravell

Well, from your stack trace it doesn't seem to be using it... I'm
confused as to why you are doubling up on setting headers anyway:
surely .Credentials should manage the Authorization header (so why set
twice?) Likewise, the content-type of a file upload isn't application/
x-www-form-urlencoded, but multipart/form-data. You don't should
netCred being initialized, but I can't see why this isn't playing
ball...

Marc
 
S

shantanu

Well, from your stack trace it doesn't seem to be using it... I'm
confused as to why you are doubling up on setting headers anyway:
surely .Credentials should manage the Authorization header (so why set
twice?) Likewise, the content-type of a file upload isn't application/
x-www-form-urlencoded, but multipart/form-data. You don't should
netCred being initialized, but I can't see why this isn't playing
ball...

Marc

thanx marc
but any how is it possible that the server is not providing the
sufficient rights to upload the data in this way.I was reading in some
article that the portal should me deployed in a anonymous mode. Is it
true.??
regards
shantanu
 
S

shantanu

thanx marc
but any how is it possible that the server is not providing the
sufficient rights to upload the data in this way.I was reading in some
article that the portal should me deployed in a anonymous mode. Is it
true.??
regardsshantanu

Hi
I am still waiting for the resolution kindly help
regards
shantanu
 

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

Top