Hi,
I'm refactoring an old module originally written for DNN 5 and upgraded to DNN 7. It uses the FileSystemUtils.GetRoles feature to set a permission (read/write) on a given folder in the module directory. I understand that FolderManager has additional functionality and am seeking code samples / suggestion on how best to refactor the following:
public static System.Web.UI.WebControls.DropDownList GetFolderDDL(System.Web.UI.WebControls.DropDownList ddl, DirectoryInfo ChildDirectory, DotNetNuke.Entities.Portals.PortalSettings portalSettings, int portalId, string folder, FolderPermissionInfo permissionsInfo, IFolderInfo folderInfo)
{
string readRoles;
string writeRoles;
PortalInfo portalInfo = new PortalInfo();
if (ChildDirectory == null)
{
ChildDirectory = new DirectoryInfo(portalSettings.HomeDirectoryMapPath);
ddl.Items.Clear();
System.Web.UI.WebControls.ListItem rootItem = new System.Web.UI.WebControls.ListItem();
rootItem.Text = "Root";
rootItem.Value = String.Empty;
readRoles = DotNetNuke.Common.Utilities.FileSystemUtils.GetRoles("", portalSettings.PortalId, "READ");
writeRoles = DotNetNuke.Common.Utilities.FileSystemUtils.GetRoles("", portalSettings.PortalId, "WRITE");
if ((DotNetNuke.Security.PortalSecurity.IsInRoles(readRoles) || (DotNetNuke.Security.PortalSecurity.IsInRoles(writeRoles))))
{
ddl.Items.Add(rootItem);
}
}
DirectoryInfo currentDir = ChildDirectory;
DirectoryInfo[] childDirs;
string parentFolderName;
parentFolderName = ChildDirectory.FullName.Substring(portalSettings.HomeDirectoryMapPath.Length);
currentDir = ChildDirectory;
childDirs = currentDir.GetDirectories();
foreach (DirectoryInfo dir in childDirs)
{
System.Web.UI.WebControls.ListItem folderItem = new System.Web.UI.WebControls.ListItem();
string itemText = parentFolderName.Replace(@"\", "/") + "/" + dir.Name;
if (itemText.StartsWith("/"))
itemText = itemText.Remove(0, 1);
if (itemText.EndsWith("/"))
itemText = itemText.Remove(itemText.Length - 1, 1);
//readRoles = DotNetNuke.Common.Utilities.FileSystemUtils.GetRoles(itemText, portalSettings.PortalId, "READ");
readRoles = FolderPermissionController.GetFolderPermissionsCollectionByFolder(portalId, folder).ToString();
//writeRoles = DotNetNuke.Common.Utilities.FileSystemUtils.GetRoles(itemText, portalSettings.PortalId, "WRITE");
writeRoles = FolderPermissionController.SaveFolderPermissions(folderInfo);
if ((DotNetNuke.Security.PortalSecurity.IsInRoles(readRoles) || (DotNetNuke.Security.PortalSecurity.IsInRoles(writeRoles))))
{
folderItem.Text = itemText;
folderItem.Value = itemText + "/";
ddl.Items.Add(folderItem);
}
if (dir.GetDirectories().Length > 0)
ddl = GetFolderDDL(ddl, dir, portalSettings, portalId, folder, folderInfo);
}
return ddl;
}
You'll note that I experimented with the FolderPermissionController.SaveFolder feature. However, I'm uncertain whether this is considered best practice for DNN 9? Greatly appreciate advice and guidance.
Thanks,
Sid