1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Download List - send email on clicking download link

Download List - send email on clicking download link

4 posts, 0 answered
  1. Sachin Sood
    Sachin Sood avatar
    2 posts
    Registered:
    31 Aug 2009
    22 Sep 2009
    Link to this post
    Hello,

    We have a downloads section on our web site that we will display only if the user is signed in to the site.  The downloadable files are listed using the Download List control.  When they sign in and download any file from the site, we want to do 2 things:

    - record the download activity of this member in the DB.
    - send an email to us with the member details and what file was downloaded.

    How can we achieve this?

    Thanks in advance.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 May 2017
    22 Sep 2009
    Link to this post
    Hello Sachin Sood,

    Currently we do not support statistics so you should implement some custom logic that tracks the downloads.

    Below is a sample working code:

    using System;  
    using System.Web;  
    using System.Web.Mail;  
    using Telerik.Cms.Engine;  
     
      
    public class CustomContentHttpHandler : ContentHttpHandler  
    {  
          public override void ProcessRequest(HttpContext context)  
            {  
                string path = String.Concat(context.Request.ApplicationPath, "/Libraries/MembersOnly/");  
                if (context.Request.RawUrl.StartsWith(path, StringComparison.OrdinalIgnoreCase))  
                {  
     
                    string statement= "INSERT INTO mytable ([date],[path]) VALUES (GETDATE(),'" + context.Request.RawUrl.ToString() + "')";  
                    SqlConnection connection = new SqlConnection();  
                    connection .ConnectionString = ConfigurationManager.ConnectionStrings["Sitefinity"].ConnectionString;  
                    connection .Open();  
                    SqlCommand command= new SqlCommand(statement, connection );  
                    command.CommandType = CommandType.Text;  
                    try  
                    {  
                        command.ExecuteNonQuery();  
      
                    }  
                    catch (SqlException ex)  
                    {  
                           
                    }  
                    finally  
                    {  
                        if (command!= null) command.Dispose();  
                        // Send mail message using  MailMessage class. 
                          
                    }  
      
                    connection.Close();  
                }  
                base.ProcessRequest(context);  
            } 
    }  
      

    You should crate a new table in the database to store the request. This will allow you to preview them later. I hope this helps.
     

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Sachin Sood
    Sachin Sood avatar
    2 posts
    Registered:
    31 Aug 2009
    22 Sep 2009
    Link to this post
    Thanks a lot for the sample code!  I'll try it out and see how it works.

    Wishing you and your team in Bulgaria a Happy Independence day!
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 May 2017
    22 Sep 2009
    Link to this post
    Hello Sachin Sood,

    Thank you for getting back to me. Let us know if there is anything else that we can do for you.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered