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

The Archive Base Latest Questions

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

I code this function which converts all pipes into commas, and after that converting

  • 0

I code this function which converts all pipes into commas, and after that converting it into an excel .CSV file.

However, after that I realize that there are some problems with some rows.

E.g. Name [Chua Wei Loon] (supposedly to be in one column), ended up “Chua Wei” is in one column, “Loon” is in the next column.

I have look through the text file and find no pipes in between the name, and I couldn’t find a solution to it.

Below is my code for the 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;
            }

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

            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:/";
                }

                //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('Please select a file');</script>");

A sample output of the .csv file (rows with errors are highlighted):

enter image description here

I have realized my mistake, it is due to having commans inside variables which caused the name to split.

Are there any suggestions so that I could still convert them to .csv files despite having commans in between variables?

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

    did you check whether [Chua Wei Loon] is not actually [Chua Wei, Loon] ? Did you get rid of the commas in the data first?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In code below is function that converts slider class into slider control. It has
I have this code which is called at an onChange event of an function
We have this anonymous function in our code, which is part of the jQuery's
I am writing this code. Here dt is input into the function, as well
I have some JQuery code that converts all HTML elements of a specific class
I see a lot of code like this: function Base() {} function Sub() {}
This code function LoadContent(Id) { alert('Controls/Network/NetworkDetail.aspx?' + rnd() + '&CtlId=' + Id); $.get('Controls/Network/NetworkDetail.aspx?' +
View this code: function testprecision(){ var isNotNumber = parseFloat('1.3').toPrecision(6); alert(typeof isNotNumber); //=> string }
With this code function someFunction(classParam:Class):Boolean { // how to know if classParam implements some
I have this code: function submitTwice(f){ f.action = 'http://mydomain.com/threevideopage.php'; f.target='name'; f.submit(); } I left

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.