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.

    Joshua
  2. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 03 Aug 2009 Link to this post

    Hi,

    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

    Regards

    Manfred
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Josh
    Josh avatar
    46 posts
    Member since:
    May 2009

    Posted 04 Aug 2009 Link to this post

    ManniAT,

     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?

    Joshua
  5. 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  
            {  
                get 
                {  
                    return _context;  
                }  
                set 
                {  
                    _context = value;  
                }  
            }  
     
     
            public void ProcessRequest(HttpContext context)  
            {  
                Context = context;  
                string filePath = context.Request.QueryString["path"];  
                filePath = context.Server.MapPath(filePath);  
     
                if (filePath == null)  
                {  
                    return;  
                }  
     
                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)  
                {  
                    return;  
                }  
     
                streamReader.Close();  
                br.Close();  
                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.Clear();  
                response.ContentType = contentType;  
     
                response.AddHeader("content-disposition""attachment; filename=" + fileName);  
     
                response.BinaryWrite(content);  
                response.Flush();  
                response.End();  
            }  
     
            public bool IsReusable  
            {  
                get 
                {  
                    return false;  
                }  
            }
            #endregion  
        }  
    }    
  6. 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 ...
  7. Dobromir
    Admin
    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,
    Dobromir
    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
UI for ASP.NET Ajax is Ready for VS 2017