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)); } }
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)); } }
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)); } }
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 GetDirectoryItemWithDNNPermissions(string path) { var radDirectory = TelerikContent.ResolveDirectory(FileSystemValidation.ToVirtualPath(path)); if (radDirectory.FullPath == PortalSettings.HomeDirectory) { radDirectory.Name = DNNValidator.GetString("Root"); } Logger.DebugFormat("GetDirectoryItemWithDNNPermissions - path: {0}, radDirectory: {1}", path, radDirectory); //var directoryArray = new[] {radDirectory}; return(AddChildDirectoriesToList(radDirectory)); }
private DirectoryItem GetDirectoryItemWithDNNPermissions(string path, bool loadFiles) { var radDirectory = TelerikContent.ResolveDirectory(FileSystemValidation.ToVirtualPath(path)); var directoryArray = new[] { radDirectory }; var returnValues = AddChildDirectoriesToList(ref directoryArray, true, loadFiles); if (returnValues != null && returnValues.Length > 0) { return(returnValues[0]); } return(null); }
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); }
private bool CheckAllChildrenVisible(ref FolderInfo folder) { string virtualPath = FileSystemValidation.ToVirtualPath(folder.FolderPath); //check files are visible IDictionary <string, Services.FileSystem.FileInfo> files = GetDNNFiles(folder.FolderID); int visibleFileCount = 0; foreach (Services.FileSystem.FileInfo fileItem in files.Values) { string[] tempVar = SearchPatterns; if (CheckSearchPatterns(fileItem.FileName, ref tempVar)) { visibleFileCount = visibleFileCount + 1; } } if (visibleFileCount != Directory.GetFiles(HttpContext.Current.Request.MapPath(virtualPath)).Length) { return(false); } //check folders if (folder != null) { IDictionary <string, FolderInfo> childUserFolders = DNNValidator.GetChildUserFolders(virtualPath); if (childUserFolders.Count != Directory.GetDirectories(HttpContext.Current.Request.MapPath(virtualPath)).Length) { return(false); } //check children foreach (FolderInfo childFolder in childUserFolders.Values) { //do recursive check FolderInfo tempVar2 = childFolder; if (!(CheckAllChildrenVisible(ref tempVar2))) { return(false); } } } return(true); }
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)); } }
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)); } }
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)); } }
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)); } }
public override string GetFileName(string url) { return(TelerikContent.GetFileName(FileSystemValidation.ToVirtualPath(url))); }
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; } }
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)); } }