C# - Creating FileStream start at certain row?

Hello all,

I am reading in an excel file into a FileStream as I am using an excel reader with that stream.  User will be inputting what row is the header row in a particular file.  Have files that come in where I need to eliminate some garbage header rows from the file.  So right now I have for example:

FileStream fileStream = new FileStream(dto.DataSourceFile.FullFilePath, FileMode.Open, FileAccess.Read);

How do I read in the file starting at a certain row for example Row 5 as an example?

Thanks all.
sbornstein2Asked:
Who is Participating?
 
jonnidipConnect With a Mentor Commented:
>>  I do not want to use Microsoft Interop at all as it sucks.
TOTALLY AGREE with you!

You can delete a number of rows from your DataTable, after reading your Excel.
You should really know how many rows are garbage, then you can work with your DataTable.
I think there is no further filtering in ExcelDataReader, other than "IsFirstRowAsColumnNames".

Regards.
0
 
YZlatCommented:
you can't do that.

What you can do is read data into a data structure like a datatable or an array and then access whatever row you want
0
 
sbornstein2Author Commented:
Well essentially I want to use the DataTable.ColumnName as the end result to get the column name.  The excel reader code gets it into a dataset:

 IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fileStream);
                excelReader.IsFirstRowAsColumnNames = true;
               
                DataSet ds = excelReader.AsDataSet();
                DataTable dt = ds.Tables[0];

Then I was going to loop through the column count get the columnname.  The IsFirstRow flag sets the dataset column names.  Problem is the 1st row is not my header row in certain scenarios.  I do not want to use Microsoft Interop at all as it sucks.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
sbornstein2Author Commented:
ya I may have to just delete from the datatable at that point.  just need to make sure I dont have too many columns etc. without the header.
0
 
jonnidipCommented:
Is the problem in the columns or in the rows?
0
 
sbornstein2Author Commented:
tx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.