I've created a web-part. I've added few documents to it. I'm implementing download functionality. I want file download dialog. My code is like this.
DownloadItem(SPListItem item)
{
// Get physical path of the file
string itemPath = MapPathSecure(item.File.Url);
HttpContext.Current.Response.ContentType = "application/x-download";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + item.File.Name);
HttpContext.Current.Response.TransmitFile(itemPath);
HttpContext.Current.Response.End();
}
This throws an error : "Could not find a part of the path 'Path to the document'. The path does not exist. I know that Sharepoint documents are not located on the hard disk. Am I missing something here ?
How do I get this code to work ?