This is a migrated thread and some comments may be shown as answers.

Direct Download Example

5 Answers 275 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 03 Aug 2009, 09:13 PM
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

5 Answers, 1 is accepted

Sort by
0
ManniAT
Top achievements
Rank 2
answered on 03 Aug 2009, 09:47 PM
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
0
Josh
Top achievements
Rank 1
answered on 04 Aug 2009, 11:37 AM
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
0
Bryan Davis
Top achievements
Rank 1
answered on 23 Feb 2010, 02:47 PM
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  
    }  
}    
0
Tommy
Top achievements
Rank 1
answered on 17 Jun 2010, 08:17 PM
What about a VB version of the file, I tried converting it but it doesn't seem to want to work ...
0
Dobromir
Telerik team
answered on 21 Jun 2010, 12:59 PM
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
Tags
FileExplorer
Asked by
Josh
Top achievements
Rank 1
Answers by
ManniAT
Top achievements
Rank 2
Josh
Top achievements
Rank 1
Bryan Davis
Top achievements
Rank 1
Tommy
Top achievements
Rank 1
Dobromir
Telerik team
Share this question
or