Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7048615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:54:47+00:00 2026-05-28T02:54:47+00:00

I am making a site that consumes a csv file this file can come

  • 0

I am making a site that consumes a csv file this file can come in 2 formats(maybe more in the future).

Structure 1

Header 1 Header 2 Header 3 Header 4 
a          b      c       d
x          x      x       x

Structure 2

Header 1 Header 4
a          d
x          x

the above is how it would be shown in excel(if looking at raw it would be all comma separated)

The reason why I want to have 2 structures is because I am using trying to leverage a 3rd party site that user can export their data from. This site exports it as a csv file with the first row being the headers. I really only care about 2 of the headers and the reset is not needed at this current time (but you have to export all columns can’t pick and choose).

The second structure is if the user does not wish to use this site because they don’t want to, uncomfortable to do so and etc. They have an option of opening excel up and writing the data manually in and then saving it as a csv file.

So for manual people I want to make it as simple as possible as if I am not using Header 2 and Header 4 data why should I bother getting them to enter it in? However at the same time if people go through the first way and export the data I don’t want them to have to go and load the file into excel up and remove 2 columns.

I am going to require the header must always be intact and be the first row. The only idea I came up with is read the first row and see the order of the headers. If it has 4 headers in the exact order then render it one way. If only 2 headers in that order render it another way.

I know that FileHelpers has the ability to do multiple delimiters and choose how to render it but since I am looking at headers I am not sure if this baked in or if I need to somehow write it myself and then tell it what to do.

Does anyone have an idea if I can do this with filehelpers?

Edit
this is what I have so far

MultiRecordEngine engine = new MultiRecordEngine(typeof(Format2), typeof(Format1));
    engine.RecordSelector = new RecordTypeSelector(CustomSelector);

    using (TextReader textReader = new StreamReader(stream))
    {
        if (engine.RecordType == typeof(Format2))
        {
            var myArry = engine.ReadStream(textReader) as Format2[];

        }
        else if(engine.RecordType == typeof(Format1))
        {
            var myArry = engine.ReadStream(textReader) as Format1[];
        }



    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:54:48+00:00Added an answer on May 28, 2026 at 2:54 am

    Here are a couple of suggested approaches:

    Read the first line of the file (outside of FileHelpers) and determine which format is being used before creating the engine

    if (firstLineOfFile.Contains("Header 2"))
        FileHelperEngine engine = new FileHelperEngine(typeof(Format1)); 
    else
        FileHelperEngine engine = new FileHelperEngine(typeof(Format2)); 
    

    Alternatively, you can use the MultiRecordEngine

    MultiRecordEngine engine;  
    engine = new MultiRecordEngine(typeof(Format1), typeof(Format2)); 
    engine.RecordSelector = new RecordTypeSelector(CustomSelector); 
    

    with a selector method something like

    Type CustomSelector(MultiRecordEngine engine, string record) 
    { 
        // count the separators to determine which format to return
        int separatorCount = record.Count(f => f == ',');
        if (separatorCount == 4) 
            return typeof(Format1); 
        else 
            return typeof(Format2); 
    } 
    

    (The MultiRecordEngine can handle more formats in the future – it has a constructor with a params parameter)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a Http Webrequest to an available site that I can visit
Do you know of any site that can help me start with making template
I am making a site that publishes articles in issues each month. It is
I am making an app that takes photos from web site for some Username
I am making a site that depend on users to register to be able
I'm making a site that will be translated into x languages. All strings must
I'm in the process of making some improvements to a live Drupal site that's
I have a flash site that users can view full Screen video. the trouble
Can anyone recommend a web site that includes up to date performance tips for
I am making a site that determines the value of an array based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.