Update documents in DocumentLibrary

Posted by Community Admin on 03-Aug-2018 12:22

Update documents in DocumentLibrary

All Replies

Posted by Community Admin on 16-Feb-2011 00:00

Hello!
I need to update some properties of a document directly from code. I try, for example, to update the property ViewsCounter. This is the code:

var linkButton = sender as System.Web.UI.WebControls.LinkButton;
     if (linkButton != null)
    
           string text = ((System.Web.UI.WebControls.LinkButton)(sender)).Text;
  
           LibrariesManager libManager = LibrariesManager.GetManager();
           IQueryable<Document> documents = libManager.GetDocuments().Where(o1 => o1.ApprovalWorkflowState == "PUBLISHED");
  
           Document doc = documents.Where(o1 => o1.Title == text).FirstOrDefault();
           doc.ViewsCount++; 
  
           libManager.SaveChanges();

But when i run the program, it return me this Error:
    "You are not authorized to 'Modify library and manage documents' ('Document')."
Why? Is there any mistakes in the code?

Another question:
when the code executes in a custom user control, the permission of the user (in other words the current user that's in sitefinity) is the one of the user or can I force to execute it as an Admin?

Posted by Community Admin on 21-Feb-2011 00:00

Hello Ilaria,

The user you use does not have permissions to modify document items. If this user is not authenticated you should use SuppressSecurityChecks property of the provider and set it to true.

Greetings,
Ivan Dimitrov
the Telerik team

This thread is closed