I have a consoled based application that imports assets (images) for the catalog products in EPI Server.
The program creates the blob successfully but when I call the _contentRepository.Save(file, EPiServer.DataAccess.SaveAction.Publish); I get an error saying "Access was denied to content 157. The required access level was "Create, Publish""
Running the same code within Website context does not give me that acception.
I am running the consoled based application as admin so access level should not be a problem.
I was able to resolve this on saving the content by settting up the priciplal on the current thread
WindowsIdentity myIdentity = WindowsIdentity.GetCurrent(); IPrincipal wp = new WindowsPrincipal((WindowsIdentity)myIdentity); Thread.CurrentPrincipal = wp;
but when I try to associate the image with Variation, I get the same access issue
var variant = (VariationContent)contentLoader.Get<VariationContent>(variantLink).CreateWritableClone(); variant.CommerceMediaCollection.Add(commerceMedia); contentRepository.Save(variant, EPiServer.DataAccess.SaveAction.Publish);
Did you try with contentRepository.Save(variant, EPiServer.DataAccess.SaveAction.Publish, AccessLevel.NoAccess); ?
That worked. Thanks Quan,