More in this section

Forums / General Discussions / Update documents in DocumentLibrary

Update documents in DocumentLibrary

2 posts, 1 answered
  1. Ilaria
    Ilaria avatar
    25 posts
    Registered:
    20 Jan 2011
    16 Feb 2011
    Link to this post
    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?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Feb 2011
    Link to this post
    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
    Answered
2 posts, 1 answered