Reputation: 451
I'm having problems when trying to use the Open option in Internet Explorer when serving an excel document from an ASP.NET web app.
Response.AddHeader("content-disposition", "attachment;filename=" + filename.Replace(",", "") + ".xls");
Response.Charset = String.Empty;
Response.ContentType = "application/vnd.xls";
using (StringWriter sw = new StringWriter())
using(HtmlTextWriter hw = new HtmlTextWriter(sw))
{
gridView.RenderControl(hw);
Response.Write(sw.ToString());
}
Response.End();
I didn't write the code but what I have noticed is that if the filename length is <= 177 then it works. Anything over >= 118 I receive a file could not be found error. I've checked the the 118th character is a 0 so doesn't appear to be anything to do with this.
Any ideas what might be causing this as it seems to work fine in Chrome and Firefox.
Upvotes: 0
Views: 474
Reputation: 68902
I think here is the reason: http://support.softartisans.com/kbview_892.aspx
Although the NTFS or FAT32 file systems can support filenames up to 255 characters, it isn't possible to use a file input to upload a file with a name that long. This is due to the way that IE inserts the chosen file into the form field.
When you browse to a file and select it using the File input, IE inserts the full file path. IE also limits you to 255 characters, but counts the file path against that limit. This means that if you had a path with a length of 55 characters, the maximum length of the file name that you could choose to upload would be 200 characters.
also this may be helpful: https://stackoverflow.com/a/153400/20126
However, there is still a limitation (apparently IE-only) on the byte-length of the file name (a bug, I assume). So even if the file name is made of only single-byte characters, the beginning of the file name is truncated. The limitation is around 160 bytes.
Upvotes: 1