views:

158

answers:

3

Hi,

Can anyone suggest the best way to offer a file for download within a SharePoint web part? The file will be dynamically created on request, but I still need to end up with the standard page being displayed as well as the file being downloaded.

Cheers

Moo

A: 

The basic ingredients of this example are quite simple and can be found in a Microsoft article at (http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;q306654&lex).

The Microsoft article includes the following code snippet:

private void Page_Load(object sender, System.EventArgs e) { //Set the appropriate ContentType. Response.ContentType = "Application/pdf"; //Get the physical path to the file. string FilePath = MapPath("acrobat.pdf"); //Write the file directly to the HTTP content output stream. Response.WriteFile(FilePath); Response.End(); }

Thats should help you.

Chris Jones
Unless I am mistaken, the problem with that is the 'Response.End' - you can't do anything other than send the file and thats that. I need to send the file and display a normal page.
Moo
A: 

Hello Moo,

Were you able to find a solution for your problem? I am in the same boat and looking for a solution. I have a grid view of documents and want to provide an option for the user to either open or download the file and still say in the same grid view.

Anybody with any insight and help. Appreciate it.

Thanks, Cricket

Cricket
In the end I dynamically added an iFrame to the web part during the reload after the user chooses the 'Export' option, and within that loaded a standard .aspx page which handles the sending. This got around the issue of having to send a Response.End. Hope that helps!
Moo
A: 

In the end I dynamically added an iFrame to the web part during the reload after the user chooses the 'Export' option, and within that loaded a standard .aspx page which handles the sending. This got around the issue of having to send a Response.End

Moo