Exemplo n.º 1
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));
            }
        }
Exemplo n.º 2
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));
            }
        }
Exemplo 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));
            }
        }
Exemplo 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));
            }
        }
Exemplo n.º 7
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));
            }
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
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));
            }
        }
Exemplo n.º 10
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));
            }
        }
        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)));
        }