/// <summary> /// Ensures the directory exists. /// </summary> /// <param name="logicalPath">The logical path.</param> /// <param name="subFolders">array of subfolders completing the path.</param> public IResultModel EnsureDirectoryExists(UploadFoldersEnum logicalPathEnum, params string[] subFolders) { IResultModel rm = new ResultModel(); string tmpDir = string.Empty; int x = 0; try { tmpDir = GetPhysicalPath(logicalPathEnum.ToString()); if (!Directory.Exists(tmpDir)) { Directory.CreateDirectory(tmpDir); } for (x = 0; x < subFolders.Length; x++) { tmpDir = GetPhysicalPath(Path.Combine(tmpDir, subFolders[x])); if (!Directory.Exists(tmpDir)) { Directory.CreateDirectory(tmpDir); } } rm.OnSuccess(); } catch (Exception ex) { rm.OnException(ex); } return(rm); }
/// <summary> /// Moves the file. /// </summary> /// <param name="sourceFilePath">The source file path.</param> /// <param name="targetFolder">The target folder.</param> /// <returns></returns> public string MoveFile(string sourceFilePath, UploadFoldersEnum targetFolderEnum) { var relativePath = sourceFilePath; string targetFolder = targetFolderEnum.ToString(); if (!relativePath.Contains("~")) { relativePath = "~" + relativePath; } var localFilePath = GetPhysicalPath(relativePath); if (!targetFolder.EndsWith("/")) { targetFolder += "/"; } var logicalTargetFile = normalizePath(targetFolder + Path.GetFileName(sourceFilePath)); var destinationFilePath = GetPhysicalPath(logicalTargetFile); if (localFilePath.Contains("admin.png")) { File.Copy(localFilePath, destinationFilePath, true); } else { File.Move(localFilePath, destinationFilePath); } return(getFullUrlFor(logicalTargetFile)); }
/// <summary> /// Ensures the directory exists. /// </summary> /// <param name="logicalPath">The logical path.</param> public void EnsureDirectoryExists(UploadFoldersEnum logicalPathEnum) { string tmpDir = GetPhysicalPath(logicalPathEnum.ToString()); if (!Directory.Exists(tmpDir)) { Directory.CreateDirectory(tmpDir); } }
public string GetPath(string fileName, UploadFoldersEnum folderEnum) { return(HostingEnvironment.MapPath(GetRelativePath(fileName, folderEnum.ToString()))); }
public string GetRelativeFolderPath(UploadFoldersEnum folderEnum) { return(string.Format(@"{0}/{1}", _basePath, folderEnum.ToString())); }