473,836 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Content-Disposition Doesn't Set Filename in IE

Jed
I have looked everywhere and cannot find a resolution for this. I have read
several post on this forum that allude to similar issues but I have not found
a solution.

I am sending dynamic content to the browser to be opened in Excel. On some
browsers including on the mac it works fine, but in other browsers it sets
the filename to the script instead of to the name specified in the
content-disposition.

I am at my wits end. Here is a snapshot of my code, but I have tried dozens
of permutations. It works on my local machine but not on the server. The
server is running under HTTPS which may be an issue? I have tried without
and with the mime type defined in the IIS on the server. The request is
launched from a javascript window.open and I have tried both relative and
absolute urls.

FYI: this is part of a function and the context is the current httpcontext.
I am doing all this from an HttpHandler with session state enabled.

XslTransform xslt = new XslTransform();
xslt.Load(xslPa th);
System.IO.Memor yStream stream = new System.IO.Memor yStream();
xslt.Transform( xmlDocument, xargs, stream, new XmlUrlResolver( ));
context.Respons e.Buffer = true;
context.Respons e.Clear();
context.Respons e.ClearContent( );
context.Respons e.ClearHeaders( );
context.Respons e.Cookies.Clear ();
context.Respons e.Charset = System.Text.UTF 8Encoding.UTF8. WebName;
//string.Empty;
context.Respons e.ContentEncodi ng = System.Text.UTF 8Encoding.UTF8;
context.Respons e.AppendHeader( "Content-Length", stream.Length.T oString());
//context.Respons e.AppendHeader( "Content-Disposition-Type","inline") ;
//context.Respons e.AppendHeader( "Pragma","cache ");
//context.Respons e.AppendHeader( "Expires", "-1");
//context.Respons e.AppendHeader( "Cache-Control","no-store, no-cache,
must-revalidate, post-check=0, pre-check=0");
context.Respons e.ContentType = "applicatio n/vnd.ms-excel";
context.Respons e.AppendHeader( "Content-Disposition",
"inline; " +
"filename=\ "" + "Download.x ls" + "\"; " +
"size=" + stream.Length.T oString() + "; " +
"creation-date=" + DateTime.Now.To String("R") + "; " +
"modificati on-date=" + DateTime.Now.To String("R") + "; " +
"read-date=" + DateTime.Now.To String("R"));
context.Respons e.BinaryWrite(s tream.ToArray() );
stream.Close();
context.Respons e.Flush();
context.Respons e.Close();
stream = null;
context.Respons e.End();

Nov 19 '05 #1
4 2309
well its up to the browser to honor the content file name. as you found,
many don't. you have two options:

1) live with it.
2) use an http module, and use url remapping to get around the problem, so
that

Download.xls get remapped to producexml.aspx
-- bruce (sqlwork.com)

..

"Jed" <Je*@discussion s.microsoft.com > wrote in message
news:52******** *************** ***********@mic rosoft.com...
I have looked everywhere and cannot find a resolution for this. I have
read
several post on this forum that allude to similar issues but I have not
found
a solution.

I am sending dynamic content to the browser to be opened in Excel. On
some
browsers including on the mac it works fine, but in other browsers it sets
the filename to the script instead of to the name specified in the
content-disposition.

I am at my wits end. Here is a snapshot of my code, but I have tried
dozens
of permutations. It works on my local machine but not on the server. The
server is running under HTTPS which may be an issue? I have tried without
and with the mime type defined in the IIS on the server. The request is
launched from a javascript window.open and I have tried both relative and
absolute urls.

FYI: this is part of a function and the context is the current
httpcontext.
I am doing all this from an HttpHandler with session state enabled.

XslTransform xslt = new XslTransform();
xslt.Load(xslPa th);
System.IO.Memor yStream stream = new System.IO.Memor yStream();
xslt.Transform( xmlDocument, xargs, stream, new XmlUrlResolver( ));
context.Respons e.Buffer = true;
context.Respons e.Clear();
context.Respons e.ClearContent( );
context.Respons e.ClearHeaders( );
context.Respons e.Cookies.Clear ();
context.Respons e.Charset = System.Text.UTF 8Encoding.UTF8. WebName;
//string.Empty;
context.Respons e.ContentEncodi ng = System.Text.UTF 8Encoding.UTF8;
context.Respons e.AppendHeader( "Content-Length", stream.Length.T oString());
//context.Respons e.AppendHeader( "Content-Disposition-Type","inline") ;
//context.Respons e.AppendHeader( "Pragma","cache ");
//context.Respons e.AppendHeader( "Expires", "-1");
//context.Respons e.AppendHeader( "Cache-Control","no-store, no-cache,
must-revalidate, post-check=0, pre-check=0");
context.Respons e.ContentType = "applicatio n/vnd.ms-excel";
context.Respons e.AppendHeader( "Content-Disposition",
"inline; " +
"filename=\ "" + "Download.x ls" + "\"; " +
"size=" + stream.Length.T oString() + "; " +
"creation-date=" + DateTime.Now.To String("R") + "; " +
"modificati on-date=" + DateTime.Now.To String("R") + "; " +
"read-date=" + DateTime.Now.To String("R"));
context.Respons e.BinaryWrite(s tream.ToArray() );
stream.Close();
context.Respons e.Flush();
context.Respons e.Close();
stream = null;
context.Respons e.End();

Nov 19 '05 #2
Jed
Thanks, Bruce,

Maybe that is what I should do. Can you explain why it works in my local
development environment but not on the live server?

Obviously, the browser is the same in both contexts.

Thanks again.

"Bruce Barker" wrote:
well its up to the browser to honor the content file name. as you found,
many don't. you have two options:

1) live with it.
2) use an http module, and use url remapping to get around the problem, so
that

Download.xls get remapped to producexml.aspx
-- bruce (sqlwork.com)

..

"Jed" <Je*@discussion s.microsoft.com > wrote in message
news:52******** *************** ***********@mic rosoft.com...
I have looked everywhere and cannot find a resolution for this. I have
read
several post on this forum that allude to similar issues but I have not
found
a solution.

I am sending dynamic content to the browser to be opened in Excel. On
some
browsers including on the mac it works fine, but in other browsers it sets
the filename to the script instead of to the name specified in the
content-disposition.

I am at my wits end. Here is a snapshot of my code, but I have tried
dozens
of permutations. It works on my local machine but not on the server. The
server is running under HTTPS which may be an issue? I have tried without
and with the mime type defined in the IIS on the server. The request is
launched from a javascript window.open and I have tried both relative and
absolute urls.

FYI: this is part of a function and the context is the current
httpcontext.
I am doing all this from an HttpHandler with session state enabled.

XslTransform xslt = new XslTransform();
xslt.Load(xslPa th);
System.IO.Memor yStream stream = new System.IO.Memor yStream();
xslt.Transform( xmlDocument, xargs, stream, new XmlUrlResolver( ));
context.Respons e.Buffer = true;
context.Respons e.Clear();
context.Respons e.ClearContent( );
context.Respons e.ClearHeaders( );
context.Respons e.Cookies.Clear ();
context.Respons e.Charset = System.Text.UTF 8Encoding.UTF8. WebName;
//string.Empty;
context.Respons e.ContentEncodi ng = System.Text.UTF 8Encoding.UTF8;
context.Respons e.AppendHeader( "Content-Length", stream.Length.T oString());
//context.Respons e.AppendHeader( "Content-Disposition-Type","inline") ;
//context.Respons e.AppendHeader( "Pragma","cache ");
//context.Respons e.AppendHeader( "Expires", "-1");
//context.Respons e.AppendHeader( "Cache-Control","no-store, no-cache,
must-revalidate, post-check=0, pre-check=0");
context.Respons e.ContentType = "applicatio n/vnd.ms-excel";
context.Respons e.AppendHeader( "Content-Disposition",
"inline; " +
"filename=\ "" + "Download.x ls" + "\"; " +
"size=" + stream.Length.T oString() + "; " +
"creation-date=" + DateTime.Now.To String("R") + "; " +
"modificati on-date=" + DateTime.Now.To String("R") + "; " +
"read-date=" + DateTime.Now.To String("R"));
context.Respons e.BinaryWrite(s tream.ToArray() );
stream.Close();
context.Respons e.Flush();
context.Respons e.Close();
stream = null;
context.Respons e.End();


Nov 19 '05 #3
Jed
OK,

I went with the extension mapping option and it doesn't work.

I mapped the xls extension and am handling it with an HttpHandler. It
behaves exactly the same as running it through an aspx. It works locally
where there is no SSL but it doesn't work on the server where the request is
secured. So even though the "file" has the xls extension, it still won't
download.

I don't think it is an MSOffice issue, I think it is a security issue. I
have seen unanswered posts about Cacheability having an effect, but I have
seen no answers on the subject.

I am stumped.

"Bruce Barker" wrote:
well its up to the browser to honor the content file name. as you found,
many don't. you have two options:

1) live with it.
2) use an http module, and use url remapping to get around the problem, so
that

Download.xls get remapped to producexml.aspx
-- bruce (sqlwork.com)

..

"Jed" <Je*@discussion s.microsoft.com > wrote in message
news:52******** *************** ***********@mic rosoft.com...
I have looked everywhere and cannot find a resolution for this. I have
read
several post on this forum that allude to similar issues but I have not
found
a solution.

I am sending dynamic content to the browser to be opened in Excel. On
some
browsers including on the mac it works fine, but in other browsers it sets
the filename to the script instead of to the name specified in the
content-disposition.

I am at my wits end. Here is a snapshot of my code, but I have tried
dozens
of permutations. It works on my local machine but not on the server. The
server is running under HTTPS which may be an issue? I have tried without
and with the mime type defined in the IIS on the server. The request is
launched from a javascript window.open and I have tried both relative and
absolute urls.

FYI: this is part of a function and the context is the current
httpcontext.
I am doing all this from an HttpHandler with session state enabled.

XslTransform xslt = new XslTransform();
xslt.Load(xslPa th);
System.IO.Memor yStream stream = new System.IO.Memor yStream();
xslt.Transform( xmlDocument, xargs, stream, new XmlUrlResolver( ));
context.Respons e.Buffer = true;
context.Respons e.Clear();
context.Respons e.ClearContent( );
context.Respons e.ClearHeaders( );
context.Respons e.Cookies.Clear ();
context.Respons e.Charset = System.Text.UTF 8Encoding.UTF8. WebName;
//string.Empty;
context.Respons e.ContentEncodi ng = System.Text.UTF 8Encoding.UTF8;
context.Respons e.AppendHeader( "Content-Length", stream.Length.T oString());
//context.Respons e.AppendHeader( "Content-Disposition-Type","inline") ;
//context.Respons e.AppendHeader( "Pragma","cache ");
//context.Respons e.AppendHeader( "Expires", "-1");
//context.Respons e.AppendHeader( "Cache-Control","no-store, no-cache,
must-revalidate, post-check=0, pre-check=0");
context.Respons e.ContentType = "applicatio n/vnd.ms-excel";
context.Respons e.AppendHeader( "Content-Disposition",
"inline; " +
"filename=\ "" + "Download.x ls" + "\"; " +
"size=" + stream.Length.T oString() + "; " +
"creation-date=" + DateTime.Now.To String("R") + "; " +
"modificati on-date=" + DateTime.Now.To String("R") + "; " +
"read-date=" + DateTime.Now.To String("R"));
context.Respons e.BinaryWrite(s tream.ToArray() );
stream.Close();
context.Respons e.Flush();
context.Respons e.Close();
stream = null;
context.Respons e.End();


Nov 19 '05 #4
Jed
Well, I think I have it resolved, though I am not sure what of the following
fixed it.

Here are a couple useful resource links:
http://support.microsoft.com/?kbid=317208
http://www.generation.net/~hleboeuf/downfile.htm

Here is the header code:
context.Respons e.Clear();
context.Respons e.ClearContent( );
context.Respons e.ClearHeaders( );
context.Respons e.Cookies.Clear ();
context.Respons e.Cache.SetCach eability(HttpCa cheability.Priv ate);
context.Respons e.CacheControl = "private";
context.Respons e.Charset = System.Text.UTF 8Encoding.UTF8. WebName;
context.Respons e.ContentEncodi ng = System.Text.UTF 8Encoding.UTF8;
context.Respons e.AppendHeader( "Content-Length", stream.Length.T oString());
context.Respons e.AppendHeader( "Pragma","cache ");
context.Respons e.AppendHeader( "Expires", "60");
context.Respons e.ContentType = "applicatio n/vnd.ms-excel";
context.Respons e.AppendHeader( "Content-Disposition",
"inline; " +
"filename=\ "" + fileName + "\"; " +
"size=" + stream.Length.T oString() + "; " +
"creation-date=" + DateTime.Now.To String("R") + "; " +
"modificati on-date=" + DateTime.Now.To String("R") + "; " +
"read-date=" + DateTime.Now.To String("R"));

According to the KB article above, Office cannot open files that have not
been cached by IE. I changed the cache settings to accommodate this
"limitation ". Though the following may have been enough.

One of the Advanced settings in the IE options is "Do not save encrypted
pages to disk" I had this option checked and I believe this is why neither
download (attachment) nor open (inline) worked for me in HTTPS/SSL but did
work for others.

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
3233
by: jonathan.beckett | last post by:
Hi All, For the past few months I have been working on an open source Apache/PHP/MySQL content management system - and have recently made it available for download. It's still very much a work in progress (current release version is 0.4.6), but you should get a very good idea of what it's about by visiting the site (which uses it, funnily enough), or downloading a copy of it and trying it out.
0
2331
by: jonathan.beckett | last post by:
Hi All, I have just made version 0.4.8 of the PluggedOut CMS Content Management System available for download - it's free, and covered by the GPL. It's still very much a work in progress (current release version is 0.4.8), but you should get a very good idea of what it's about by visiting the site (which uses it, funnily enough), or downloading a copy of it and trying it out.
0
2150
by: Scott Abel | last post by:
For immediate release: The Rockley Group Content Management Workshop Series Coming to Atlanta, Seattle, Vancouver, Chicago, Washington, DC, Toronto, and Research Triangle Park Learn more: http://www.rockley.com/workshops.htm The Rockley Group Content Management Workshop Series is designed to
10
2679
by: clintonG | last post by:
Can somebody direct me to documents or source that supports the use of collapsible content that is collapsed by default when the page is loaded? The secondary objective would of course be cross-browser support.for IE (5-6) and browsers derived from Mozilla (varies). Thank you... <%= Clinton Gallagher
0
9671
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10854
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10558
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10600
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.