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;
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;