Solved

ASP.NET Reponse.Content help with selecting and uploading file

Posted on 2007-04-09
3
413 Views
Last Modified: 2007-12-19
Hi, I'm using asp.net and a gembox Excel DLL to read/write excel files. The writing aspect works well using the following code, which prompts the user where to save the file.

//ef is the ExcelFile object.

 Response.Clear();
 Response.ContentType = "application/vnd.ms-excel";
 Response.AddHeader("Content-Disposition", "attachment; filename=temp.xls");
 ef.SaveXls(Response.OutputStream);
 Response.End();

Now, I need to figure out how to read the file using the ef.LoadXls function. It works fine if I hardcode the file to the local machine, but how do I get it to prompt the user through the web interface and allow them to select/upload the file?

Thanks,

Terry


0
Comment
Question by:TerryBurger
3 Comments
 
LVL 5

Accepted Solution

by:
asp_lha earned 500 total points
ID: 18879693
first, you need to prompt the user to upload a file (show some help)
then upload the file where the user selected to a temp. directory
and use the ef.LoadXls to load the file.

sample code for upload file
(come from http://www.asp.net/learn/dataaccess/tutorial54vb.aspx?tabid=63):

Protected Sub UploadButton_Click(sender As Object, e As EventArgs) _
    Handles UploadButton.Click
   
    If UploadTest.HasFile = False Then
        ' No file uploaded!
        UploadDetails.Text = "Please first select a file to upload..."
    Else
        ' Display the uploaded file's details
        UploadDetails.Text = String.Format( _
                "Uploaded file: {0}<br />" & _
                "File size (in bytes): {1:N0}<br />" & _
                "Content-type: {2}", _
                UploadTest.FileName, _
                UploadTest.FileBytes.Length, _
                UploadTest.PostedFile.ContentType)

        ' Save the file
        Dim filePath As String = _
            Server.MapPath("~/Brochures/" & UploadTest.FileName)
        UploadTest.SaveAs(filePath)
    End If
End Sub
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question