1

How do I load an Excel file in an ASP page from System.Web.HttpInputStream? File uploaded by Telerik: RadUpload.

Appreciate any help. Thanks

2
  • Is your question about getting a file from the stream OR somehow rendering Excel file on ASP.Net page? Commented Feb 3, 2011 at 19:05
  • Only need to read the stream that comes into the property of InputStream, transforming it into an Excel file and read the columns. I know how to read the data but does not know how I can create an Excel object that is valid from the Stream. @Alexei Levenkov Commented Feb 3, 2011 at 19:13

1 Answer 1

3

I had to do this recently from a file that a user would upload. I got it to work by saving the file temporarily then doing the following

string fileTempPath = Path.Combine(Server.MapPath("~/temp"), fileUploader.FileName);
                    fileUploader.SaveAs(fileTempPath);
                    fileTempPathHiddenField.Value = fileTempPath;

                    System.Data.DataTable excelDataTable = LoadData();

Later in the code:

 protected System.Data.DataTable LoadData()
        {
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                        "Data Source=" + fileTempPathHiddenField.Value + ";" +
                        "Extended Properties=Excel 8.0;";
            OleDbDataAdapter dataAdapter = new OleDbDataAdapter(string.Format("Select * from [{0}$]", sheetNameTextBox.Text), connectionString);
            DataSet excellDataSet = new DataSet();

            dataAdapter.Fill(excellDataSet, "ExcelInfo");
            return excellDataSet.Tables["ExcelInfo"];
        }

Then once you are done with the temp file, go ahead and delete it if you want to.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.