Download whitepaper widget

Posted by Community Admin on 04-Aug-2018 16:33

Download whitepaper widget

All Replies

Posted by Community Admin on 22-May-2013 00:00

Does anyone have working code to create a download form simliar to Sitefinity's ( http://www.sitefinity.com/campaigns/whitepapers/mvc-whitepaper ) which requires a user to enter in their information before being able to download a file?

Posted by Community Admin on 27-May-2013 00:00

Hello Amanda,

You could create a custom Forms control by inheriting from FormsControl class and overriding the Submit_Click event like so:

protected override void Submit_Click(object sender, EventArgs e)
        
            base.Submit_Click(sender, e);
 
            var manager = LibrariesManager.GetManager();
            Document doc = manager.GetDocuments().Where(d => d.Title == "DocumentTitle" && d.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master).FirstOrDefault();
            
            //Set the appropriate ContentType.
            HttpContext.Current.Response.ContentType = "text/plain"; // "Application/msword", "image/Jpeg" etc..
             
            string filePath = HttpContext.Current.Request.MapPath(doc.Url);
             
            HttpContext.Current.Response.WriteFile(filePath);
            
        

Register the custom Forms control in the toolboxes and drop it on a page to try it out.

Regards,
Pavel Benov
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 28-May-2013 00:00

Hi Pavel,
Thanks for the response. I tried using this code, but I receive the following message.

'http:/localhost:2596/docs/default-source/press-materials/press-pass-form_editable.pdf' is not a valid virtual path.

Posted by Community Admin on 31-May-2013 00:00

Hello Amanda,

Try with the following:

protected override void Submit_Click(object sender, EventArgs e)
        
            base.Submit_Click(sender, e);
 
            var manager = LibrariesManager.GetManager();
            Document doc = manager.GetDocuments().Where(d => d.Title == "DocTitle" && d.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master).FirstOrDefault();
            
            string url = doc.Url + "&download=true";
            HttpContext.Current.Response.Redirect(url, false);
        
 

Regards,
Pavel Benov
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 31-May-2013 00:00

Hi Pavel,
Thanks for the code. This does prompt the user to download the file. However, it also ends the process and does not continue on with the "successful submission" message. I'll try looking for a solution for this. If you do have something, please let me know.
THanks!

Posted by Community Admin on 04-Jun-2013 00:00

Hi Amanda,

Try to force it to download in a new tab like so:

protected override void Submit_Click(object sender, EventArgs e)
        
            base.Submit_Click(sender, e);
            var manager = LibrariesManager.GetManager();
            Document doc = manager.GetDocuments().Where(d => d.Title == "LoL" && d.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master).FirstOrDefault();
            
            string url = doc.Url + "&download=true";
            //HttpContext.Current.Response.Redirect(url, false);
            HttpContext.Current.Response.Write("<script> window.open( '" + url + "' ); </script>");
        
 
I hope this helps.

Regards,
Pavel Benov
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed