Пример #1
0
        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
                    {
                        //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) && fileInfo.Extension.ToLower() == "htmtemplate")
                        {
                            byte[] fileBytes = FileSystemUtils.GetFileContent(fileInfo);
                            fileContents = System.Text.Encoding.ASCII.GetString(fileBytes);
                        }
                    }

                    if (!(string.IsNullOrEmpty(fileContents)))
                    {
                        Content.Text = Server.HtmlEncode(fileContents);
                    }
                }
            }
            catch (Exception ex)
            {
                Services.Exceptions.Exceptions.LogException(ex);
                Content.Text = string.Empty;
            }
        }
Пример #2
0
        public virtual FolderInfo GetUserFolder(string path)
        {
            string dbPath = (string)(string)FileSystemValidation.ToDBPath(path);

            if (UserFolders.ContainsKey(dbPath))
            {
                return(UserFolders[dbPath]);
            }

            return(null);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        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;
            }
        }
Пример #6
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));
            }
        }
Пример #7
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));
            }
        }
Пример #8
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));
            }
        }
Пример #9
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));
            }
        }
Пример #11
0
 private FolderInfo GetDNNFolder(string path)
 {
     return(DNNFolderCtrl.GetFolder(PortalSettings.PortalId, FileSystemValidation.ToDBPath(path), false));
 }