Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

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

 
Thread Tools Search this Thread
Old 11-02-2009, 02:03 PM   #1
Default Load a wen page with file information and show save as dialog


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();


Stefan Soljemo
  Reply With Quote
Old 11-03-2009, 08:09 AM   #2
Alexey Smirnov
 
Posts: n/a
Default Re: Load a wen page with file information and show save as dialog
On Nov 2, 3:03*pm, Stefan Soljemo <ssste...@newsgroup.nospam> wrote:
> 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
.....


Alexey Smirnov
  Reply With Quote
Old 11-04-2009, 07:13 AM   #3
Stefan Soljemo
 
Posts: n/a
Default RE: Load a wen page with file information and show save as dialog
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" wrote:

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



Alexey Smirnov




Stefan Soljemo
  Reply With Quote
Old 11-04-2009, 07:58 AM   #4
Alexey Smirnov
 
Posts: n/a
Default Re: Load a wen page with file information and show save as dialog
On Nov 4, 8:13*am, Stefan Soljemo <ssste...@newsgroup.nospam> wrote:
> 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() );
.....

}



}


Alexey Smirnov
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46