Downloading documents
I want to have some LinkButtons to download files, and on click of those I'd like to update the viewcount of the document.
So that part I can do...(quite nice with fluent)
How do I get the download URL of the document (the embed link we get in the backend). Is it safe to just call the standard URL method, and append the extension and ?Status=Master or is there a better way.
**EDIT**
Ok, so turns out the updating viewcount fails when I try it as a user not logged in...?
Line 56: Document doc = lm.GetDocument(documentID);
Line 57: doc.ViewsCount = doc.ViewsCount + 1;
Line 58: lm.SaveChanges();
Line 59:
Line 60: Response.Redirect(lm.GetItemUrl(doc) + doc.Extension + "?Status=Master");
|
[UnauthorizedAccessException: You are not authorized to 'Modify library and manage documents' ('Document').] DynamicModule.ns.Wrapped_OpenAccessLibrariesProvider_d00af4c87f854b479dd3d3f88b3444e1.CommitTransaction() +342 Telerik.Sitefinity.Data.ManagerBase`1.SaveChanges() +53 SitefinityWebApp.UserControls.Publications.Publications.OnDownload_Click(Object sender, EventArgs e) in C:\My Dropbox\Projects\Leap\OCFP\Web\UserControls\Publications\Publications.ascx.cs:58 System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +155 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691 |
Hi Steve,
The code fails, because you cannot make modifications to an object with the api if the current user ( which in your case is anonymous ) is not granted with modify permissions.
You can use Manager.Provider.SuppressSecurityChecks = true; in your code to allow SaveChanges to be processed then set SuppressSecurityChecks back to false which is its initial state.
Best wishes,
Ivan Dimitrov
the Telerik team