Sending a ZIP file as a ASHX

Last post 09-13-2005 5:22 PM by davidebb. 1 replies.

Sort Posts:

  • Sending a ZIP file as a ASHX

    09-13-2005, 3:17 PM
    Locked
    • Member
      190 point Member
    • eemece2
    • Member since 06-03-2003, 7:32 AM
    • Posts 38
    Hello,

    Until now I am using the following code to loading  a XML file and sending as a ashx page response. (I do this for security reasons)
    But now I want to send a ZIP file (or any other binary file) instead the XML file.
    How can I do this?
    what time of stream I need to use, and how?
    public class XmlBackupHandler : IHttpHandler
        {
            public bool IsReusable { get { return true; } }

            public void ProcessRequest(HttpContext ctx)
            {
               XmlDocument xmlBackup = new XmlDocument();
               xmlBackup.Load(HttpContext.Current.Server.MapPath("~/temp/file.xml"));
              ctx.Response.ContentType = "text/xml"; // may bee "application/x-zip-compressed" ?
              xmlBackup.Save(ctx.Response.OutputStream);
            }
        }

    Thanks you very much,
    Edu

  • Re: Sending a ZIP file as a ASHX

    09-13-2005, 5:22 PM
    Locked
    • Contributor
      5,655 point Contributor
    • davidebb
    • Member since 06-11-2002, 8:31 AM
    • Redmond, WA
    • Posts 1,123
    Try something like this:

        public void ProcessRequest(HttpContext context) {
            context.Response.ContentType = "application/x-zip-compressed";
            context.Response.TransmitFile(context.Server.MapPath("~/temp/file.zip"));
        }

    David
Page 1 of 1 (2 items)