Load a wen page with file information and show save as dialog

S

Stefan Soljemo

I developing an asp.net application with a page that creating a file.
Redirect to another page with file information and shows a save as dialog.
The file will be streamed as contets type "application/force-download". The
first questeion is if I need to create the page twise. One with the HTML data
to be shown and a second with the sream. If so how to do the postback?
The second question is if its possible to att the contents type
"application/force-download" at the end of the page.
Note that the application using AJAX.

I use the folliwing code to create the stream:
stream = new FileStream( sFile, FileMode.Open, FileAccess.Read,
FileShare.Read );

Response.Clear();
Response.AddHeader( "Content-Disposition", "attachment; filename=" + sFile);
Response.AddHeader( "Content-Length", stream.Length.ToString() );
Response.ContentType = "application/force-download";
iBufSize = 16384;
buffer = new byte[ iBufSize ];
iCount = stream.Read( buffer, 0, iBufSize );

while( iCount > 0 )
{
Response.OutputStream.Write( buffer, 0, iCount );
iCount = stream.Read( buffer, 0, iBufSize );
}
Response.Flush();
Response.Close();
stream.Close();
 
G

Guest

I developing an asp.net application with a page that creating a file.
Redirect to another page with file information and shows a save as dialog..
The file will be streamed as contets type "application/force-download". The
first questeion is if I need to create the page twise. One with the HTML data
to be shown and a second with the sream. If so how to do the postback?
The second question is if its possible to att the contents type
"application/force-download" at the end of the page.
Note that the application using AJAX.

I use the folliwing code to create the stream:
stream = new FileStream( sFile, FileMode.Open, FileAccess.Read,
FileShare.Read );

Response.Clear();
Response.AddHeader( "Content-Disposition", "attachment; filename=" + sFile);
Response.AddHeader( "Content-Length", stream.Length.ToString() );
Response.ContentType = "application/force-download";
iBufSize = 16384;
buffer = new byte[ iBufSize ];
iCount = stream.Read( buffer, 0, iBufSize );

while( iCount > 0 )
{
    Response.OutputStream.Write( buffer, 0, iCount );
    iCount = stream.Read( buffer, 0, iBufSize );}

Response.Flush();
Response.Close();
stream.Close();

I think you need to put your code in the place where redirect was
located. You can also add a control such as LinkButton to do the
postback. For example,

<asp:LinkButton id="LinkButton1" Text="Download"....

void LinkButton1_Click(...)
{
stream = new FileStream( sFile, FileMode.Open, FileAccess.Read,
FileShare.Read );
Response.Clear();
.....

}

Response.ContentType specifies the HTTP content type for the response
header and this information is located at the top (head) of the
response

HTTP/1.1 200 OK
Content-Disposition: filename=xxx
Content-Length: xxx
Content-Type: application/force-download
.....
 
S

Stefan Soljemo

Thank you Alexey!

I did that from begining but got trouble when tha page was loaded twise
because of security settings. The dtream needs to be created every time tha
page is loaded.




Stefan Soljemo said:
I developing an asp.net application with a page that creating a file.
Redirect to another page with file information and shows a save as dialog.
The file will be streamed as contets type "application/force-download". The
first questeion is if I need to create the page twise. One with the HTML data
to be shown and a second with the sream. If so how to do the postback?
The second question is if its possible to att the contents type
"application/force-download" at the end of the page.
Note that the application using AJAX.

I use the folliwing code to create the stream:
stream = new FileStream( sFile, FileMode.Open, FileAccess.Read,
FileShare.Read );

Response.Clear();
Response.AddHeader( "Content-Disposition", "attachment; filename=" + sFile);
Response.AddHeader( "Content-Length", stream.Length.ToString() );
Response.ContentType = "application/force-download";
iBufSize = 16384;
buffer = new byte[ iBufSize ];
iCount = stream.Read( buffer, 0, iBufSize );

while( iCount > 0 )
{
Response.OutputStream.Write( buffer, 0, iCount );
iCount = stream.Read( buffer, 0, iBufSize );
}
Response.Flush();
Response.Close();
stream.Close();

I think you need to put your code in the place where redirect was
located. You can also add a control such as LinkButton to do the
postback. For example,

<asp:LinkButton id="LinkButton1" Text="Download"....

void LinkButton1_Click(...)
{
stream = new FileStream( sFile, FileMode.Open, FileAccess.Read,
FileShare.Read );
Response.Clear();
......

}

Response.ContentType specifies the HTTP content type for the response
header and this information is located at the top (head) of the
response

HTTP/1.1 200 OK
Content-Disposition: filename=xxx
Content-Length: xxx
Content-Type: application/force-download
......



Anon User
 
G

Guest

Thank you Alexey!

I did that from begining but got trouble when tha page was loaded twise
because of security settings. The dtream needs to be created every time tha
page is loaded.


You probably can use Page.IsPostBack Property

if (!Page.IsPostBack) {
// here's the code with the HTML data
}
else {
// here's the code with the sream.
stream = new FileStream( sFile, FileMode.Open, FileAccess.Read,
FileShare.Read );
}

void LinkButton1_Click(...)
{

Response.Clear();
Response.Clear();
Response.AddHeader( "Content-Disposition", "attachment; filename=" +
sFile);
Response.AddHeader( "Content-Length", stream.Length.ToString() );
.....

}



}
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top