Direct Download Example

6 posts, 0 answers
  1. Josh
    Josh avatar
    46 posts
    Member since:
    May 2009

    Posted 03 Aug 2009 Link to this post

    In the direct download example, Handler.ashx is referenced.  I am looking for the
    code that makes up that generic file, because I can't get the direct download
    to work right without it.  I looked everywhere, however, I might have missed it.
    Thanks in advance.

  2. ManniAT
    ManniAT avatar
    885 posts
    Member since:
    Nov 2003

    Posted 03 Aug 2009 Link to this post


    you are right - this file is not browsable in the samples.
    But you can find it in the following directory on your local machine (after installing rad controls):
    <%PROGRAM_FILES%>\telerik\RadControls for ASP.NET AJAX Q2 2009\Live Demos\FileExplorer\Examples\FilterAndDownloadFiles


  3. Josh
    Josh avatar
    46 posts
    Member since:
    May 2009

    Posted 04 Aug 2009 Link to this post


     Thanks for the reply.  I looked through the folders and I do not have that folder.  Could you
    please post on here, so that I may duplicate it on my machine.  I wonder why they didn't
    post the Handler.ashx in the online example?

  4. Bryan Davis
    Bryan Davis avatar
    24 posts
    Member since:
    Jan 2008

    Posted 23 Feb 2010 Link to this post

    Here is the code for the handler incase you still need it.

    <%@ WebHandler Language="C#" Class="Telerik.Web.Examples.FileExplorer.FilterAndDownloadFiles.Handler" %>  
    using System;  
    using System.Data;  
    using System.Configuration;  
    using System.Web;  
    using System.Text;  
    using Telerik.Web.UI;  
    namespace Telerik.Web.Examples.FileExplorer.FilterAndDownloadFiles  
        [RadCompressionSettings(HttpCompression = CompressionType.None)] // Disable RadCompression for this page ;  
        public class Handler : IHttpHandler  
            #region IHttpHandler Members  
            private HttpContext _context;  
            private HttpContext Context  
                    return _context;  
                    _context = value;  
            public void ProcessRequest(HttpContext context)  
                Context = context;  
                string filePath = context.Request.QueryString["path"];  
                filePath = context.Server.MapPath(filePath);  
                if (filePath == null)  
                System.IO.StreamReader streamReader = new System.IO.StreamReader(filePath);  
                System.IO.BinaryReader br = new System.IO.BinaryReader(streamReader.BaseStream);  
                byte[] bytes = new byte[streamReader.BaseStream.Length];  
                br.Read(bytes, 0, (int)streamReader.BaseStream.Length);  
                if (bytes == null)  
                string extension = System.IO.Path.GetExtension(filePath);  
                string fileName = System.IO.Path.GetFileName(filePath);  
                if (extension == ".jpg")  
                { // Handle *.jpg and  
                    WriteFile(bytes, fileName, "image/jpeg jpeg jpg jpe", context.Response);  
                else if (extension == ".gif")  
                {// Handle *.gif  
                    WriteFile(bytes, fileName, "image/gif gif", context.Response);  
                else if (extension == ".pdf")  
                {// Handle *.pdf  
                    WriteFile(bytes, fileName, "application/pdf", context.Response);  
            /// <summary>  
            /// Sends a byte array to the client  
            /// </summary>  
            /// <param name="content">binary file content</param>  
            /// <param name="fileName">the filename to be sent to the client</param>  
            /// <param name="contentType">the file content type</param>  
            private void WriteFile(byte[] content, string fileName, string contentType, HttpResponse response)  
                response.Buffer = true;  
                response.ContentType = contentType;  
                response.AddHeader("content-disposition""attachment; filename=" + fileName);  
            public bool IsReusable  
                    return false;  
  5. Tommy
    Tommy avatar
    23 posts
    Member since:
    Jun 2009

    Posted 17 Jun 2010 Link to this post

    What about a VB version of the file, I tried converting it but it doesn't seem to want to work ...
  6. Dobromir
    Dobromir avatar
    1633 posts

    Posted 21 Jun 2010 Link to this post

    Hi Tommy,

    You can use the this online code converter tool in order to convert C# into VB.
    For your convenience I have converted the handler's code into VB. Please, find the attached file.

    Sincerely yours,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top