I am using VS2005 c#.
I have this function for converting pipe delimited text files into excel format.
The files will then be stored in the C:\ of the user PC.
However, when I deployed my web application into the test server, the files are saved in the C:\ of the test server instead.
Below is my code snippet, may I know how can I change it to be saved on the users' pc instead of the server's, or if possible, show a popup message for the user to open/save the file. Thank you
if (TextFile.HasFile)
{
string strFileName = Server.HtmlEncode(TextFile.FileName);
string strExtension = Path.GetExtension(strFileName);
string activeDir = @"C:\";
string newPath = System.IO.Path.Combine(activeDir, "App_Converted");
System.IO.Directory.CreateDirectory(newPath);
string strExcelOutputFilename = "C:/App_Converted/" + xlExtension;
using (StreamWriter outputWriter = new StreamWriter(File.Create(strExcelOutputFilename)))
{
StreamReader inputReader = new StreamReader(TextFile.FileContent);
while (inputReader.Peek() >= 0)
{
string[] myInputFields = inputReader.ReadLine().Split(new char[] { '|' });
List<string> myOutputFields = new List<string>();
foreach (string aField in myInputFields)
{
string oField = aField;
if (oField.Contains(","))
oField = "\"" + oField + "\"";
myOutputFields.Add(oField);
}
outputWriter.WriteLine(string.Join(",", myOutputFields.ToArray()));
}
inputReader.Close();
UploadStatusLabel.Text = "File stored at [C:/App_Converted/] as file name [namelist.csv]";
Response.Clear();
Response.ContentType = "application/vnd.xls";
Response.AddHeader("Content-Disposition", "attachment;filename=namelist.csv");
StringWriter swriter = new StringWriter();
HtmlTextWriter hwriter = new HtmlTextWriter(swriter);
Response.Write(swriter.ToString());
Response.End();
return;
}
EDIT:
Updated code with save windows. However, I do not know how to link my converted file to the save windows. Need some help here. Above is my updated code.