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

  • Home
  • SEARCH
  • 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 6939487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:37:43+00:00 2026-05-27T12:37:43+00:00

I need to read csv file twice. but after first reading: using (var csvReader

  • 0

I need to read csv file twice. but after first reading:

using (var csvReader = new StreamReader(file.InputStream))
{
    fileFullText += csvReader.ReadToEnd();
    file.InputStream.Seek(0, SeekOrigin.Begin);
    csvReader.Close();
}

using file in enother function:

public static List<string> ParceCsv(HttpPostedFileBase file)
{
    //file.InputStream.Seek(0, SeekOrigin.Begin);
    using (var csvReader = new StreamReader(file.InputStream))
    {
       // csvReader.DiscardBufferedData();
       // csvReader.BaseStream.Seek(0, SeekOrigin.Begin);
        string inputLine = "";
        var values = new List<string>();

        while ((inputLine = csvReader.ReadLine()) != null)
        {
            values.Add(inputLine.Trim().Replace(",", "").Replace(" ", ""));
        }
        csvReader.Close();
        return values;
    } 
}

The file.Length is 0.
Can anybody help?

  • 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-27T12:37:44+00:00Added an answer on May 27, 2026 at 12:37 pm

    The reason is that SteramReader‘s Dispose() method also closes the underlying stream; In your case file.InputStream. The using statement calls Dispose() implicitly. Try to replace using with disposes of both your StreamReaded-s after you finished both read operations. As I remember some stream classes have a bool option to leave underlying stream open after dispose.

    .NET 4.5 fixed this issue by introducing leaveOpen parameter in SteamReader constructor. See: MSDN

    public StreamReader(
        Stream stream,
        Encoding encoding,
        bool detectEncodingFromByteOrderMarks,
        int bufferSize,
        bool leaveOpen
    )
    

    One more thing. You do not need to close SteramReader yourself (the line with csvReader.Close();) when you wrap it in using statement, thus Dispose() and Close() are the same in case of StreamReader.

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

Sidebar

Related Questions

For my system, i first need to read CSV file and then i need
I need to read CSV file header from FTP. As these files can be
Question: I need to read a CSV file. I use the FileHelpers library to
I'm working on a project and I need to read a CSV file and
I need to read from a CSV/Tab delimited file and write to such a
Using Ruby 1.9.2 I need to parse a CSV file, and output lines with
I have a need to read a CSV file, and the only language I
I have a flat CSV file which I need read from to end up
In a project I'm working on, I need to read from a CSV file,
I have a data set which I read from my a .csv file. After

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.