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

Forums / Developing with Sitefinity / Download whitepaper widget

Download whitepaper widget

6 posts, 0 answered
  1. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    22 May 2013
    Link to this post
    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?
  2. Pavel Benov
    Pavel Benov avatar
    341 posts
    Registered:
    14 Mar 2016
    27 May 2013
    Link to this post
    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
  3. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    28 May 2013 in reply to Pavel Benov
    Link to this post
    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.
  4. Pavel Benov
    Pavel Benov avatar
    341 posts
    Registered:
    14 Mar 2016
    31 May 2013
    Link to this post
    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
  5. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    31 May 2013 in reply to Pavel Benov
    Link to this post
    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!
  6. Pavel Benov
    Pavel Benov avatar
    341 posts
    Registered:
    14 Mar 2016
    04 Jun 2013
    Link to this post
    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
6 posts, 0 answered