private void AddFiles() { if (_dialogs.AddFilesDialog(out IList <string> fileNames)) { UploadFiles.AddNewRange(fileNames); } }
public void OnFileDrop(string[] filepaths) { if (!UploadIsRunning) { UploadFiles.AddNewRange(filepaths); } }
public async Task CreateCVAsync([FromForm] RecruitmentRequest input) { bool checkExist = await WorkScope.GetAll <CV>().AnyAsync(x => x.PostId == input.PostId && x.UserId == input.UserId && input.UserId.HasValue); if (checkExist) { throw new UserFriendlyException("Bạn đã ứng tuyển vị trí này"); } var post = await WorkScope.GetAsync <Post>(input.PostId); var cv = ObjectMapper.Map <CV>(input); if (input.FileCV?.Length > 0) { string fileLocation = UploadFiles.CreateFolderIfNotExists(ConstantVariable.RootFolder, $@"{ConstantVariable.UploadFolder}\{ConstantVariable.CV}\{post.PostUrl}"); string fileName = await UploadFiles.UploadAsync(fileLocation, input.FileCV); cv.Link = $"{ConstantVariable.UploadFolder}/{ConstantVariable.CV}/{post.PostUrl}/{fileName}"; } await WorkScope.InsertAsync(cv); }
private void CopyFile(FileListItem control) { string temp = AppDomain.CurrentDomain.BaseDirectory + "\\Temp\\" + control.FileName; //临时文件路径 //若临时文件夹中已存在同名文件,则文件名加当前时间点保存为备用文件名 if (File.Exists(temp)) { int i = control.FileName.LastIndexOf("."); string backUpName = control.FileName.Substring(0, i) + DateTime.Now.ToString("yyyyMMddHHmmss") + control.FileName.Substring(i); temp = AppDomain.CurrentDomain.BaseDirectory + "\\Temp\\" + backUpName; control.BackUpName = backUpName; using (DBContext db = new DBContext()) { UploadFiles upload = db.UploadFiles.Where(q => q.ID.Equals(control.ID)).FirstOrDefault(); if (upload == null) { SetFileItemMsg(control, "未找到对应上传记录"); } upload.BackUpName = backUpName; db.Entry(upload).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } File.Copy(control.FileSource, temp); }
public UploadFilesResponse Post(UploadFiles filesInfo) { return(new UploadFilesResponse { Result = _fileExchange.UploadFilesList(filesInfo.files, filesInfo.repository) }); }
public async Task UpdateNationality([FromForm] NationalityRequest input) { bool checkName = await WorkScope.GetAll <Nationality>().AnyAsync(x => x.Name == input.Name && x.Id != input.Id); if (checkName) { throw new UserFriendlyException("Quốc tịch đã tồn tại"); } var nationality = await WorkScope.GetAll <Nationality>().FirstOrDefaultAsync(x => x.Id == input.Id); if (nationality == default) { throw new UserFriendlyException("Quốc tịch không tồn tại"); } nationality.Name = input.Name; if (input.Image?.Length > 0) { string fileLocation = UploadFiles.CreateFolderIfNotExists(ConstantVariable.RootFolder, $@"{ConstantVariable.UploadFolder}\{ConstantVariable.Company}"); string fileName = await UploadFiles.UploadAsync(fileLocation, input.Image); nationality.Path = $"{ConstantVariable.UploadFolder}/{ConstantVariable.Company}/{fileName}"; } await WorkScope.UpdateAsync(nationality); }
public async Task CreateNationalityAsync([FromForm] NationalityRequest input) { bool checkName = await WorkScope.GetAll <Nationality>().AnyAsync(x => x.Name == input.Name); if (checkName) { throw new UserFriendlyException("Quốc tịch đã tồn tại"); } string fileName = string.Empty; string fileLocation = UploadFiles.CreateFolderIfNotExists(ConstantVariable.RootFolder, $@"{ConstantVariable.UploadFolder}\{ConstantVariable.Nationality}"); if (input.Image?.Length > 0) { fileName = await UploadFiles.UploadAsync(fileLocation, input.Image); } var nationality = new Nationality { Name = input.Name, Path = $"{ConstantVariable.UploadFolder}/{ConstantVariable.Nationality}/{fileName}" }; await WorkScope.InsertAsync(nationality); }
/// <summary> /// /// </summary> /// <param name="args"></param> /// <returns></returns> protected override async Task OnFileChange(InputFileChangeEventArgs args) { CurrentFile = new UploadFile() { OriginFileName = args.File.Name, Size = args.File.Size, File = args.File, Uploaded = false }; CurrentFile.ValidateId = $"{Id}_{CurrentFile.GetHashCode()}"; if (IsSingle) { // 单图片模式 DefaultFileList?.Clear(); UploadFiles.Clear(); } UploadFiles.Add(CurrentFile); await base.OnFileChange(args); // ValidateFile 后 IsValid 才有值 CurrentFile.IsValid = IsValid; if (OnChange != null) { await OnChange(CurrentFile); } else { await CurrentFile.RequestBase64ImageFileAsync(CurrentFile.File.ContentType, 320, 240); } }
public JsonResult AddExcelChequeUpload(UploadFiles upload) { using (var db = new TheCoreBanking_FilesContext()) //using (var stream = new MemoryStream()) { for (int imgCounter = 0; imgCounter < upload.ImageFile.Count; imgCounter++) { TblLodgementWithdrawal imagedocument = new TblLodgementWithdrawal { AccountId = upload.AccountId, Description = upload.FileTitle, Mime = upload.ImageFile[imgCounter].ContentType, IsDeleted = false }; using (var stream = new MemoryStream()) { upload.ImageFile[imgCounter].CopyTo(stream); imagedocument.FileData = stream.ToArray(); } db.TblLodgementWithdrawal.Add(imagedocument); } db.SaveChanges(); } return(Json(true)); }
private async Task OnFileChange(InputFileChangeEventArgs args) { var files = new List <UploadFile>(); if (IsMultiple || Style == UploadStyle.UploadFolder) { files.AddRange(args.GetMultipleFiles(MaxFileCount).Select(f => new UploadFile() { OriginFileName = f.Name, Size = f.Size, File = f, UpdateCallback = Update })); } else { var file = new UploadFile() { OriginFileName = args.File.Name, Size = args.File.Size, File = args.File, UpdateCallback = Update }; files.Add(file); } UploadFiles.AddRange(files); if (OnChange != null) { await OnChange(files); } }
private void SaveFileInfo(FileListItem item) { try { using (DBContext db = new DBContext()) { UploadFiles upload = new UploadFiles() { ID = item.ID, FileName = item.FileName, BackUpName = item.BackUpName, FileSource = item.FileSource, FileSize = item.FileSize }; db.UploadFiles.Add(upload); db.SaveChanges(); } } catch (Exception ex) { LogHelper.WriteLog("保存文件信息时出错", ex.Message, ex.StackTrace); } }
private void SetFileServerID(string id, string serverFileID) { try { using (DBContext db = new DBContext()) { UploadFiles upload = db.UploadFiles.Where(q => q.ID.Equals(id)).FirstOrDefault(); if (upload == null) { LogHelper.WriteLog("更新文件服务端ID时未查找到对应文件信息", null, null); return; } upload.ServerFileID = serverFileID; db.Entry(upload).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } catch (Exception ex) { LogHelper.WriteLog("更新文件服务端ID时出错", ex.Message, ex.StackTrace); } }
public IActionResult Put(Guid id, [FromForm] Produto _produto) { try { Produto _produtoBuscado = _repository.BuscarProdutoId(id); if (_produtoBuscado == null) { return(NotFound()); } if (_produto.Imagem != null) { var _urlImg = UploadFiles.Local(_produto.Imagem); _produto.UrlImagem = _urlImg; } //_produto.Id = id; _repository.AlterarProduto(_produto); return(Ok(_produto)); } catch (Exception _e) { return(BadRequest(_e.Message)); } }
public async Task <IActionResult> PostMovimentacao(IFormFile file) { try { if (file != null) { var filePath = UploadFiles.Upload(file); Importacao importacao = new Importacao(); importacao.Id = Guid.NewGuid(); importacao.DataImportacao = DateTime.Now; importacao.NomeArquivo = filePath; importacao.Movimentacoes = Extrato.MontaExtrato(await _movimentacaoRepository.GetSaldo(), importacao); _importacaoRepository.Add(importacao); if (await _importacaoRepository.SaveChangesAsync()) { return(Ok(await _movimentacaoRepository.Get())); } } return(BadRequest()); } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Falha no upload do arquivo.")); } }
/// <summary> /// 获得当前图片集合 /// </summary> /// <returns></returns> protected virtual List <UploadFile> GetUploadFiles() { var ret = new List <UploadFile>(); if (IsSingle) { if (DefaultFileList?.Any() ?? false) { ret.Add(DefaultFileList.First()); } if (ret.Count == 0 && UploadFiles.Any()) { ret.Add(UploadFiles.First()); } } else { if (DefaultFileList != null) { ret.AddRange(DefaultFileList); } ret.AddRange(UploadFiles); } return(ret); }
public static void Compress(FileInfo fileToCompress) { using (FileStream originalFileStream = fileToCompress.OpenRead()) { if ((File.GetAttributes(fileToCompress.FullName) & FileAttributes.Hidden) != FileAttributes.Hidden & fileToCompress.Extension != ".gz") { if (File.Exists(fileToCompress.FullName + ".gz")) { File.Delete(fileToCompress.FullName + ".gz"); Console.WriteLine("File '{0}' was deleted", fileToCompress.FullName + ".gz"); Thread.Sleep(10000); } using (FileStream compressedFileStream = File.Create(fileToCompress.FullName + ".gz")) { using (GZipStream compressionStream = new GZipStream(compressedFileStream, CompressionMode.Compress)) { originalFileStream.CopyTo(compressionStream); Console.WriteLine("Compressed {0} from {1} to {2} bytes.", fileToCompress.Name, fileToCompress.Length.ToString(), compressedFileStream.Length.ToString()); } } } } // Open the stream and read it back. string fileText = File.ReadAllText(fileToCompress.FullName + ".gz"); Console.WriteLine("Readed {0} chars", fileText.Length.ToString()); Thread.Sleep(10000); string hash = UploadFiles.GetMd5Hash(fileText); Console.WriteLine("Hash = {0}", hash); Thread.Sleep(10000); File.WriteAllText(fileToCompress.FullName + ".gz.md5", hash); }
public virtual async Task <UploadedFiles> Upload(UploadFiles uploadFiles) { var uploadFolder = Path.Combine(this.UploadFolder, Temp); if (!Directory.Exists(uploadFolder)) { Directory.CreateDirectory(uploadFolder); } var uploadedItems = new List <UploadedItem>(); foreach (var uploadItem in uploadFiles.Items) { var fileName = $"{Guid.NewGuid()}{Path.GetExtension(uploadItem.OriginalFileName)}"; using (var fs = new FileStream( Path.Combine(uploadFolder, fileName), FileMode.CreateNew)) { await fs.WriteAsync(uploadItem.File, 0, uploadItem.File.Length); uploadedItems.Add(new UploadedItem( fileName, uploadItem.OriginalFileName, uploadItem.MimeType)); } } return(new UploadedFiles(uploadedItems)); }
public async void OnFileDrop(string[] filepaths, bool controlKeyPressed) { // TODO: OnFileDrop fix dropping folders being allowed if (!UploadIsRunning && !AddingFiles) { AddingFiles = true; if (filepaths.Length == 1 && !controlKeyPressed) { var youtubePlaylistId = _youtube.ExtractPlaylistId(filepaths[0]); if (youtubePlaylistId != null) { await AddYoutubePlaylistVideos(youtubePlaylistId); } else { UploadFiles.AddNewRange(filepaths); } } else { await UploadFiles.AddNewRangeAsync(filepaths); } AddingFiles = false; } }
private async Task UploadVideo(UploadFile file, CancellationToken cancelToken) { file.SetUploading(); while (true) { IngestionControllerResponse response; try { response = await _fileUploader.UpLoadVideoAsync(file.FullPath, cancelToken); } finally { await _helpers.Wait(_appSettings.UploadDelay, cancelToken); } if (response.Success) { UploadFiles.Remove(file); break; //while true } else { if (_editTokenRefreshed || response.HttpStatusCode != HttpStatusCode.BadRequest) { file.SetError(response.Status); break; // while true } else { await RefreshEditToken(); } } } }
private async void LoadList() { if (AddingFiles) { return; } if (_dialogs.LoadUploadListDialog(out var fileName)) { AddingFiles = true; try { var newFiles = _uploadFileSerializer.Deserialize(fileName); await UploadFiles.AddRangeAsync(newFiles); } catch (Exception ex) { _dialogs.ErrorMessage(Resources.CantReadUploadListMessage, ex); } finally { AddingFiles = false; } } }
private async void AddFolder() { if (AddingFiles) { return; } if (_dialogs.AddFolderDialog(out var folderPath)) { if (_dialogs.AddFolderOptionsDialog(folderPath, out var includeSunfolder, out var includeFiles, out var extension)) { try { AddingFiles = true; var fileNames = _fileFinder.GetFiles(folderPath, includeSunfolder, includeFiles, extension); await UploadFiles.AddNewRangeAsync(fileNames); } catch (Exception ex) { _dialogs.ErrorMessage(Resources.UnableToAddFiles, ex); } finally { AddingFiles = false; } } } }
private void Update_Function() { UploadFiles title = new UploadFiles(); while (true) { lock (_locker) //锁,用来保护数据读写不会冲突 { if (_tasks.Count > 0) //队列中剩余的数据 { title = _tasks.Dequeue(); //去取得数据 } } if (title.filename != null) //任务不为空 { bool recv = httppost.uploadfile(title.filepath, title.filename); if (recv == false) { EnqueuelTask(title); } else { title.filename = null; } } else { //_wh.WaitOne(); Thread.Sleep(1000); } } }
public static bool EnqueuelTask(UploadFiles data) { lock (_locker) { _tasks.Enqueue(data); } return(true); }
/// <summary> /// 上传图片() /// </summary> public void UploadPhoto() { UploadFiles upload = new UploadFiles("UploadFile"); upload.TWidth = 50; upload.UpLoadIMG(Request.Files[0]); ResponseWrite(upload.FileName); }
private void ResetViewModel() { UploadSummary = ""; PageContent = ""; UploadFiles.Clear(); _templateSearch = _wikiSearchFactory.CreateTemplateSearch(_fileUploader); _categorySearch = _wikiSearchFactory.CreateCategorySearch(_fileUploader); }
public ActionResult Create(MatchResult entity)//文档上传 { string msg = string.Empty; if (Request.Files.Count == 2)//前端获取文件选择控件值 { for (int i = 0; i < Request.Files.Count; i++) { System.Web.HttpPostedFileBase postedFile = Request.Files[i]; //获取页面选择的文件 UploadFiles upFiles = new UploadFiles(); msg = upFiles.fileSaveAsResult(postedFile); //上传文件 if (i == 0) { entity.BasePath = postedFile.FileName; entity.BaseFullPath = msg; } else { entity.GoldTempPath = postedFile.FileName; entity.GoldTempFullPath = msg; } } } else { return(View()); } string currentPerson = GetCurrentPerson(); entity.CreateTime = System.DateTime.Now; entity.CreatePerson = currentPerson; entity.Id = Result.GetNewId(); //excel操作 entity.Vertion = GetVersion(); entity.Result = GoldMatch.Make(entity); string returnValue = string.Empty; if (m_BLL.Create(ref validationErrors, entity)) { return(Redirect("/home/index"));//提示创建成功 } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return(true); }); } LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",对比结果的信息," + returnValue, "对比结果" ); //写入日志 return(View()); //提示插入失败 } }
private void RemoveFiles(object selectedItems) { // must guard against running upload because a delete keypress can fire this // as well as a button press. if (!UploadIsRunning) { UploadFiles.RemoveRange(((IList)selectedItems).OfType <UploadFile>().ToList()); } }
public Guid Insert(UploadFiles item, Guid UpdatedId) { Check.IsNotNull(item.token, $"Token relacion requerido {item.token}."); Check.IsNotNull(item.type, $"Tipo de archivo requerido {item.type}."); Check.IsNotNull(item.name, $"Nombre archivo requerido {item.name}."); item.State = ObjectState.Added; item.UpdatedId = UpdatedId; return(db.Save(item)); }
public string HDpic()//头像上传 { //byte[] FileByte = Request.BinaryRead(Request.TotalBytes); string upfile = Request.Form["name"]; //取得上传的对象名称 HttpPostedFileBase pstFile = Request.Files["file"]; UploadFiles upFiles = new UploadFiles(); string msg = upFiles.fileSaveAs(pstFile, upfile); return msg; }
public ProdutosController(IProdutoRepository produtoRepository, IFornecedorRepository fornecedorRepository, ICategoriaRepository categoriaRepository, IProdutoService produtoService, IMapper mapper, UploadFiles uploadFiles, INotificador notificador) : base(notificador) { _produtoRepository = produtoRepository; _fornecedorRepository = fornecedorRepository; _categoriaRepository = categoriaRepository; _produtoService = produtoService; _mapper = mapper; _uploadFiles = uploadFiles; }
/// <summary> /// OnInitialized 方法 /// </summary> protected override void OnInitialized() { base.OnInitialized(); // 如果默认预览文件集合有值时增加到文件集合中 if (DefaultFileList != null) { UploadFiles.AddRange(DefaultFileList); } }
protected void UploadImages_Click(object sender, EventArgs e) { List<UploadFiles> listOffiles = new List<UploadFiles>(); UploadFiles uploadFiles; string propertyID=""; if (Session["propPicturesID"] != null) { propertyID = (string)Session["propPicturesID"]; } if (FileUpload1.HasFile) { uploadFiles = new UploadFiles(); uploadFiles.ContentLength = Convert.ToString(FileUpload1.PostedFile.ContentLength); uploadFiles.ContentType = FileUpload1.PostedFile.ContentType; uploadFiles.FileName = FileUpload1.PostedFile.FileName; uploadFiles.Stream = FileUpload1.PostedFile.InputStream; listOffiles.Add(uploadFiles); } if (FileUpload2.HasFile) { uploadFiles = new UploadFiles(); uploadFiles.ContentLength = Convert.ToString(FileUpload2.PostedFile.ContentLength); uploadFiles.ContentType = FileUpload2.PostedFile.ContentType; uploadFiles.FileName = FileUpload2.PostedFile.FileName; uploadFiles.Stream = FileUpload2.PostedFile.InputStream; listOffiles.Add(uploadFiles); } if (FileUpload3.HasFile) { uploadFiles = new UploadFiles(); uploadFiles.ContentLength = Convert.ToString(FileUpload3.PostedFile.ContentLength); uploadFiles.ContentType = FileUpload3.PostedFile.ContentType; uploadFiles.FileName = FileUpload3.PostedFile.FileName; uploadFiles.Stream = FileUpload3.PostedFile.InputStream; listOffiles.Add(uploadFiles); } if (FileUpload4.HasFile) { uploadFiles = new UploadFiles(); uploadFiles.ContentLength = Convert.ToString(FileUpload4.PostedFile.ContentLength); uploadFiles.ContentType = FileUpload4.PostedFile.ContentType; uploadFiles.FileName = FileUpload4.PostedFile.FileName; uploadFiles.Stream = FileUpload4.PostedFile.InputStream; listOffiles.Add(uploadFiles); } if (FileUpload5.HasFile) { uploadFiles = new UploadFiles(); uploadFiles.ContentLength = Convert.ToString(FileUpload5.PostedFile.ContentLength); uploadFiles.ContentType = FileUpload5.PostedFile.ContentType; uploadFiles.FileName = FileUpload5.PostedFile.FileName; uploadFiles.Stream = FileUpload5.PostedFile.InputStream; listOffiles.Add(uploadFiles); } if (FileUpload6.HasFile) { uploadFiles = new UploadFiles(); uploadFiles.ContentLength = Convert.ToString(FileUpload6.PostedFile.ContentLength); uploadFiles.ContentType = FileUpload6.PostedFile.ContentType; uploadFiles.FileName = FileUpload6.PostedFile.FileName; uploadFiles.Stream = FileUpload6.PostedFile.InputStream; listOffiles.Add(uploadFiles); } Search.AddImage(FederationForms, listOffiles, Guid.Parse(propertyID)); lblImages.Visible = true; // Keys key = Search.GetID(FederationForms); ltvThumbnail.DataSource = Search.GetThumbnails(FederationForms, Guid.Parse(propertyID)); ltvThumbnail.DataBind(); }
public int InsertRecord(string FirstName, string Lastname, int applyAsrole, string password, string emailId, List<UploadFile> L) { int result = 0; using (ROPAEntities context = new ROPAEntities()) { UpcmomingSurveyor obj = new UpcmomingSurveyor(); obj.FirstName = FirstName; obj.LastName = Lastname; obj.ApplyAsRole = applyAsrole; obj.Password = password; obj.AppId = 1; obj.ModifedDate = DateTime.Now; obj.EMAILID = emailId; context.AddToUpcmomingSurveyors(obj); foreach (UploadFile G in L) { UploadFiles Upld = new UploadFiles(); string s = G.GUID; var Q = (from u in context.UploadFiles where u.GUID ==s select u).FirstOrDefault(); Q.SurApp_Id = obj.SurApp_Id; } context.SaveChanges(); return result; } }