Example #1
0
        public string GetFileSource(string webRootPath, string filePath, FileHandlerFolder fileHandlerFolder)
        {
            var    folderPath = GetUploadFolderPath(fileHandlerFolder);
            string uploadPath = webRootPath + "\\" + ConstantPath.Uploads + "\\"
                                + folderPath + "\\" + filePath;

            try
            {
                var files = Directory.GetFiles(
                    uploadPath,
                    "*.*",
                    SearchOption.TopDirectoryOnly);

                if (files.Length > 0 && files[0] != null)
                {
                    var path = "\\" + ConstantPath.Uploads + "\\" +
                               folderPath + "\\" + filePath + "\\" + Path.GetFileName(files[0]);

                    return(path.Replace(@"\", "/"));
                }
            }
            catch { }

            return(null);
        }
Example #2
0
        public List <string> GetFilesSourceList(string webRootPath, string filePath, FileHandlerFolder fileHandlerFolder)
        {
            var    folderPath = GetUploadFolderPath(fileHandlerFolder);
            string uploadPath = webRootPath + "\\" + ConstantPath.Uploads + "\\"
                                + folderPath + "\\" + filePath;

            List <string> fileSources = new List <string>();

            try
            {
                var files = Directory.GetFiles(
                    uploadPath,
                    "*.*",
                    SearchOption.TopDirectoryOnly);

                foreach (var file in files)
                {
                    string src = "\\" + ConstantPath.Uploads + "\\"
                                 + folderPath + "\\" + filePath + "\\" + Path.GetFileName(file);

                    fileSources.Add(src.Replace(@"\", "/"));
                }
            }
            catch { }

            return(fileSources);
        }
Example #3
0
        private string GetUploadFolderPath(FileHandlerFolder fileHandlerFolder)
        {
            if (fileHandlerFolder == FileHandlerFolder.Posts)
            {
                return(ConstantPath.Posts);
            }

            return(ConstantPath.Profiles);
        }
Example #4
0
        public async Task UploadMedia(
            IFormFileCollection files,
            string webRootPath,
            string filePath,
            FileHandlerFolder fileHandlerFolder)
        {
            string uploadPath = webRootPath + "\\" + ConstantPath.Uploads + "\\"
                                + GetUploadFolderPath(fileHandlerFolder) + "\\" + filePath;

            foreach (var file in files)
            {
                await Upload(file, uploadPath);
            }
        }
Example #5
0
        public void DeleteMedia(string webRootPath, string filePath, FileHandlerFolder fileHandlerFolder)
        {
            string uploadPath = webRootPath + "\\" + ConstantPath.Uploads + "\\"
                                + GetUploadFolderPath(fileHandlerFolder) + "\\" + filePath;

            try
            {
                if (Directory.Exists(uploadPath))
                {
                    Directory.Delete(uploadPath, true);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }