Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6770961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:22:34+00:00 2026-05-26T15:22:34+00:00

I am using VS2005 C# and im trying to convert a pipe delimited text

  • 0

I am using VS2005 C# and im trying to convert a pipe delimited text file to excel workbook format. Below is my 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" && strExtension!=".txt")
            {

                Response.Write("<script>alert('Failed to import. Cause: Invalid text file.');</script>");
                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("<script>alert('Failed to import. Cause: No file found');</script>");
    }
}

Currently I am having some file saving errors

Any suggestions? Thanks a lot!

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:22:34+00:00Added an answer on May 26, 2026 at 3:22 pm

    That’s because Excel doesnt support pipelines you have to convert it so comma’s or semicolumns like:

    using (StreamWriter outputWriter = new StreamWriter(File.Create(strExcelOutputFilename)))
    {
        StreamReader inputReader = new StreamReader(TextFile.FileContent);
        string fileContent = inputReader.ReadToEnd();
    
        fileContent = fileContent.Replace('|', ',');
        outputWriter.Write(fileContent);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VS2005 C#. I am trying to convert my ListBox control to
I am using VS2005 C#, I am trying to import an excel filesheet into
I am trying to compile my code in vs2005. I am using std::map and
I am writing code in VS2005 using its STL. I have one UI thread
I'm trying to compile someone elses C++ program using VS2005 on Windows 2003 (SP2).
I am using VS2005 C#. I am trying to switch my login authentication from
I am using VS2005 and SQL Server 2005. I am trying to execute multiple
I am using VS2005 and SQL Server 2005. I am trying to execute multiple
First of all, I'm using VS2005 and C# 2.0. I'm trying to set a
I am trying to convert some old VB6 code to VB.NET. The VB6 uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.