示例#1
0
        /// <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);
        }
示例#2
0
        /// <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));
        }
示例#3
0
        /// <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);
            }
        }
示例#4
0
 public string GetPath(string fileName, UploadFoldersEnum folderEnum)
 {
     return(HostingEnvironment.MapPath(GetRelativePath(fileName, folderEnum.ToString())));
 }
示例#5
0
 public string GetRelativeFolderPath(UploadFoldersEnum folderEnum)
 {
     return(string.Format(@"{0}/{1}", _basePath, folderEnum.ToString()));
 }
示例#6
0
        /// <summary>
        /// Deletes the specified file in the specified folder.
        /// </summary>
        /// <param name="fileName">The file name.</param>
        /// <param name="folderEnum">The folder Enum.</param>
        /// <returns></returns>
        public bool Delete(string fileName, UploadFoldersEnum folderEnum)
        {
            string path = GetPath(fileName, folderEnum);

            return(Delete(path));
        }