473,658 Members | 2,623 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 2301
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
3190
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
2311
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
2130
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
2637
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
8330
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
8850
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...
1
8523
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,...
0
8626
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5649
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
4175
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
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.