public FileResult DownloadNotes(int id) { DAO oDAO = new DAO(MvcApplication.SF.GetCurrentSession()); TblNotes note = oDAO.getNotes(id); string file = note.NotesFile; string RootFolder = AppDomain.CurrentDomain.BaseDirectory + "Uploads/"; string FullPath = RootFolder + "NotesFiles/" + file; note.NotesDownloads = note.NotesDownloads + 1; oDAO.uploadNotes(note); return(File(FullPath, MimeMapping.GetMimeMapping(file), Path.GetFileNameWithoutExtension(file) + Path.GetExtension(file))); }
public ActionResult UploadNotes(TblNotes notes) { if (ModelState.IsValid) { try { foreach (string upload in Request.Files) { if (Request.Files[upload].ContentLength > 0) { string RootFolder = AppDomain.CurrentDomain.BaseDirectory + "Uploads/"; if (!Directory.Exists(RootFolder + "NotesFiles/")) { Directory.CreateDirectory(RootFolder + "NotesFiles/"); } string path = RootFolder + "NotesFiles/"; string Filename = System.IO.Path.GetFileNameWithoutExtension(Request.Files[upload].FileName); string ext = System.IO.Path.GetExtension(Request.Files[upload].FileName); string newfilename = Filename + DateTime.Now.ToString("ddMMyyyyttmm") + ext; notes.NotesFile = newfilename; Request.Files[upload].SaveAs(System.IO.Path.Combine(path, newfilename)); } } DAO oDAO = new DAO(MvcApplication.SF.GetCurrentSession()); notes.SessionId = 1; notes.NotesPosteddate = DateTime.Now; notes.CourseId = 1; notes.UserId = 1; notes.UserType = "Student"; notes.UpdatedNotes = "NO"; notes.NotesDownloads = 0; if (oDAO.uploadNotes(notes)) { TempData["Message"] = Constants.allModelProperties.registrationMessage; return(RedirectToAction("NotesList", "Home")); } } catch (Exception ex) { ViewBag.Message = ex.Message; } } return(View()); }