Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Using Response.BinaryWrite and DownloadDataUsing Response.BinaryWrite and DownloadData
Previous
 
Next
New Post
12/28/2007 11:33 AM
 

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,

Jorge Marques
Actua Software
 
New Post
12/28/2007 11:21 PM
 

I think you have to get rid of the flush(). Here is what I have in the Survey Module:

Response.Clear()
            Response.AddHeader("content-disposition", "attachment; filename=Survey_Results_" + ModuleId.ToString + "_" + DateTime.Now.ToShortDateString().Replace("/", "_") + ".csv")
            Response.Charset = ""
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Dim stringWriter As System.IO.StringWriter = New System.IO.StringWriter()
            Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWriter)

            stringWriter.Write("Question,Option,Option Type,Is Correct?,UserID" & vbCrLf)

            Dim colSurveyResultInfo As List(Of SurveyResultInfo) = SurveyOptionController.GetSurveyResultData(ModuleId)
            Dim objSurveyResultInfo As SurveyResultInfo

            For Each objSurveyResultInfo In colSurveyResultInfo
                stringWriter.Write(objSurveyResultInfo.Question & "," & objSurveyResultInfo.OptionName & "," & objSurveyResultInfo.OptionType & "," & objSurveyResultInfo.IsCorrect & "," & objSurveyResultInfo.UserId & vbCrLf)
            Next

            Response.Write(stringWriter.ToString())
            Response.End()



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
12/29/2007 2:06 AM
 

After searching for your solution , i got below link for you .Just go thru it ,that may help you .

http://aspspider.info/magicalspell4u/?quest=ResponseBinaryWrite

-Thanks

52

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Using Response.BinaryWrite and DownloadDataUsing Response.BinaryWrite and DownloadData


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out