Download whitepaper widget
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?
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); 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.
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); 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!
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>");