[Last Call] Learn how to a build a cloud-first strategyRegister Now


C# - Creating FileStream start at certain row?

Posted on 2012-08-13
Medium Priority
Last Modified: 2012-08-21
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.
Question by:sbornstein2
  • 3
  • 2
LVL 35

Expert Comment

ID: 38289433
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

Author Comment

ID: 38289467
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.
LVL 13

Accepted Solution

jonnidip earned 600 total points
ID: 38291399
>>  I do not want to use Microsoft Interop at all as it sucks.

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".

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 38291884
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.
LVL 13

Expert Comment

ID: 38291898
Is the problem in the columns or in the rows?

Author Closing Comment

ID: 38317264

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question