asp.net form to send a request to a put request

G

Guest

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.
 
J

Jeffrey Palermo [MCP]

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

eswanson said:
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.
 
G

Guest

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
 
J

Jeffrey Palermo [MCP]

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
 
G

Guest

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'&programnumber='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
 
J

Jeffrey Palermo [MCP]

Eric,
I've done a bit of research on this, and you need to use the
HttpWebRequest class in the System.Net namespace to create a custom web
request that will post a file to an external website. I found a class that
abstracts a lot of the code required:
http://www.c-sharpcorner.com/Code/2003/May/DotNetBugs.asp
Pull this class into your project, and then it will just take a few lines of
code:
MultipartForm mp = new MultipartForm(http://localhost/AcceptFile.aspx);
mp.sendFile(@"c:\resetlog.txt");

I was able to send my file to a web page that accepted it as a client
upload. You can examine the code of MultipartForm for what code is actually
run. It gets a little bit hairy.

Best regards,

Jeffrey Palermo
 
J

Jeffrey Palermo [MCP]

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
 
G

Guest

Jeff,

Thanks for the suggestions, but I really do not want to prompt the user for
a file and also, I really do not want to write a file out . Instead I would
like to store the contents of the file on a aspx page and then press a button
on that page and send this information to the page that wants a file and
other inputs....

I know that a 3rd party control wilsoncontrols will allow you to post data
on this page to other pages. What I need assistance on is how what format
does the paramater for the input=file needs to be? I do not want to write a
file first, instead I want to store this information into a text box on the
form.

Hope this makes since.

Thanks

Eric

Jeffrey Palermo said:
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

eswanson said:
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
 
J

Jeffrey Palermo [MCP]

Good luck.


ejs said:
Jeff,

Thanks for the suggestions, but I really do not want to prompt the user for
a file and also, I really do not want to write a file out . Instead I would
like to store the contents of the file on a aspx page and then press a button
on that page and send this information to the page that wants a file and
other inputs....

I know that a 3rd party control wilsoncontrols will allow you to post data
on this page to other pages. What I need assistance on is how what format
does the paramater for the input=file needs to be? I do not want to write a
file first, instead I want to store this information into a text box on the
form.

Hope this makes since.

Thanks

Eric

Jeffrey Palermo said:
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

eswanson said:
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
 
G

Guest

Jeff,

Is this possible to store the data in a text box and then somehow with the
right format send it to a page that accepts a get? The question is what
should the format of the text in the text box be?

Thanks

Eric

Jeffrey Palermo said:
Good luck.


ejs said:
Jeff,

Thanks for the suggestions, but I really do not want to prompt the user for
a file and also, I really do not want to write a file out . Instead I would
like to store the contents of the file on a aspx page and then press a button
on that page and send this information to the page that wants a file and
other inputs....

I know that a 3rd party control wilsoncontrols will allow you to post data
on this page to other pages. What I need assistance on is how what format
does the paramater for the input=file needs to be? I do not want to write a
file first, instead I want to store this information into a text box on the
form.

Hope this makes since.

Thanks

Eric

Jeffrey Palermo said:
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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top