how to prevent automatic conversion of csv to xls

G

Guest

Hi,

I have a web page which generates a CSV file based on some user input. When
this file is downloaded by the user, the file is being automatically
converted to .xls. Any idea how I can prevent this?

My code (snippet) -

StreamWriter sw;
if(File.Exists(filename))
File.Delete(filename);
sw = File.CreateText(filename);
string values="\"File Name\",\"Name\",\"Description\",\"Is Customizable\"";
try
{
foreach(DataRow dr in dt.Rows)
{
for(int i=0; i<dt.Columns.Count; i++)
values += ",\"" + dr.ToString() +"\"";
}
values += ",\"Document Type\",\"Category\"";
sw.WriteLine(values);
}
catch(Exception ex)
{
//Show error msg
sw.Close();
return;
}
sw.Close();
//Show success message

filename = DMS.Global.site_config.getAttribute("base_href") +
@"/temporary_files/file_import.csv";

//hiddenlbl is an asp Label which is invisible when page is loaded
//The following code is for the file download popup
string htmlinput = "<iframe id='downloadFrame' src = '" + filename + "'";
htmlinput += " style='display:none'></iframe>";
hiddenlbl.Visible = true;
hiddenlbl.Text = htmlinput;
 
G

Guest

Hi,

When excel is setup on the pc the file extension .csv is automatically
associated with excel. So when the browser wants to open the .csv file it
hands over the control to the associated file viewer. If there is some other
application which has been setup as the default file viewer for .csv files
then the browser will call that application. It is upto the browser to call
the application. So nothing that u can do about it.
 

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

Top