1

I'm getting the [Exception: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))] when trying to import documentSet programmatically from a site collection document library to another document lib located in on of his subsites.

PS: this code works perfectly with a FULL Control in site collection but not with contribute or Modification Role.

My question is what is the minimum role to be able to execute the code?

SPList publishingList = publishingWeb.TryGetListByUrl("PublishedCases/");
byte[] compressedFile = docSet.Export();
SPContentType secondCt = publishingList.ContentTypes["DOCLIB"];
SPFolder targetFolder = publishingList.RootFolder; 
DocumentSet publishedDocSet = DocumentSet.Import(compressedFile, myitem.Name, targetFolder, secondCt.Id, properties, elevateWeb.CurrentUser);

Regards,

0

I actually did it with Elevate Privileges but still dont know the minimum permissions to be able to create document Set programatically.

SPUserToken sysToken = SPContext.Current.Site.SystemAccount.UserToken;
using (SPSite elevatedSite = new SPSite(site.ID, sysToken))
{    
    using (SPWeb elevatePublishingWeb = elevatedSite.OpenWeb("Publishing"))
    {
         //Code here ....
         SPList publishingList = 
         elevatePublishingWeb.TryGetListByUrl("PublishedCases/");
         byte[] compressedFile = docSet.Export();
         SPContentType secondCt = publishingList.ContentTypes["CT_DOCLIB"];
         SPFolder targetFolder = publishingList.RootFolder; 
         DocumentSet publishedDocSet = DocumentSet.Import(compressedFile, 
         myitem.Name, targetFolder, secondCt.Id, properties, elevateWeb.CurrentUser);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.