Пример #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));
            }
        }
Пример #2
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));
            }
        }
Пример #3
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));
            }
        }
Пример #4
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);
        }
Пример #5
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));
            }
        }