Esempio n. 1
0
        public override string DeleteDirectory(string path)
        {
            try
            {
                string virtualPath = FileSystemValidation.ToVirtualPath(path);

                string returnValue = DNNValidator.OnDeleteFolder(virtualPath);
                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.CannotDeleteFolder_ChildrenVisible));
                }


                if (string.IsNullOrEmpty(returnValue))
                {
                    FolderManager.Instance.DeleteFolder(folder);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path));
            }
        }
Esempio n. 2
0
        public override string CopyFile(string path, string newPath)
        {
            try
            {
                string virtualPathAndFile    = FileSystemValidation.ToVirtualPath(path);
                string virtualNewPathAndFile = FileSystemValidation.ToVirtualPath(newPath);

                string returnValue = DNNValidator.OnCopyFile(virtualPathAndFile, virtualNewPathAndFile);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                //Returns errors or empty string when successful (ie: NewFileAlreadyExists)
                returnValue = TelerikContent.CopyFile(virtualPathAndFile, virtualNewPathAndFile);

                if (string.IsNullOrEmpty(returnValue))
                {
                    string     virtualNewPath = FileSystemValidation.RemoveFileName(virtualNewPathAndFile);
                    FolderInfo dnnFolder      = DNNValidator.GetUserFolder(virtualNewPath);
                    var        dnnFileInfo    = new Services.FileSystem.FileInfo();
                    FillFileInfo(virtualNewPathAndFile, ref dnnFileInfo);

                    DNNFileCtrl.AddFile(PortalSettings.PortalId, dnnFileInfo.FileName, dnnFileInfo.Extension, dnnFileInfo.Size, dnnFileInfo.Width, dnnFileInfo.Height, dnnFileInfo.ContentType, dnnFolder.FolderPath, dnnFolder.FolderID, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, newPath));
            }
        }
Esempio n. 3
0
        public override string DeleteFile(string path)
        {
            try
            {
                string virtualPathAndFile = FileSystemValidation.ToVirtualPath(path);

                string returnValue = DNNValidator.OnDeleteFile(virtualPathAndFile);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                returnValue = TelerikContent.DeleteFile(virtualPathAndFile);

                if (string.IsNullOrEmpty(returnValue))
                {
                    string     virtualPath = FileSystemValidation.RemoveFileName(virtualPathAndFile);
                    FolderInfo dnnFolder   = DNNValidator.GetUserFolder(virtualPath);
                    DNNFileCtrl.DeleteFile(PortalSettings.PortalId, Path.GetFileName(virtualPathAndFile), dnnFolder.FolderID, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path));
            }
        }
        public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
        {
            try
            {
                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 DotNetNuke.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));
            }
        }
Esempio n. 5
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));
            }
        }
Esempio n. 7
0
 public override DirectoryItem[] ResolveRootDirectoryAsList(string path)
 {
     try
     {
         Logger.DebugFormat("ResolveRootDirectoryAsList: {0}", path);
         return(GetDirectoryItemWithDNNPermissions(path).Directories);
     }
     catch (Exception ex)
     {
         DNNValidator.LogUnknownError(ex, path);
         return(null);
     }
 }
 public override DirectoryItem[] ResolveRootDirectoryAsList(string path)
 {
     try
     {
         System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString() + "ResolveRootDirectoryAsList: " + path);
         return(GetDirectoryItemWithDNNPermissions(path, false).Directories);
     }
     catch (Exception ex)
     {
         DNNValidator.LogUnknownError(ex, path);
         return(null);
     }
 }
Esempio n. 9
0
        public override string StoreBitmap(System.Drawing.Bitmap bitmap, string url, System.Drawing.Imaging.ImageFormat format)
        {
            try
            {
                //base calls CheckWritePermissions method
                string virtualPathAndFile = FileSystemValidation.ToVirtualPath(url);
                string virtualPath        = FileSystemValidation.RemoveFileName(virtualPathAndFile);
                string returnValue        = DNNValidator.OnCreateFile(virtualPathAndFile, 0);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                returnValue = TelerikContent.StoreBitmap(bitmap, virtualPathAndFile, format);

                var dnnFileInfo = new Services.FileSystem.FileInfo();
                FillFileInfo(virtualPathAndFile, ref dnnFileInfo);

                //check again with real contentLength
                string errMsg = DNNValidator.OnCreateFile(virtualPathAndFile, dnnFileInfo.Size);
                if (!(string.IsNullOrEmpty(errMsg)))
                {
                    TelerikContent.DeleteFile(virtualPathAndFile);
                    return(errMsg);
                }

                FolderInfo dnnFolder = DNNValidator.GetUserFolder(virtualPath);
                Services.FileSystem.FileInfo dnnFile = DNNFileCtrl.GetFile(dnnFileInfo.FileName, PortalSettings.PortalId, dnnFolder.FolderID);

                if (dnnFile != null)
                {
                    DNNFileCtrl.UpdateFile(dnnFile.FileId, dnnFileInfo.FileName, dnnFileInfo.Extension, dnnFileInfo.Size, bitmap.Width, bitmap.Height, dnnFileInfo.ContentType, dnnFolder.FolderPath, dnnFolder.FolderID);
                }
                else
                {
                    DNNFileCtrl.AddFile(PortalSettings.PortalId, dnnFileInfo.FileName, dnnFileInfo.Extension, dnnFileInfo.Size, bitmap.Width, bitmap.Height, dnnFileInfo.ContentType, dnnFolder.FolderPath, dnnFolder.FolderID, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, url));
            }
        }
Esempio n. 10
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));
            }
        }
Esempio n. 11
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));
            }
        }
Esempio n. 12
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));
            }
        }
Esempio n. 13
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));
            }
        }