title: Creating Documents Sitefinity backend non admin user
body: <p>I'm running into a problem with the telerik sitefinity api. I'm trying to create pdf certifications in the backend and publish them to the documents library. Here is my code for how I create and publish the certifications.</p>
  
  <pre><code>   byte[] byteArray = reportViewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);
  
                  var documentLibraryList = SitefinityHelper.GetDocumentLibraries();
  
                  string certificationLibraryTitle = ConfigurationManager.AppSettings["CertificationLibrary"].ToString().ToUpper();
  
                  DocumentLibrary certLibrary = null;
  
                  //Make sure the parent library exists before doing anything else.
                  foreach (DocumentLibrary library in documentLibraryList)
                  {
                      if (library.Title.ToUpper() == certificationLibraryTitle.ToUpper())
                      {
                          certLibrary = library;
                          break;
                      }
                  }
                  //If not null, good to create the pdf cert, but need to check for previous ones.
                  if (certLibrary != null)
                  {
                      try
                      {
  
  
                          string pdfCertificationTitle = currentUser.UserName + "_"+ "Certification_" + moduleViewModel.ExamID.ToString();
  
                          UserCertifications previousCertifcationRecord = certBo.GetUserCertificationByTitle(pdfCertificationTitle);
  
                          if (previousCertifcationRecord == null)
                          {
                              //No previous record exists, create the new record. 
  
                              MemoryStream memStream = new MemoryStream(byteArray);
  
                              Guid documentID = Guid.NewGuid();
  
                              string format = ".pdf";
  
                              LibrariesManager librariesManager = LibrariesManager.GetManager();
  
                              Document pdfDocument = librariesManager.CreateDocument(documentID);
  
                              DocumentLibrary parentLibrary = librariesManager.GetDocumentLibraries().Where(d =&gt; d.Id == certLibrary.Id).SingleOrDefault();
  
                              pdfDocument.Parent = parentLibrary;
  
                              pdfDocument.Title = pdfCertificationTitle;
                              pdfDocument.DateCreated = DateTime.UtcNow;
                              pdfDocument.PublicationDate = DateTime.UtcNow;
                              pdfDocument.LastModified = DateTime.UtcNow;
                              pdfDocument.UrlName = Regex.Replace(pdfCertificationTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
  
                              librariesManager.RecompileAndValidateUrls(pdfDocument);
                              librariesManager.Upload(pdfDocument, memStream, format);
  
                              librariesManager.SaveChanges();
  
                              var bag = new Dictionary&lt;string, string&gt;();
                              bag.Add("ContentType", typeof(Document).FullName);
  
                              WorkflowManager.MessageWorkflow(documentID, typeof(Document), null, "Publish", false, bag);
  
                              string fullUrl = SitefinityHelper.GetDocumentUrl(pdfCertificationTitle);
  
                              //Save the certification to the DB.
                              certBo.InsertNewUserCertification(pdfCertificationTitle, fullUrl, currentUser.UserID);
                          }
                      }
  
                      catch (Exception ex)
                      {
                          ExceptionManager.LogException(this, ex);
                      }
                  }
  </code></pre>
  
  <p>The exception message that I'm running into is:</p>
  
  <p><strong>Telerik.Sitefinity.Libraries.Model.DocumentLibrary, Telerik.Sitefinity.Model was not granted ManageDocument in Document for principals with IDs</strong></p>
  
  <p>However, this exception, only occurs when I try to create and publish the pdf document when I'm logged in as a non-admin / non-backend user. When I'm logged in as a backend user this code executes just fine. I believe there must be a way to set a permission in order to allow non-backend users the proper authority to create documents but I just dont know how and googling didn't reveal much. If anyone could please help I would really appreciate it. </p>
  
  <p>This is using Sitefinity version 6.2</p>