tags:

views:

103

answers:

3

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

A: 

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
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
A: 

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
So there is no simple way to have for the user to choose a file location in asp.net?
Nick LaMarca
+1  A: 

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
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
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
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