Eric,
Another, easier but less flexible way to do it is to use the WebClient
class:
Console.Write("\nPlease enter the URI to post data to : ");
String uriString = "
http://localhost/WebApplication1/AcceptFile.aspx";
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
Console.WriteLine("\nPlease enter the fully qualified path of the file to be
uploaded to the URI");
string fileName = @"c:\upload.txt";
Console.WriteLine("Uploading {0} to {1} ...",fileName,uriString);
byte[] responseArray = myWebClient.UploadFile(uriString, "POST", fileName);
// Decode and display the response.
Console.WriteLine("\nResponse Received.The contents of the file uploaded
are: \n{0}",Encoding.ASCII.GetString(responseArray));
Console.ReadLine();
Best regards,
Jeffrey Palermo
Please read the entire reponse, hopefully this clears up your questions.
The data used that needs to go into the batchupload page comes from a
server. My problem is that currently I write a file to the server and
then
the user has to pick this file and send it up to the batchupload page.
The
batchupload page is not one of our page, instead it is another company's
page. This is there interface to do batch processing. We have no control
over it. We just call this page "batchupload" with a file and other
parameters. I am attempting to call the page "batchupload" and send fill
in
the parameters with out first creating the file. Is this possible? Do
you
understand our problem.
First batchupload is a page from another company. It is used for their
batch processing. Request parameters include a file <html input
type=file> -
does this have to be a file or some other data stream stored on the page
and
then sent over to this page?
The html page I sent you would be a page that was written for us to
communicate with the batchupload page. I can hard code all of the other
parameters except for the input type=file. Instead of writing out a file,
I
would like to buffer the file data into an asp.net page and then just send
all of the information at once over to the "batchupload" page.
I know that I can use
httpppost(
http://www.othercompany.com/batchupload?batchid='123'&programnumbe
r='ABC'&xml=?????????)
How do I specify the xml, since this variable is a file. What has to be
in
the data stream of xml, so that it appears to be a file, but is actually a
character string?
Hopefully this clears up the confusion.
Thanks
Eric
:
Eric,
I'm not sure I know exactly what you are trying to do, but if the
file
is coming from a user's machine, you can't automatically grab it. That
would be a security issue. If the file is originating on the server,
then
there is no need for one page to grab it and post it to another page.
The
second page could just use the absolute path on the server or the
network to
open the file.
Try reposting this question to the newsgroup, be more specific.
Best regards,
Jeffrey Palermo
Hi Jeff,
Here is an example that does this in HTML, but I would like to do this
in
asp.net, but I do not want to create the file first, instead I would
like
to
somehow stream the data to this post instead of writing out the file
first
and then having the user select the file and transfering it up to the
host
site. Is this possible?
Here is the current html:
<form method="post" enctype="multipart/form-data"
action="
https://egov.immigration.gov/sbtsevisbatch/action/batchUpload"/>
<!--<form method="post" enctype="multipart/form-data"
action="
https://egov.immigration.gov/sbtsevisbatch/action/batchUpload">-->
XML: <input type="file" name="xml" id="xml="><br>
Batch ID: <input type="text" name="batchid" id="batchid="><br>
Program Number: <input type="text" name="programnumber"
id="programnumber="><br>
<input type="submit">
I am attempting to automated the input type="file", instead I would
like
to
stream the file data from an asp.net page without first creating a
file
and
then having the user select this file and transmitting it up to the
other
site. What other options do I have instead of creating the file first
or
is
it possible to tell the input type='file' exactly what the file is and
where
it is?
Thanks
Eric
:
You would do this exactly the same as you would do it in regular
HTML
without ASP.NET. In fact, you don't have to use server controls for
this.
You can use a normal form and normal <input type="file"/>, <input
type="submit"/> controls, and set the action of the form to the
other
page.
Don't use a runat="server" form. A regular form will do. Then in
the
page
you post to, just retrieve the form values.
Best regards,
Jeffrey Palermo
I have a web page I need to post a file plus some other fields to
it.
How
can I do this from a asp.net page. I know I can send individual
fields
to
the
other page, but how do I send a file to the other page, or is
there
something
else like a stream which will be like a file. I am attempting to
get
a
way
from writing out a file and then having to give the page that I am
posting
to
the file name. Instead I would like to just from asp.net post to
the
other
HTML page, the information, plus this file without writing a file
out
first.