I am trying to create a console application that will execute an HTTPWebRequest to an aspx page to first login, and then secondly upload a file. I am able to login fine but when I re-direct to the upload page I pass in the path to the file and I set my variable
(txtFile.Value) = the path "C:\files\filetoupload.zip". When I try to execute the upload with txtFile.PostedFile.SaveAs("uploaded.zip"); It says that txtFile.PostedFile is null. I am trying to execute this via the query string, not by clicking on a submit
button or posting the form back to the page. Any help would be greatly appreciated. Nicko
Is there another way to approach this then? I was trying to upload the file using:
string filePath = ConfigurationSettings.AppSettings.Get("localFilePath");
String uriString = "http://localhost";
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
Console.WriteLine("Uploading {0} to {1} ...",filePath,uriString);
// Upload the file to the URL using the HTTP 1.0 POST.
byte[] responseArray = myWebClient.UploadFile(uriString,"POST",filePath);
// Decode and display the response.
Console.WriteLine("\nResponse Received.The contents of the file uploaded are: \n{0}",Encoding.ASCII.GetString(responseArray));
nicko
Member
40 Points
8 Posts
Help with upload
Aug 01, 2003 05:53 PM|LINK
Nicko
rl711
Participant
825 Points
165 Posts
Re: Help with upload
Aug 01, 2003 06:13 PM|LINK
nicko
Member
40 Points
8 Posts
Re: Help with upload
Aug 01, 2003 06:27 PM|LINK
string filePath = ConfigurationSettings.AppSettings.Get("localFilePath"); String uriString = "http://localhost"; // Create a new WebClient instance. WebClient myWebClient = new WebClient(); Console.WriteLine("Uploading {0} to {1} ...",filePath,uriString); // Upload the file to the URL using the HTTP 1.0 POST. byte[] responseArray = myWebClient.UploadFile(uriString,"POST",filePath); // Decode and display the response. Console.WriteLine("\nResponse Received.The contents of the file uploaded are: \n{0}",Encoding.ASCII.GetString(responseArray));but nothing gets uploaded. Thanks for your help.Nicko
rl711
Participant
825 Points
165 Posts
Re: Help with upload
Aug 01, 2003 06:42 PM|LINK