public string GetFullFileName() { var fileName = FileName; if (!String.IsNullOrWhiteSpace(FileExtension)) { if (!FileExtension.Contains(".")) { fileName += "."; } fileName += FileExtension; } return(fileName); }
private void CollectFiles(List <string> files, string targetDirectory) { string[] fileEntries = Directory.GetFiles(targetDirectory); foreach (string fileName in fileEntries) { string ext = Path.GetExtension(fileName); if (!string.IsNullOrEmpty(ext) && FileExtension.Contains(ext)) { files.Add(fileName); System.Windows.Application.Current.Dispatcher.Invoke(new Action(() => Status = fileName)); } } // Recurse into subdirectories of this directory string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory); foreach (string subdirectory in subdirectoryEntries) { CollectFiles(files, subdirectory); } }
//Asynchronuous posting with File Extension Blacklisting /// <summary> /// Process Multiple Posted Files with Specified File Extensions Asynchronously /// </summary> /// <param name="file"> Collection of files /// </param> /// <param name="extension"> /// file extensions to be rejected during upload eg .docx, .jpeg, .xlsx /// </param> public async Task <int> ProcessFilesAsync(IEnumerable <HttpPostedFileBase> file) { try { foreach (var files in file) { if (file != null && files.ContentLength > 0) { //get filename fileName = Path.GetFileName(files.FileName); //get file path string serverPath = Path.Combine(HostingEnvironment.MapPath(FilePath), fileName); //get file extensions var FileExt = Path.GetExtension(serverPath); //reject extensions if (FileExtension.Contains(FileExt)) { //blacklist.Add(FileName); //Add the blacklisted file continue; //skip the current iteration } files.SaveAs(serverPath); //Increment successful written file fileCount = fileCount + 1; } } // get number of fles written //filesWritten = file.Count(); } catch (Exception e) { e.ToString(); } //return number of files written successfully int result = await Task.FromResult <int>(fileCount); return(result); }