Click here to Skip to main content
15,848,157 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends ,

In my application which i am developing i am processing a CSV File.
Actually the Process is , the user will download a Excel Template for Website and make entries to Excel File and then will upload the excel file for the system to Process the record to sql.
From my application logic . i am storing the uploaded file in SQL using file stream , then when processing start , i download the file stream convert it to CSV (Pipe Seprated) and then process the file , so far i have not encountered any issue with processing ,but one column in the excel is (Description)and users will copy paste the column , now the column has line breaks and paragraph breaks , so when i processing the file and reading the file Line by Line using Stream Reader Readline method , when it encounter the break and consider it as the end line

Any one pls suggest any solution for it below is the code for proper understanding

string fileinfo = ExcelConversion(FileName, FileID.Value);//Converion of Excel File to CSV
               byte[] output = UTF8Encoding.UTF8.GetBytes(fileinfo);//since the values will have chinese or japanese characters
               MemoryStream stream = new MemoryStream(output);
               using (StreamReader reader = new StreamReader(stream))
                   char[] splitchar;
                   splitchar = new char[] { '|' };
                   SrcUpperBoundColumnIndex =Src_Excel_Issedetails._021_TargetCompletionDate;
                   DataTable IssueUploaded = CreateDataTable(reader.ReadLine());
                   string strIssueRecord;
                   while ((strIssueRecord = reader.ReadLine()) != null)
                       string[] Columns = strIssueRecord.Split(splitchar);
                       if (Columns.GetUpperBound(0) == (SrcUpperBoundColumnIndex.GetHashCode() + 1))
                           throw new Exception("File upload failed. Invalid column count found.");

1 solution

While processing - Stream Reader you can use Trim Function to remove such Line Breaks & Para's
Share this answer
Rickin Kane 4-Nov-12 22:52pm    
Thanks for the help, Trim can work as well , but i added below line and it worked like a charm , thanks for your help ,Accpeting your answer as it is also a possible solution
string replaceWith = "";
fileinfo = fileinfo.Replace("\r\n", replaceWith).Replace("\n", replaceWith).Replace("\r", replaceWith);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900