Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-04-09
3
Medium Priority
?
425 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
asp_lha earned 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

670 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