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 6779123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:20:52+00:00 2026-05-26T16:20:52+00:00

I am using VS2005 C#, I am trying to import an excel filesheet into

  • 0

I am using VS2005 C#, I am trying to import an excel filesheet into SQL server database.

Currently I am trying to convert pipe-delimited text files into .XLS format directly.

However I could not find a way to do it, so I tried to convert pipe-delimited text files to .CSV instead.

But in the end, after the conversion was done, I realize that there are some default commans in between some variables, causing the rows to be messed up.

Does anyone know anyway to ignore the default commans in the variables, or using another variable instead of commans? Below is the code for my conversion function:

protected void SaveAsExcelBtn_Click(object sender, EventArgs e)
    {


        //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('Invalid text file!');</script>");
                return;
            }

            if (DEMUserRoleRB.Checked)
            {
                string strExcelOutputFilename = "C:/" + "userrolelist" + xlExtension;


                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();
                    UploadStatusLabel.Text = "Conversion successful. File is stored at directory C:/";
                }

            }
        }
        else Response.Write("<script>alert('Please select a file');</script>");
    }

Thank you

  • 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-26T16:20:53+00:00Added an answer on May 26, 2026 at 4:20 pm

    you need to process the file line by line – try

    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() ) );
    };
    

    This takes a line from the input file and split it into “fields” at every pipe | it finds… then it builds a new line with , as a delimiter and enclosing any field which already contains , with double quotes " in the process…

    MSDN references:

    • http://msdn.microsoft.com/en-us/library/system.io.streamreader.peek.aspx
    • http://msdn.microsoft.com/en-us/library/b873y76a.aspx
    • http://msdn.microsoft.com/en-us/library/57a79xd0.aspx
    • http://msdn.microsoft.com/en-us/library/x303t819.aspx

    EDIT – as per comment:

    The above code replaces the following 3 lines from the original code:

    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# and im trying to convert a pipe delimited text
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
I am using VS2005 C#. I am trying to convert my ListBox control to
I am using VS2005 C# and SQL Server 2005. I have a a few
I'm using MS SQL 2000, VS2008, MVC and C#. I'm trying to insert and
I'm currently using VS2005 Profesional and .NET 2.0, and since our project is rather
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
First of all, I'm using VS2005 and C# 2.0. I'm trying to set a

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.