6

I am trying to use TextfieldParser that was found within Reading CSV files using C#. I am using VS 2010 and doing this in C#.

I keep on getting "the type or namespace "TextFieldParser" could not be found.."

When I try and add the using line, it will only go using Microsoft.VisualBasic; deep and not using Microsoft.VisualBasic.FileIO;

Any help would be great.

Community
  • 1
  • 1
user1158745
  • 2,402
  • 9
  • 41
  • 60

3 Answers3

29

In Visual Studio, right click on References in the Solution Explorer side panel. Click "Add Reference".

In that list be sure to check Microsoft.VisualBasic. Hit OK.

Now in the namespace, add Using Microsoft.VisualBasic.FileIO.

That will allow you to use TextFieldParser. For a good, easy example on how to use it, look here: http://geekswithblogs.net/brians/archive/2010/07/07/whats-a-nice-class-like-textfieldparser-doing-in-a-namespace.aspx

Mark P.
  • 1,827
  • 16
  • 37
0

For uncompiled files (aspx / ashx), you need to put an reference in the web.config. (They cannot use the project references.)

<system.web>
    <compilation debug="true" targetFramework="4.6.1">
      <assemblies>
        <add assembly="Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
      </assemblies>
    </compilation>
</system.web>

Alternatively for web applications, it would be preferred to put the code in a compiled file (cs/vb) and add a reference to the project.

See this question microsoft.visualbasic.fileio does not exist.

llessurt
  • 555
  • 3
  • 14
0

Application references are not available to uncompiled files in your application (aspx, ashx). The reference would need added to the web.config or else the code would need moved to a compiled file (cs/vb).

llessurt
  • 555
  • 3
  • 14