public static void DownloadDocument(Document downloadDoc, HttpContextBase context) { CloudBlobContainer sampleContainer = client.GetContainerReference(downloadDoc.Container); CloudBlockBlob fileBlob = sampleContainer.GetBlockBlobReference(downloadDoc.Blob); context.Response.Charset = "UTF-8"; context.Response.Buffer = false; context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + downloadDoc.FileName + "\""); context.Response.AddHeader("Content-Length", downloadDoc.FileSize); //Set the length the file context.Response.ContentType = "application/msword"; context.Response.Flush(); fileBlob.DownloadToStream(context.Response.OutputStream); }
public static bool UploadDocument(Document uploadDoc, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { try { CloudBlobContainer studentContainer = client.GetContainerReference(uploadDoc.Container); studentContainer.CreateIfNotExists(); CloudBlockBlob blob = studentContainer.GetBlockBlobReference(uploadDoc.Blob); using (Stream fileStream = file.InputStream) { blob.UploadFromStream(fileStream); } } catch (Exception ex) { Console.WriteLine(ex.Message); return false; } return true; } return false; }
public ActionResult Upload(HttpPostedFileBase file, int SelectedUserID, int VersID, string returnUrl) { if (file != null && file.ContentLength > 0) { Document feedbackUpload = new Document { FileName = file.FileName, FileSize = file.ContentLength.ToString(), UploadDate = DateTime.Now, Container = "user" + SelectedUserID }; db.saveFeedback(feedbackUpload, VersID); try { FileManager.UploadDocument(feedbackUpload, file); ViewBag.SuccessMessage = "Upload Successfull!"; } catch { ViewBag.SuccessMessage = "Upload Failed. Please Try Again."; } } else { ViewBag.SuccessMessage = "Upload Failed. Please attach a non-empty file"; } if (returnUrl != null) { return Redirect(returnUrl + "&Message=" + ViewBag.SuccessMessage); } else { return RedirectToAction("Index"); } }
public void uploadTask(int taskID, int userID, Document uploadDoc) { var taskVersions = db.TaskVersions.Where(v => v.UserID == userID && v.TaskID == taskID); TaskVersion uploadTask = new TaskVersion() { Document = uploadDoc, RatingStatus = "Pending", TaskID = taskID, UserID = userID, Version = taskVersions.FirstOrDefault() != null ? taskVersions.Max(v => v.Version) + 1 : 1 }; uploadDoc.Blob = uploadTask.TaskID + "/" + uploadTask.Version; db.Documents.Add(uploadDoc); db.TaskVersions.Add(uploadTask); db.SaveChanges(); }
public void saveFeedback(Document feedbackDoc, int versID) { TaskVersion updateVersion = db.TaskVersions.Find(versID); feedbackDoc.Blob = updateVersion.Document.Blob + "feedback"; db.Documents.Add(feedbackDoc); updateVersion.FeedbackDoc = feedbackDoc; db.SaveChanges(); }
public ActionResult Upload(HttpPostedFileBase file, int taskID, int ProgramCohortID) { if (file != null && file.ContentLength > 0) { Document uploadDoc = new Document() { Container = "user" + User.Identity.GetUserId(), FileName = file.FileName, FileSize = file.ContentLength.ToString(), UploadDate = DateTime.Now, }; db.uploadTask(taskID, Convert.ToInt32(User.Identity.GetUserId()), uploadDoc); FileManager.UploadDocument(uploadDoc, file); } return RedirectToAction("Index", new {TaskID = taskID, ProgramCohortID = ProgramCohortID }); }