Note that there are some explanatory texts on larger screens.

plurals
  1. POC# VS2005 Convert Pipe Delimited .TXT to Excel Workbook .XLS
    primarykey
    data
    text
    <p>I am using VS2005 C# and im trying to convert a pipe delimited text file to excel workbook format. Below is my code:</p> <pre><code>public partial class TextToExcel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void SaveAsExcelBtn_Click(object sender, EventArgs e) { string xlExtension = ".csv"; string strExcelOutputFilename = "C:/Documents and Settings/rhlim/My Documents/" + DateTime.Now.ToString("yyyyMMddHHmmss") + xlExtension; // Before attempting to import the file, verify // that the FileUpload control contains a file. if (TextFile.HasFile) { // Get the name of the Excel spreadsheet. string strFileName = Server.HtmlEncode(TextFile.FileName); // Get the extension of the text. string strExtension = Path.GetExtension(strFileName); // Validate the file extension. if (strExtension != ".TXT" &amp;&amp; strExtension!=".txt") { Response.Write("&lt;script&gt;alert('Failed to import. Cause: Invalid text file.');&lt;/script&gt;"); return; } // Generate the file name to save the text file. //string strUploadFileName = "C:/Documents and Settings/rhlim/My Documents/Visual Studio 2005/WebSites/SoD/UploadFiles/" + DateTime.Now.ToString("yyyyMMddHHmmss") + strExtension; using (StreamWriter outputWriter = new StreamWriter(File.Create(strExcelOutputFilename))) { StreamReader inputReader = new StreamReader(TextFile.FileContent); string fileContent = inputReader.ReadToEnd(); fileContent = fileContent.Replace('|', ';'); outputWriter.Write(fileContent); TextFile.SaveAs(strExcelOutputFilename); inputReader.Close(); } //string strExcelOutputFilename = "C:/Documents and Settings/rhlim/My Documents/" + DateTime.Now.ToString("yyyyMMddHHmmss")+xlExtension; // Save the Excel spreadsheet on server. //TextFile.SaveAs (strExcelOutputFilename); } else Response.Write("&lt;script&gt;alert('Failed to import. Cause: No file found');&lt;/script&gt;"); } } </code></pre> <p>Currently I am having some file saving errors</p> <p>Any suggestions? Thanks a lot!</p> <p><img src="https://i.stack.imgur.com/OXp1m.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload