C# Read from csv-file

Posted on 2009-03-30
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
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 …

688 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