//-------------------------------------------------------------------------------- //сохранение файла private void backgroundDownloader_DoWork(object sender, DoWorkEventArgs e) { MyFile file=(MyFile)e.Argument; using (FileStream output = new FileStream(file.Path, FileMode.Create)) { SinchronizeFileProgressInfo.ProgressBytes = 0; SinchronizeFileProgressInfo.ProgressProcent = 0; SinchronizeFileProgressInfo.Action = FileStatus.Download; using (FileSystemClient serverFileSystem = new FileSystemClient()) { StreamWithProgress fileSourceStream = new StreamWithProgress(serverFileSystem.GetFileStream(selectedFileId, Account.GetUserEmail(), Account.GetUserPass())); fileSourceStream.ProgressChanged += SetProgressInfoData; fileSourceStream.CopyTo(output); } } }
public ActionResult DownloadFile(int id, string name) { string userEmail = (string)Session["email"]; string userPassword = (string)Session["password"]; if (userEmail == null || userPassword == null) return RedirectToRoute("Logout"); FileSystemClient serverFileSystem = new FileSystemClient(); try { return File(serverFileSystem.GetFileStream(id, userEmail, userPassword), "application/octet-stream", name); } catch (Exception) { return RedirectToRoute("UserEvents"); } }