1

I am creating an excel report in vb.net using the office interop. When the report is completed I am saving the excel file on the C drive. The users have asked to save file anywhere they want not just the c drive. Can someone give me some code to popup an opend file dialog in asp.net?

I want the dialog to popup in a saveAs in ASP.NET. I know how to do it in win forms, but I am creating an excel report in asp.net and calling the worksheet objects SaveAs property that excepts a fileName. So right now I just hardcode a file name in there. The users want to choose a file location

9
  • 1
    Just to be clear... This is being done via ASP.NET, not WinForms? And you're saving it to THEIR C: drive? Commented Apr 5, 2010 at 14:46
  • 1
    I think you're referring to .NET, not ASP.NET. ASP.NET is used only in a web context. Commented Apr 5, 2010 at 14:50
  • How are you currently saving it to the C Drive? Commented Apr 5, 2010 at 15:26
  • Dim fn as String="C:\RptCrd.xls" xlWorkBook.SaveAs(fn) Commented Apr 5, 2010 at 15:40
  • 1
    Are you sure this isn't saving out to the server C: not the client C:? Commented Apr 5, 2010 at 15:59

3 Answers 3

1

I think what you want is actually rather simple.

You can't save a file to the user's computer due to security restrictions (would you want a website saving a file to your computer?)

What you need to do is:

  1. Complete report
  2. Save report file to location on server, IE (.../myWebsite/files/GUID/myReport.rpt)
  3. Display link on next screen pointing to the report file

Doing this the user can right-click and save the file to wherever they want on their computer.

You can clean up these files on whatever schedule you would like.

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

3 Comments

Yeah I wanted to save it on the client but maybe thats just a bad design. Its an intranet website app so I understand it makes no sense to download to a client but in my case it kinda does because the not all users can see the reports and managers dont want the reprots archived on the server.
I thought you might have some sort of privacy thing, which is why I used the GUID as a folder, this way you can't guess the path. You can also schedule a process that deletes all the folders in the "files" folder every night, this way the reports aren't archived.
they wanna have the other to create the file on the client and save it whereever they want on their machine. Is there a way?
0

Assuming you are actually talking about a desktop, winforms app then you can use the built in FileSaveDialog.

Official documentation is here:

but there are tons of tutorials explaining it out there:

1 Comment

No I want the dialog to popup in a saveAs in asp.net. I know how to do it in win forms, but I am creating an excel report in asp.net and calling the worksheet objects SaveAs property that excepts a fileName. So right now I just hardcode a file name in there. The users want to choose a file location.
0

You can server files with the Open / Save dialog by using Response.TransmitFile().

The user is then presented with a save as dialog where they can choose the filename and the location on their computer.

You normally do this inside a HttpHandler. A simple one is described here:

1 Comment

So there is no simple way to have for the user to choose a file location in asp.net?

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.