Question

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.

Was it helpful?

Solution

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

OTHER TIPS

The basic ingredients of this example are quite simple and can be found in a Microsoft article here.

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();
}

That should help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top