I am providing user an option to download CSV file from my application. If we don't save that file in the machine and instead of clicking save we click open in internet explorer it opens in Microsoft Excel and excel uses the file name as worksheet name. Now in this case what is happening that it shows me excel worksheet name as .csv[filename this is illegal name for excel worksheet and I get error for the same. In other case if I save this file on my machine and open it, it works fine. Can any one tell me is it the problem with my code or something else? I am using following content type to download this CSV file.
IE works out what to do with a file based on the Content-Type and Content-Disposition headers. If you have correctly set both of those (as Ulf suggested earlier) it should be OK. Windows uses the registry HKEY_CLASSES_ROOT/MIME/Database/Content-Type to map the Content-Type header to an application. Windows also has a concept called MIME sniffing whereby it has an algorithm that attempts to workout the MIME type of a binary file by analysing the first n bytes with varying degrees of success. Assuming you have correctly set the Content-Type MIME sniffing should not be playing a part, but if you are on XP SP2 or above you can disable it to make sure.
The file name doesn't matter to Excel. I can open a file names foo.bar in Excel 2003 no problem. The square brakets stuff you see is a file name pattern that Excel itself can generate. Are you sure the error is about the file name and not a security warning that files of a particular type cannot be opened from a particular location? There is a bug in IE6 that (for security reasons) prevents certain applications opening files in the default temp file space.