Can I ask on how to properly create a download mechanism using the generated file of aspose. My problem is that sometimes it downloads the page name ie. “mypage.aspx” it must be “filedownload.pdf”
it only happens in pdf.
here is my code
doc.Save(Convert.ToString(HttpContext.Current.Server.MapPath(docfileName)), Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Pdf));
byte[] fileInBytes = System.IO.File.ReadAllBytes(Convert.ToString(HttpContext.Current.Server.MapPath(docfileName)));
using (MemoryStream ms = new MemoryStream(fileInBytes))
{
long dataLengthToRead = ms.Length;
int blockSize = dataLengthToRead >= 5000 ? 5000 : (int)dataLengthToRead;
byte[] buffer = new byte[dataLengthToRead];
Response.Clear();
// Clear the content of the response
Response.ClearContent();
Response.ClearHeaders();
// Buffer response so that page is sent
// after processing is complete.
Response.BufferOutput = true;
// Add the file name and attachment,
// which will force the open/cance/save dialog to show, to the header
// Response.AddHeader("Content-Disposition", "attachment; filename=" + strFile);
// bypass the Open/Save/Cancel dialog
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFile);
// Add the file size into the response header
Response.AddHeader("Content-Length", fileInBytes.Length.ToString());
// Set the ContentType
Response.ContentType = "application/pdf";
while (dataLengthToRead > 0 && Response.IsClientConnected)
{
Int32 lengthRead = ms.Read(buffer, 0, blockSize);
Response.OutputStream.Write(buffer, 0, lengthRead);
dataLengthToRead = dataLengthToRead - lengthRead;
}
Response.Flush();
Response.Close();
}
// End the response
Response.End();
Thanks