All,
I hope someone can help me here.
Here is my problem. I have some code for download a file working on IIS 5, but I have some problems on IIS 6.
I have one function for give me one byte array using de method DownloadData
public byte[] GetAttachment(int portalId, int objectTypeCode, string attachId, int sizeBuffer, string contentType,ref string encodingBodyName,ref string encodingWebName)
{
string url = "http://" + this.m_server + "/Activities/Attachment/download.aspx?AttachmentType=" + Convert.ToString(objectTypeCode) + "&AttachmentId={" + attachId + "}";
System.Net.WebClient webClient = new System.Net.WebClient();
webClient.Credentials = this.m_credentials;
byte[] data = webClient.DownloadData(url);
return data;
}
Then I use the same array for download on client using the object Response:
AttachmentInfo attachmentInfo = CrmIncidentController.GetAttachment(PortalId, annotationId);
....
//clear the output buffer
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
//header
Response.AppendHeader("Cache-Control", "no-store, no-cache, must-revalidate");
Response.AppendHeader("Content-Length", attachmentInfo.Content.Length.ToString());
Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + attachmentInfo.FileName + "\"");
Response.ContentType = attachmentInfo.ContentType;
Response.Buffer = true;
//cache
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
Response.BinaryWrite(attachmentInfo.Content);//it's the same array from GetAttachment
Response.Flush();
Response.Close();
Response.End();
If write for the server the file it’s OK, but on the browse give me the "file is corrupted"
Thanks for any help you can offer,