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

Nick LaMarca
  • 8,076
  • 31
  • 93
  • 152

3 Answers3

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.

Nathan Koop
  • 24,803
  • 25
  • 90
  • 125
  • 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. – Nick LaMarca Apr 05 '10 at 17:42
  • 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. – Nathan Koop Apr 05 '10 at 17:52
  • 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? – Nick LaMarca Apr 05 '10 at 18:38
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:

rtpHarry
  • 13,019
  • 4
  • 43
  • 64
  • 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. – Nick LaMarca Apr 05 '10 at 15:19
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:

rtpHarry
  • 13,019
  • 4
  • 43
  • 64