public override Stream GetFile(string url)
        {
            //base calls CheckWritePermissions method
            Stream fileContent = null;
            var    folderPath  = FileSystemValidation.ToDBPath(url);
            var    fileName    = GetFileName(url);
            var    folder      = DNNValidator.GetUserFolder(folderPath);

            if (folder != null)
            {
                var file = FileManager.Instance.GetFile(folder, fileName);
                if (file != null)
                {
                    fileContent = FileManager.Instance.GetFileContent(file);
                }
            }
            return(fileContent);
        }
Example #2
0
        public virtual IDictionary <string, FolderInfo> GetChildUserFolders(string parentPath)
        {
            string dbPath = (string)(string)FileSystemValidation.ToDBPath(parentPath);
            IDictionary <string, FolderInfo> returnValue = new Dictionary <string, FolderInfo>();

            if (string.IsNullOrEmpty(dbPath))
            {
                //Get first folder children
                foreach (string folderPath in UserFolders.Keys)
                {
                    if (folderPath.IndexOf("/") == folderPath.LastIndexOf("/"))
                    {
                        returnValue.Add(folderPath, UserFolders[folderPath]);
                    }
                }
            }
            else
            {
                foreach (string folderPath in UserFolders.Keys)
                {
                    if (folderPath == dbPath || !(folderPath.StartsWith(dbPath)))
                    {
                        continue;
                    }

                    if (folderPath.Contains(dbPath))
                    {
                        string childPath = folderPath.Substring(dbPath.Length);
                        if (childPath.LastIndexOf("/") > -1)
                        {
                            childPath = childPath.Substring(0, childPath.Length - 1);
                        }

                        if (!(childPath.Contains("/")))
                        {
                            returnValue.Add(folderPath, UserFolders[folderPath]);
                        }
                    }
                }
            }

            return(returnValue);
        }
Example #3
0
        public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
        {
            try
            {
                // TODO: Create entries in .resx for these messages
                Uri uri;
                if (!Uri.TryCreate(name, UriKind.Relative, out uri))
                {
                    ShowMessage(string.Format("The file {0} cannot be uploaded because it would create an invalid URL. Please, rename the file before upload.", name));
                    return("");
                }

                var invalidChars = new[] { '<', '>', '*', '%', '&', ':', '\\', '?', '+' };
                if (invalidChars.Any(uri.ToString().Contains))
                {
                    ShowMessage(string.Format("The file {0} contains some invalid characters. The file name cannot contain any of the following characters: {1}", name, new String(invalidChars)));
                    return("");
                }

                string virtualPath = FileSystemValidation.ToVirtualPath(path);

                string returnValue = DNNValidator.OnCreateFile(FileSystemValidation.CombineVirtualPath(virtualPath, name), file.ContentLength);
                if (!string.IsNullOrEmpty(returnValue))
                {
                    return(returnValue);
                }

                var folder = DNNValidator.GetUserFolder(virtualPath);

                var fileInfo = new Services.FileSystem.FileInfo();
                FillFileInfo(file, ref fileInfo);

                //Add or update file
                FileManager.Instance.AddFile(folder, name, file.InputStream);

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, name));
            }
        }
        private void AddUserFolder(ref DirectoryItem[] directories, bool loadFiles)
        {
            var usersMainFolder = directories.SingleOrDefault(d => d.Name.ToUpper() == "USERS");

            if (usersMainFolder != null)
            {
                var userFolder = FolderManager.Instance.GetUserFolder(CurrentUser);
                usersMainFolder.Name = FolderManager.Instance.MyFolderName;
                string endUserPath = (string)FileSystemValidation.ToEndUserPath(userFolder.FolderPath);
                usersMainFolder.FullPath = endUserPath;

                var folderPermissions = PathPermissions.Read;
                if (DNNValidator.CanViewFilesInFolder((FolderInfo)userFolder))
                {
                    if (DNNValidator.CanAddToFolder((FolderInfo)userFolder))
                    {
                        folderPermissions = folderPermissions | PathPermissions.Upload;
                    }

                    if (DNNValidator.CanDeleteFolder((FolderInfo)userFolder))
                    {
                        folderPermissions = folderPermissions | PathPermissions.Delete;
                    }
                }
                usersMainFolder.Permissions = folderPermissions;

                //var showFiles = new ArrayList();
                //if (loadFiles)
                //{
                //    var files = FolderManager.Instance.GetFiles((FolderInfo)userFolder);
                //    foreach (var fileInfo in files)
                //    {
                //        showFiles.Add(new FileItem(fileInfo.FileName, fileInfo.Extension, fileInfo.Size, "", FileManager.Instance.GetUrl(fileInfo), "", folderPermissions));
                //    }
                //}
                //var folderFiles = (FileItem[]) showFiles.ToArray(typeof (FileItem));

                //var newDirectory = new DirectoryItem(userFolder.DisplayName, "", endUserPath, "", folderPermissions, folderFiles, new DirectoryItem[0]);
            }
        }
Example #5
0
        public override string CopyDirectory(string path, string newPath)
        {
            try
            {
                string virtualPath            = FileSystemValidation.ToVirtualPath(path);
                string virtualNewPath         = FileSystemValidation.ToVirtualPath(newPath);
                string virtualDestinationPath = FileSystemValidation.GetDestinationFolder(virtualNewPath);

                string returnValue = DNNValidator.OnCopyFolder(virtualPath, virtualDestinationPath);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                //Are all items visible to user?
                //todo: copy visible files and folders only?
                FolderInfo folder = DNNValidator.GetUserFolder(virtualPath);
                if (!(CheckAllChildrenVisible(ref folder)))
                {
                    return(DNNValidator.LogDetailError(ErrorCodes.CannotCopyFolder_ChildrenVisible));
                }

                returnValue = TelerikContent.CopyDirectory(virtualPath, virtualNewPath);

                if (string.IsNullOrEmpty(returnValue))
                {
                    //Sync to add new folder & files
                    FileSystemUtils.SynchronizeFolder(PortalSettings.PortalId, HttpContext.Current.Request.MapPath(virtualNewPath), FileSystemValidation.ToDBPath(virtualNewPath), true, true, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, newPath));
            }
        }
Example #6
0
        private static string ToDBPath(string path, bool removeFileName)
        {
            string returnValue = path;

            returnValue = returnValue.Replace("\\", "/");
            returnValue = (string)(string)FileSystemValidation.RemoveFileName(returnValue);

            if (returnValue.StartsWith(HomeDirectory))
            {
                returnValue = returnValue.Substring(HomeDirectory.Length);
            }

            if (returnValue.StartsWith(EndUserHomeDirectory))
            {
                returnValue = returnValue.Substring(EndUserHomeDirectory.Length);
            }

            //folders in dnn db do not start with /
            if (returnValue.StartsWith("/"))
            {
                returnValue = returnValue.Remove(0, 1);
            }

            //Root directory is an empty string
            if (returnValue == "/" || returnValue == "\\")
            {
                returnValue = string.Empty;
            }

            //root folder (empty string) does not contain / - all other folders must contain a slash at the end
            if (!(string.IsNullOrEmpty(returnValue)) && !(returnValue.EndsWith("/")))
            {
                returnValue = returnValue + "/";
            }

            return(returnValue);
        }
Example #7
0
        public override string CreateDirectory(string path, string name)
        {
            try
            {
                var directoryName = name.Trim();
                var virtualPath   = FileSystemValidation.ToVirtualPath(path);

                var returnValue = DNNValidator.OnCreateFolder(virtualPath, directoryName);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                //Returns errors or empty string when successful (ie: DirectoryAlreadyExists, InvalidCharactersInPath)
                returnValue = TelerikContent.CreateDirectory(virtualPath, directoryName);

                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(GetTelerikMessage(returnValue));
                }

                if (string.IsNullOrEmpty(returnValue))
                {
                    var virtualNewPath = FileSystemValidation.CombineVirtualPath(virtualPath, directoryName);
                    var newFolderID    = DNNFolderCtrl.AddFolder(PortalSettings.PortalId, FileSystemValidation.ToDBPath(virtualNewPath));
                    FileSystemUtils.SetFolderPermissions(PortalSettings.PortalId, newFolderID, FileSystemValidation.ToDBPath(virtualNewPath));
                    //make sure that the folder is flagged secure if necessary
                    DNNValidator.OnFolderCreated(virtualNewPath, virtualPath);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, name));
            }
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                string renderUrl = Request.QueryString["rurl"];

                if (!(string.IsNullOrEmpty(renderUrl)))
                {
                    string         fileContents = string.Empty;
                    FileController fileCtrl     = new FileController();
                    FileInfo       fileInfo     = null;
                    int            portalID     = PortalController.Instance.GetCurrentPortalSettings().PortalId;

                    if (renderUrl.ToLower().Contains("linkclick.aspx") && renderUrl.ToLower().Contains("fileticket"))
                    {
                        //File Ticket
                        int fileID = GetFileIDFromURL(renderUrl);

                        if (fileID > -1)
                        {
                            fileInfo = fileCtrl.GetFileById(fileID, portalID);
                        }
                    }
                    else
                    {
                        if (renderUrl.Contains("?"))
                        {
                            renderUrl = renderUrl.Substring(0, renderUrl.IndexOf("?"));
                        }
                        //File URL
                        string dbPath   = (string)(string)FileSystemValidation.ToDBPath(renderUrl);
                        string fileName = System.IO.Path.GetFileName(renderUrl);

                        if (!string.IsNullOrEmpty(fileName))
                        {
                            FolderInfo dnnFolder = GetDNNFolder(dbPath);
                            if (dnnFolder != null)
                            {
                                fileInfo = fileCtrl.GetFile(fileName, portalID, dnnFolder.FolderID);
                            }
                        }
                    }

                    if (fileInfo != null)
                    {
                        if (CanViewFile(fileInfo.Folder))
                        {
                            using (var streamReader = new StreamReader(FileManager.Instance.GetFileContent(fileInfo)))
                            {
                                fileContents = streamReader.ReadToEnd();
                            }
                        }
                    }

                    if (!(string.IsNullOrEmpty(fileContents)))
                    {
                        Content.Text = Server.HtmlEncode(fileContents);
                    }
                }
            }
            catch (Exception ex)
            {
                Services.Exceptions.Exceptions.LogException(ex);
                Content.Text = string.Empty;
            }
        }
		protected void Save_OnClick(object sender, EventArgs e)
		{
			try
			{
				if (FolderList.Items.Count == 0)
				{
					return;
				}

				DotNetNuke.Entities.Portals.PortalSettings portalSettings = DotNetNuke.Entities.Portals.PortalSettings.Current;

				string fileContents = htmlText2.Text.Trim();
				string newFileName = FileName.Text;
				if (! (newFileName.EndsWith(".html")))
				{
					newFileName = newFileName + ".html";
				}

				string rootFolder = portalSettings.HomeDirectoryMapPath;
				string dbFolderPath = FolderList.SelectedValue;
				string virtualFolder = (string)(string)FileSystemValidation.ToVirtualPath(dbFolderPath);
				rootFolder = rootFolder + FolderList.SelectedValue;
				rootFolder = rootFolder.Replace("/", "\\");

				string errorMessage = string.Empty;
				FolderController folderCtrl = new FolderController();
				FolderInfo folder = folderCtrl.GetFolder(portalSettings.PortalId, dbFolderPath, false);

				if ((folder == null))
				{
					ShowSaveTemplateMessage(GetString("msgFolderDoesNotExist.Text"));
					return;
				}

				// Check file name is valid
				FileSystemValidation dnnValidator = new FileSystemValidation();
				errorMessage = dnnValidator.OnCreateFile(virtualFolder + newFileName, fileContents.Length);
				if (! (string.IsNullOrEmpty(errorMessage)))
				{
					ShowSaveTemplateMessage(errorMessage);
					return;
				}

				FileController fileCtrl = new FileController();
				DotNetNuke.Services.FileSystem.FileInfo existingFile = fileCtrl.GetFile(newFileName, portalSettings.PortalId, folder.FolderID);

				// error if file exists
				if (! Overwrite.Checked && existingFile != null)
				{
					ShowSaveTemplateMessage(GetString("msgFileExists.Text"));
					return;
				}

				FileInfo newFile = existingFile;
				if ((newFile == null))
				{
					newFile = new FileInfo();
				}

				newFile.FileName = newFileName;
				newFile.ContentType = "text/plain";
				newFile.Extension = "html";
				newFile.Size = fileContents.Length;
				newFile.FolderId = folder.FolderID;

				errorMessage = FileSystemUtils.CreateFileFromString(rootFolder, newFile.FileName, fileContents, newFile.ContentType, string.Empty, false);

				if (! (string.IsNullOrEmpty(errorMessage)))
				{
					ShowSaveTemplateMessage(errorMessage);
					return;
				}

				existingFile = fileCtrl.GetFile(newFileName, portalSettings.PortalId, folder.FolderID);
				if (newFile.FileId != existingFile.FileId)
				{
					newFile.FileId = existingFile.FileId;
				}

				if (newFile.FileId != Null.NullInteger)
				{
					fileCtrl.UpdateFile(newFile.FileId, newFile.FileName, newFile.Extension, newFile.Size, newFile.Width, newFile.Height, newFile.ContentType, folder.FolderPath, folder.FolderID);
				}
				else
				{
					fileCtrl.AddFile(portalSettings.PortalId, newFile.FileName, newFile.Extension, newFile.Size, newFile.Width, newFile.Height, newFile.ContentType, folder.FolderPath, folder.FolderID, true);
				}

				ShowSaveTemplateMessage(string.Empty);
			}
			catch (Exception ex)
			{
				DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
				throw ex;
			}
		}
Example #10
0
        protected void Save_OnClick(object sender, EventArgs e)
        {
            try
            {
                if (FolderList.Items.Count == 0)
                {
                    return;
                }

                DotNetNuke.Entities.Portals.PortalSettings portalSettings = DotNetNuke.Entities.Portals.PortalSettings.Current;

                string fileContents = htmlText2.Text.Trim();
                string newFileName  = FileName.Text;
                if (!(newFileName.EndsWith(".html")))
                {
                    newFileName = newFileName + ".html";
                }

                string rootFolder    = portalSettings.HomeDirectoryMapPath;
                string dbFolderPath  = FolderList.SelectedValue;
                string virtualFolder = (string)(string)FileSystemValidation.ToVirtualPath(dbFolderPath);
                rootFolder = rootFolder + FolderList.SelectedValue;
                rootFolder = rootFolder.Replace("/", "\\");

                string           errorMessage = string.Empty;
                FolderController folderCtrl   = new FolderController();
                FolderInfo       folder       = folderCtrl.GetFolder(portalSettings.PortalId, dbFolderPath, false);

                if ((folder == null))
                {
                    ShowSaveTemplateMessage(GetString("msgFolderDoesNotExist.Text"));
                    return;
                }

                // Check file name is valid
                FileSystemValidation dnnValidator = new FileSystemValidation();
                errorMessage = dnnValidator.OnCreateFile(virtualFolder + newFileName, fileContents.Length);
                if (!(string.IsNullOrEmpty(errorMessage)))
                {
                    ShowSaveTemplateMessage(errorMessage);
                    return;
                }

                FileController fileCtrl = new FileController();
                DotNetNuke.Services.FileSystem.FileInfo existingFile = fileCtrl.GetFile(newFileName, portalSettings.PortalId, folder.FolderID);

                // error if file exists
                if (!Overwrite.Checked && existingFile != null)
                {
                    ShowSaveTemplateMessage(GetString("msgFileExists.Text"));
                    return;
                }

                FileInfo newFile = existingFile;
                if ((newFile == null))
                {
                    newFile = new FileInfo();
                }

                newFile.FileName    = newFileName;
                newFile.ContentType = "text/plain";
                newFile.Extension   = "html";
                newFile.Size        = fileContents.Length;
                newFile.FolderId    = folder.FolderID;

                errorMessage = FileSystemUtils.CreateFileFromString(rootFolder, newFile.FileName, fileContents, newFile.ContentType, string.Empty, false);

                if (!(string.IsNullOrEmpty(errorMessage)))
                {
                    ShowSaveTemplateMessage(errorMessage);
                    return;
                }

                existingFile = fileCtrl.GetFile(newFileName, portalSettings.PortalId, folder.FolderID);
                if (newFile.FileId != existingFile.FileId)
                {
                    newFile.FileId = existingFile.FileId;
                }

                if (newFile.FileId != Null.NullInteger)
                {
                    fileCtrl.UpdateFile(newFile.FileId, newFile.FileName, newFile.Extension, newFile.Size, newFile.Width, newFile.Height, newFile.ContentType, folder.FolderPath, folder.FolderID);
                }
                else
                {
                    fileCtrl.AddFile(portalSettings.PortalId, newFile.FileName, newFile.Extension, newFile.Size, newFile.Width, newFile.Height, newFile.ContentType, folder.FolderPath, folder.FolderID, true);
                }

                ShowSaveTemplateMessage(string.Empty);
            }
            catch (Exception ex)
            {
                DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                throw ex;
            }
        }
Example #11
0
 public override string GetFileName(string url)
 {
     return(TelerikContent.GetFileName(FileSystemValidation.ToVirtualPath(url)));
 }
Example #12
0
        private DirectoryItem AddChildDirectoriesToList(DirectoryItem radDirectory)
        {
            var parentFolderPath = radDirectory.FullPath.EndsWith("/") ? radDirectory.FullPath : radDirectory.FullPath + "/";

            if (parentFolderPath.StartsWith(PortalSettings.HomeDirectory))
            {
                parentFolderPath = parentFolderPath.Remove(0, PortalSettings.HomeDirectory.Length);
            }

            var dnnParentFolder = FolderManager.Instance.GetFolder(PortalSettings.PortalId, parentFolderPath);

            if (!DNNValidator.CanViewFilesInFolder(dnnParentFolder.FolderPath))
            {
                return(null);
            }

            var dnnChildFolders = FolderManager.Instance.GetFolders(dnnParentFolder).Where(folder => (FileSystemValidation.HasPermission(folder, "BROWSE,READ")));
            var radDirectories  = new List <DirectoryItem>();

            foreach (var dnnChildFolder in dnnChildFolders)
            {
                if (!dnnChildFolder.FolderPath.ToLowerInvariant().StartsWith("cache/") &&
                    !dnnChildFolder.FolderPath.ToLowerInvariant().StartsWith("users/") &&
                    !dnnChildFolder.FolderPath.ToLowerInvariant().StartsWith("groups/"))
                {
                    var radSubDirectory =
                        TelerikContent.ResolveDirectory(FileSystemValidation.ToVirtualPath(dnnChildFolder.FolderPath));
                    radSubDirectory.Permissions = FileSystemValidation.TelerikPermissions(dnnChildFolder);
                    radDirectories.Add(radSubDirectory);
                }
            }

            radDirectory.Files = IncludeFilesForCurrentFolder(dnnParentFolder);

            if (parentFolderPath == "")
            {
                var userFolder = FolderManager.Instance.GetUserFolder(PortalSettings.UserInfo);
                if (userFolder.PortalID == PortalSettings.PortalId)
                {
                    var radUserFolder = TelerikContent.ResolveDirectory(FileSystemValidation.ToVirtualPath(userFolder.FolderPath));
                    radUserFolder.Name        = DNNValidator.GetString("MyFolder");
                    radUserFolder.Permissions = FileSystemValidation.TelerikPermissions(userFolder);
                    radDirectories.Add(radUserFolder);
                }
            }

            radDirectory.Directories = radDirectories.ToArray();
            return(radDirectory);
        }
Example #13
0
 private FolderInfo GetDNNFolder(string path)
 {
     return(DNNFolderCtrl.GetFolder(PortalSettings.PortalId, FileSystemValidation.ToDBPath(path), false));
 }
Example #14
0
        public override string MoveFile(string path, string newPath)
        {
            try
            {
                string virtualPathAndFile    = FileSystemValidation.ToVirtualPath(path);
                string virtualNewPathAndFile = FileSystemValidation.ToVirtualPath(newPath);

                string virtualPath    = FileSystemValidation.RemoveFileName(virtualPathAndFile);
                string virtualNewPath = FileSystemValidation.RemoveFileName(virtualNewPathAndFile);

                string returnValue;
                if (virtualPath == virtualNewPath)
                {
                    //rename file
                    returnValue = DNNValidator.OnRenameFile(virtualPathAndFile);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }
                else
                {
                    //move file
                    returnValue = DNNValidator.OnMoveFile(virtualPathAndFile, virtualNewPathAndFile);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }

                //Returns errors or empty string when successful (ie: NewFileAlreadyExists)
                //returnValue = TelerikContent.MoveFile(virtualPathAndFile, virtualNewPathAndFile);
                var folderPath = FileSystemValidation.ToDBPath(path);
                var folder     = FolderManager.Instance.GetFolder(PortalSettings.PortalId, folderPath);
                if (folder != null)
                {
                    var file = FileManager.Instance.GetFile(folder, GetFileName(virtualPathAndFile));

                    if (file != null)
                    {
                        var destFolderPath = FileSystemValidation.ToDBPath(newPath);
                        var destFolder     = FolderManager.Instance.GetFolder(PortalSettings.PortalId, destFolderPath);
                        var destFileName   = GetFileName(virtualNewPathAndFile);

                        if (destFolder != null)
                        {
                            if (file.FolderId != destFolder.FolderID &&
                                FileManager.Instance.GetFile(destFolder, file.FileName) != null)
                            {
                                returnValue = "FileExists";
                            }
                            else
                            {
                                FileManager.Instance.MoveFile(file, destFolder);
                                FileManager.Instance.RenameFile(file, destFileName);
                            }
                        }
                    }
                    else
                    {
                        returnValue = "FileNotFound";
                    }
                }
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(GetTelerikMessage(returnValue));
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, newPath));
            }
        }
Example #15
0
        public override string MoveDirectory(string path, string newPath)
        {
            try
            {
                var virtualPath            = FileSystemValidation.ToVirtualPath(path);
                var virtualNewPath         = FileSystemValidation.ToVirtualPath(newPath);
                var virtualDestinationPath = FileSystemValidation.GetDestinationFolder(virtualNewPath);

                string returnValue;
                var    isRename = FileSystemValidation.GetDestinationFolder(virtualPath) == virtualDestinationPath;
                if (isRename)
                {
                    //rename directory
                    returnValue = DNNValidator.OnRenameFolder(virtualPath);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }
                else
                {
                    //move directory
                    returnValue = DNNValidator.OnMoveFolder(virtualPath, virtualDestinationPath);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }

                //Are all items visible to user?
                FolderInfo folder = DNNValidator.GetUserFolder(virtualPath);
                if (!(CheckAllChildrenVisible(ref folder)))
                {
                    return(DNNValidator.LogDetailError(ErrorCodes.CannotMoveFolder_ChildrenVisible));
                }

                if (isRename)
                {
                    var dnnFolderToRename = FolderManager.Instance.GetFolder(PortalSettings.PortalId, FileSystemValidation.ToDBPath(virtualPath));
                    var newFolderName     = virtualNewPath.TrimEnd('/').Split('/').LastOrDefault();
                    FolderManager.Instance.RenameFolder(dnnFolderToRename, newFolderName);
                }
                else             // move
                {
                    var dnnFolderToMove      = FolderManager.Instance.GetFolder(PortalSettings.PortalId, FileSystemValidation.ToDBPath(virtualPath));
                    var dnnDestinationFolder = FolderManager.Instance.GetFolder(PortalSettings.PortalId, FileSystemValidation.ToDBPath(virtualDestinationPath));
                    FolderManager.Instance.MoveFolder(dnnFolderToMove, dnnDestinationFolder);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, newPath));
            }
        }
        public override string MoveDirectory(string path, string newPath)
        {
            try
            {
                string virtualPath            = (string)(string)FileSystemValidation.ToVirtualPath(path);
                string virtualNewPath         = (string)(string)FileSystemValidation.ToVirtualPath(newPath);
                string virtualDestinationPath = FileSystemValidation.GetDestinationFolder(virtualNewPath);

                string returnValue = string.Empty;
                if (FileSystemValidation.GetDestinationFolder(virtualPath) == virtualDestinationPath)
                {
                    //rename directory
                    returnValue = DNNValidator.OnRenameFolder(virtualPath);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }
                else
                {
                    //move directory
                    returnValue = DNNValidator.OnMoveFolder(virtualPath, virtualDestinationPath);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }

                //Are all items visible to user?
                FolderInfo folder = DNNValidator.GetUserFolder(virtualPath);
                if (!(CheckAllChildrenVisible(ref folder)))
                {
                    return(DNNValidator.LogDetailError(ErrorCodes.CannotMoveFolder_ChildrenVisible));
                }

                //Returns errors or empty string when successful (ie: Cannot create a file when that file already exists)
                returnValue = TelerikContent.MoveDirectory(virtualPath, virtualNewPath);

                if (string.IsNullOrEmpty(returnValue))
                {
                    //make sure folder name is being updated in database
                    DNNValidator.OnFolderRenamed(virtualPath, virtualNewPath);
                    //Sync to remove old folder & files
                    FileSystemUtils.SynchronizeFolder(PortalSettings.PortalId, HttpContext.Current.Request.MapPath(virtualPath), FileSystemValidation.ToDBPath(virtualPath), true, true, true);
                    //Sync to add new folder & files
                    FileSystemUtils.SynchronizeFolder(PortalSettings.PortalId, HttpContext.Current.Request.MapPath(virtualNewPath), FileSystemValidation.ToDBPath(virtualNewPath), true, true, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, newPath));
            }
        }
        private DirectoryItem[] AddChildDirectoriesToList(ref DirectoryItem[] radDirectories, bool recursive, bool loadFiles)
        {
            var newDirectories = new ArrayList();
            var invalidFolders = new List <DirectoryItem>();

            foreach (var radDirectory in radDirectories)
            {
                System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString() + " AddChildDirectoriesToList " + radDirectory.Name);

                var endUserPath = (string)FileSystemValidation.ToEndUserPath(radDirectory.FullPath);

                var folderPath = radDirectory.FullPath.EndsWith("/") ? radDirectory.FullPath : radDirectory.FullPath + "/";

                var dnnFolder = DNNValidator.GetUserFolder(folderPath);

                if (dnnFolder == null)
                {
                    invalidFolders.Add(radDirectory);
                    continue;
                }

                //Don't show protected folders
                if (!string.IsNullOrEmpty(dnnFolder.FolderPath) && dnnFolder.IsProtected)
                {
                    invalidFolders.Add(radDirectory);
                    continue;
                }

                //Don't show Cache folder
                if (dnnFolder.FolderPath.ToLowerInvariant() == "cache/")
                {
                    invalidFolders.Add(radDirectory);
                    continue;
                }

                var showFiles         = new ArrayList();
                var folderPermissions = PathPermissions.Read;

                if (DNNValidator.CanViewFilesInFolder(dnnFolder))
                {
                    if (DNNValidator.CanAddToFolder(dnnFolder))
                    {
                        folderPermissions = folderPermissions | PathPermissions.Upload;
                    }

                    if (DNNValidator.CanDeleteFolder(dnnFolder))
                    {
                        folderPermissions = folderPermissions | PathPermissions.Delete;
                    }

                    if (loadFiles)
                    {
                        var files = FolderManager.Instance.GetFiles(dnnFolder);
                        foreach (var fileInfo in files)
                        {
                            showFiles.Add(new FileItem(fileInfo.FileName, fileInfo.Extension, fileInfo.Size, "", GetFileUrl(fileInfo), "", folderPermissions));
                        }
                    }

                    var folderFiles = (FileItem[])showFiles.ToArray(typeof(FileItem));

                    //Root folder name
                    var dirName = radDirectory.Name;
                    if (dnnFolder.FolderPath == "" && dnnFolder.FolderName == "")
                    {
                        dirName = FileSystemValidation.EndUserHomeDirectory;
                    }

                    DirectoryItem newDirectory;
                    if (recursive)
                    {
                        var directory = TelerikContent.ResolveRootDirectoryAsTree(radDirectory.Path);
                        var tempVar2  = directory.Directories;
                        if (dnnFolder.FolderPath == "" && dnnFolder.FolderName == "") //Replace USERS folder by the particular User Folder
                        {
                            AddUserFolder(ref tempVar2, loadFiles);
                        }
                        AddChildDirectoriesToList(ref tempVar2, false, false);
                        newDirectory             = new DirectoryItem(dirName, "", endUserPath, "", folderPermissions, folderFiles, tempVar2);
                        radDirectory.Directories = tempVar2;
                    }
                    else
                    {
                        newDirectory = new DirectoryItem(dirName, "", endUserPath, "", folderPermissions, folderFiles, new DirectoryItem[0]);
                    }

                    newDirectories.Add(newDirectory);
                }
                else
                {
                    invalidFolders.Add(radDirectory);
                }
            }
            //remove invalid folders
            radDirectories = radDirectories.Where(d => !invalidFolders.Contains(d)).ToArray();

            return((DirectoryItem[])newDirectories.ToArray(typeof(DirectoryItem)));
        }