Tuesday 2 January 2018

Reading Data Of A CSV File Without Saving It In C#

We can read the data of a CSV file without saving it onto a server. Given below are the steps :-

1) Create an aspx page and paste the following code into it. It will create an File upload control and an button.

<asp:FileUpload ID="txt_Upload" runat="server" />  
<asp:Button ID="btnsubmit" Text="Submit" runat="server" OnClick="btnsubmitclick"/>  


2) In the cs file, paste the below method.

protected void btnsubmitclick(object sender, EventArgs e)   
{  
    System.IO.StreamReader myReader = new System.IO.StreamReader(txt_Upload.PostedFile.InputStream);  
    string output = myReader.ReadToEnd();  
    Response.Write(output);  


Once you select an csv file and click on submit button, data from csv file will be read without saving the file to server and will be displayed in the page.

Hope this will be helpful!

No comments:

Post a Comment