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

x
?
Solved

C# - Creating FileStream start at certain row?

Posted on 2012-08-13
6
Medium Priority
?
410 Views
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.
0
Comment
Question by:sbornstein2
  • 3
  • 2
6 Comments
 
LVL 35

Expert Comment

by:YZlat
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
0
 

Author Comment

by:sbornstein2
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.
0
 
LVL 13

Accepted Solution

by:
jonnidip earned 600 total points
ID: 38291399
>>  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
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

by:sbornstein2
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.
0
 
LVL 13

Expert Comment

by:jonnidip
ID: 38291898
Is the problem in the columns or in the rows?
0
 

Author Closing Comment

by:sbornstein2
ID: 38317264
tx
0

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