-

Tuesday, September 25, 2012

Create CSV file integration with ASP.NET


Instructions Create a New CSV File

1 Open Windows Notepad to create a new file.

2 Type the following:

1,John Smith,blue

2,Fred Jones,purple

3,Rita Chavez,yellow

4,Belinda Simms,pink

3 Save the file to the root of your C drive as "favcolors.csv" in the "File name" text box.

Create a New Web Project

4 Open Microsoft Visual Studio 2010 and from the "File" menu choose "New Project."

5 Select Visual C# from the "Installed Templates" column and choose "ASP.NET Empty Web Application."

6 Enter a name of your choice in the "Name" text box.

7 Specify a location of your choice in the "Location" text box.

8 Click "OK."

Create the ASP.NET Page

9 Right-click the project name in "Solution Explorer," then click "Add" and "New Item."

10 Select "Web Form" from Visual C# Installed Templates and click "OK"

11 Click the "Design" button to switch to the designer view.

12 Double-click the "ListBox" control under the Standard tab of the Toolbox to add it to the page.

13 Double-click the "Button" control under the Standard tab of the Toolbox to add it to the page.

14 Right-click the button and choose "Properties," and change the Text Property to "Upload."

Write the Code

15 Double-click the button added to the designer page to display the code-behind page.

16 Type the following at the top of the file with other "using" statements:

using System.IO;

17 Type the following code between the opening "{" and closing "}" brackets of the Button1_Click event:

string fileName = @"C:\\favcolors.csv";

using (StreamReader strdr = File.OpenText(fileName))

{

String content;

while ((content = strdr.ReadLine()) != null)

{

ListBox1.Items.Add(content);

}

}

18 Click the "Save All" icon to save your changes.

Test the Program

19 Press "F5" on the keyboard to run the program in Debugging mode.

20 Click the "Upload" button.

21 Check that the names listed in the CSV file display as separate lines in the ListBox control.

for more reference please visit http://www.ehow.com/how_7416148_import-csv-file-asp_net.html