Click here to Skip to main content
15,920,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to read excel file in asp.net without uploading it to server?
Posted

Hi,

if you do not want to upload your excel file and read it then probably you need to check javascript function to read excel file.

quick search gives me this link. Also search for more reasult of "javascript to read excel file".

-Amit
 
Share this answer
 
Comments
omprakash katre 3-May-12 2:34am    
thanks for reply, i have googled for "javascript to read excel file" and also got the result but every result required XL file,in my case i am not want to upload XL file on server.
AmitGajjar 3-May-12 2:37am    
so you do not need to upload your XL file on server. javascript will read data from local computer. code do not required to copy your XL file on server (IIS).
AmitGajjar 3-May-12 2:38am    
if you have written code in C# it means that code will run on server and if you write your code in javascript then that code will run on client end.
omprakash katre 3-May-12 8:16am    
if anybody block the client side javascript, than how we can read the XL file?
AmitGajjar 3-May-12 8:22am    
in webapplication this constraint is always there. you can check if javascript is disabled then a message should prompt "Enable your Javascript to read your Excel".
Hi,

try this,
C#
<asp:fileupload id="FileUpload1" runat="server" xmlns:asp="#unknown" />
<asp:button id="Button1" runat="server" text="Send File" onclick="Button1_Click" xmlns:asp="#unknown" />
<asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown" />

// C# Code-Behind
protected void Button1_Click(object sender, EventArgs e) {
    // the ExcelDataReader takes a System.IO.Stream object
    var excelReader = new ExcelDataReader(FileUpload1.FileContent);
    FileUpload1.FileContent.Close();

    DataSet wb = excelReader.WorkbookData;
    // get the first worksheet of the workbook
    DataTable dt = excelReader.WorkbookData.Tables[0];

    GridView1.DataSource = dt.AsDataView();
    GridView1.DataBind();
}


Best Luck
Happy Coding:)
 
Share this answer
 
Comments
omprakash katre 3-May-12 2:23am    
thanks for solution,but ExcelDataReader is not part of System.Data.OleDb.
Put this code at Button Click


var excelReader = new ExcelDataReader(FileUpload1.FileContent);
FileUpload1.FileContent.Close();
DataSet wb = excelReader.WorkbookData;
DataTable dt = excelReader.WorkbookData.Tables[0];
GridView1.DataSource = dt.AsDataView();
GridView1.DataBind();
 
Share this answer
 
Comments
omprakash katre 3-May-12 2:25am    
its working in local machine but when i uploaded it on server its not getting xl file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900