File save dialog

R

Ryan Moore

I'm trying to make a page that, when opened, displays a file save dialog,
then closes itself (essentially just leaving the file save dialog). Is this
possible? I've tried this:

Response.ContentType="image/JPEG";
//Response.AddHeader ("Content-Length", FileSize.ToString());
Response.AppendHeader("Content-Disposition","attachment;
filename=img1.jpg");
Response.WriteFile(@"c:\img1.jpg");
Response.Write("<script>window.close();</script>");
Response.Flush();

But the page does not close... any ideas?
 
B

Bruno Sirianni

In your code there is a big error!

Response.ContentType="image/JPEG";
Response.AppendHeader("Content-Disposition","attachment;
filename=img1.jpg");
Response.WriteFile(@"c:\img1.jpg");
Response.Flush();

with this code you send on client a jpg!
The result is the same as you write http://server/img1.jpg....

if you write a javascript in an imige it doesn't work!

Response.Write("<script>window.close();</script>");
Is the same if you edit a Jpg with notepad and write inside this code!

If you want to close the page you can do :

1) make a first page with this tag element and script:

<iframe src="webform1.aspx"></iframe>
<script language=javascript>
<!--
window.close();
//-->
</script>


2) make a second page with your code!
the page that response image must have only code for image (no
HTML!). My council is to make a simple page, override the render method
without call the base and than place Response.Write inside this!

example :
protected override void Render(HtmlTextWriter writer)
{
Response.ContentType = "image/jpeg";
Response.AddHeader("Content-Disposition","attachment;filename=img1.jpg");
Response.WriteFile(@"c:\Sample.jpg");
Response.Flush();
}

Brun
 

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,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top