C# Read from csv-file

Posted on 2009-03-30
Medium Priority
Last Modified: 2012-05-06
I want to read a CSV file and put the data into an ArrayList. I use HtmlInputFile. It works fine when the user browse for the file and select the file. It works fine when I test this local on my machine.
But when I test it at the webserver, the filename refer to (for example) C:\myFile.csv but at the server and not the client.
Is it possible to get the file (stream) or filename in codebehind or do I have to use client script/JavaScript?
I want to read the csv file, validate that it is correct and then save the data into a database.
<INPUT id="inputFileName" type="file" runat="server">
protected HtmlInputFile inputFileName;
private void btnValidateFile_Click(object sender, System.EventArgs e)
  if( inputFileName.PostedFile != null )
      // Output no fileName...
protected void LoadFromFile(string _fileName)
  ArrayList RecordList = new ArrayList();
  string[] recordCollection;
  StreamReader cr = new StreamReader(_fileName)
        while (cr.Peek() >=0)
	  string tempString = cr.ReadLine();
	  recordCollection = tempString.Split(';');

Open in new window

Question by:Oskowich
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 24020077
.NET 1.1
Visual Studio 2003

Accepted Solution

Oskowich earned 0 total points
ID: 24021310
ArrayList RecordList = new ArrayList();
if (inputFileName.PostedFile != null)
      string[] recordCollection;
      using (System.IO.StreamReader sr = new System.IO.StreamReader(inputFileName.PostedFile.InputStream))
            while (sr.Peek() >=0)
                  string tempString = sr.ReadLine();
                  recordCollection = tempString.Split(';');

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

801 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