You can try with:
contentRepository.Save(newFolder, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);
Regards.
/Q
Yes. AccessLevel.NoAccess will work and keeps me from getting an exception when running the code but I cannot edit the folder from the UI.
Regards
Alex
What is the parent in this case?
By default a newly created content item will inherit the access from it's parent. If you go into admin mode and checks the access rights for the item and it's parent, does the user (you??) have enough access to modify the item?
Ok, did a little more research. The folders we are talking about are migrated from VPP. Before you could set access rights, change name or otherwise do stuff with the folders from the UI but now i can't seem to find the access editor and the edit choices on the folder are greyed out.
But, to answer your question, Johan: The parent in this case is a contentfolder located two steps down from the folder named "For this site". I am logged in as a WebAdmin user when the code runs and also when in the UI, so I think I should be allowed to.
If anyone needs it here's the proper way to do it.
public ContentFolder CreateFolder(int parentFolderId, string folderName)
{
var parentFolder = GetFolder(parentFolderId);
if (parentFolder == null)
return null;
if (FolderExists(parentFolderId, folderName))
throw new DuplicateNameException();
var newFolder = contentRepository.GetDefault<ContentFolder>(parentFolderId.GetContentReference());
newFolder.Name = folderName;
var newFolderRef = contentRepository.Save(newFolder, SaveAction.Publish);
/* Set access rights */
var securityDescriptor =
_securityRepository.Get(folderId.GetContentReference()).CreateWritableClone() as IContentSecurityDescriptor;
securityDescriptor.IsInherited = false;
securityDescriptor.AddEntry(new AccessControlEntry(someEpiServerUserId, AccessLevel.Delete | AccessLevel.Create | AccessLevel.Read | AccessLevel.Edit | AccessLevel.Publish, SecurityEntityType.User));
_securityRepository.Save(folderId.GetContentReference(), securityDescriptor, SecuritySaveType.Replace);
return newFolder;
}
Hi there.
I'm trying to create ContentFolders programmatically but I am not sure I'm doing it the right way. It seems that I have to save the new folder with AccessRight.NoAccess to not get an AccessDeniedException (Current user is WebAdministrator) But then I can't perform any operations on the folder in the UI. Here's my code:
public ContentFolder CreateFolder(int parentFolderId, string folderName)
{
var parentFolder = GetFolder(parentFolderId);
if (parentFolder == null)
return null;
var newFolder = contentRepository.GetDefault<ContentFolder>(new ContentReference(parentFolder.ContentLink.ID));
newFolder.Name = folderName;
contentRepository.Save(newFolder, SaveAction.Publish, AccessLevel.Publish);
return newFolder;
}
Please advice
/Alex