I have an excel File which is having data more than (>=2 Gb )., i tried using ODBC Connection, i tried few other ways like “Stream Reader” (Could be incorrect Code) to read the data, but still im not able to read the file, kindly for any support or any suggestions for reading the .CSV file… @Anil_G@Gangadhar_Athili@Yoichi
so lets focus on correcting the text reading with stream reader as this is a preferred option when handling large files. Just share with us the failing implementation and we will have a look at this
can you please correct me with this code, if it works.
Blockquote
using System;
using System.IO;
class Program
{
static void Main()
{
// Replace “your-csv-file.csv” with the actual file path
string csvFilePath = “your-csv-file.csv”;
try
{
using (StreamReader reader = new StreamReader(csvFilePath))
{
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
if (!string.IsNullOrEmpty(line))
{
string[] fields = line.Split(',');
// Process the fields as needed, for example:
foreach (string field in fields)
{
Console.Write(field + " ");
}
Console.WriteLine();
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error reading the CSV file: {ex.Message}");
}
@ppr Tq so much its working , im able to get read the data , but later im trying to pass that string to generate data table so that i can get a datatable, but im getting the below error
Maybe could you also check with the below modified code if it works :
try
{
using (StreamReader reader = new StreamReader(csvFilePath))
{
int count = 0;
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
if (!string.IsNullOrEmpty(line))
{
string[] fields = line.Split(';');
if(count==0)
{
foreach(string field in fields)
{
out_dt.Columns.Add(field);
}
}else
{
// Process the fields as needed, for example:
out_dt.Rows.Add(fields);
}
}
count++;
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error reading the CSV file: {ex.Message}");
}
DT is a Datatable created using Build Datatable activity with no columns and no rows.
As Already mentioned, we would need a sample data to understand the structure delimiter used. Current code works with Semicolon (; ) as separator but could easily be changed to the required.
However a check is needed to understand whether it is efficient enough.
But if you still wish to check on the code, you could let us know what were the Errors encountered. A Screenshot would help to analyse better, also if you have Selected VB as the Language, change it to C# and check.
I tried using the Code the bot is able to read for lesser data but the bot is not able to read the file for huge data, please find the below screenshot
lets check the part step (reading, not parsing). Once this is working, we will advance it, similar to @supermanPunch approach
Lines = New List(Of String)()
Using r As StreamReader = New StreamReader(strFilePath)
Do While ( Not r.EndOfStream)
Lines.Add(r.ReadLine())
Loop
End Using