Developer forum

Forum » Development » FileManager permissions

FileManager permissions

Jonas Mersholm
Reply

Hi there. I've created a new folder

Dynamicweb.Content.Files.FilesAndFolders.CreateFolder("/Filer/Forhandler", User.Name);

 

How do i get around, setting permissions for that single folder? It is not representet as a object with any permission values.

 

best regards

Jonas


Replies

 
Morten Bengtson
Reply

Hi Jonas,

Setting up permissions is not a simple task in Dynamicweb, but below is a working example.

Remember to also disable read access to the secure folder in IIS if you don't want these files to be accessible by entering the full URL in a browser.

// Get the user.
var user = User.GetUserByID(256);

// Get the path to the files folder - either "/Files" or "/Filer".
var filesFolderPath = "/" + Installation.FilesFolderName;

// Get the path to the secure folder (Management Center > Control Panel > Modules > User Management > Extranet secure folder).
// Note: This requires that you have already set up a secure folder (e.g. "Forhandler") with permissions (deny "All", allow access for user group "Forhandler").
var secureFolderName = Base.ChkString(Base.GetGs("/Globalsettings/Modules/Users/SecureFolderName"));
var secureFolderPath = filesFolderPath + "/" + secureFolderName;

// Create a folder for this user
var folderName = FilesAndFolders.GetValidFileAndFolderName(user.Name);
var folderPath = secureFolderPath + "/" + folderName;
FilesAndFolders.CreateFolder(secureFolderPath, folderName);

// Deny anonymous access (id = 0 is "All")
var permissionAnonymous = Permission.GetPermissionByID("0", folderPath) ?? new Permission();
permissionAnonymous.AccessElementPermissionElementTextID = folderPath;
permissionAnonymous.AccessElementPermissionTypeID = 1;
permissionAnonymous.AccessElementPermissionUserID = 0;
permissionAnonymous.AccessElementPermissionTypePermission = Permission.FolderPermissionAccess.Deny;
permissionAnonymous.Save();

// Allow access for a given user / group
var permission = Permission.GetPermissionByID(user.ID.ToString(CultureInfo.InvariantCulture), folderPath) ?? new Permission();
permission.AccessElementPermissionElementTextID = folderPath;
permission.AccessElementPermissionTypeID = 1;
permission.AccessElementPermissionUserID = user.ID;
permission.AccessElementPermissionTypePermission = Permission.FolderPermissionAccess.Allow;
permission.Save();

 

You must be logged in to post in the forum