public ActionResult Create([Bind(Include = "articleId,journId,articleDate,articleTopic,articleTitle,articleDesc")] Article article) { if (ModelState.IsValid) { db.Articles.Add(article); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.journId = new SelectList(db.Journalists, "journId", "journFname", article.journId); return(View(article)); }
public ActionResult Create2([Bind(Include = "JournFname,JournLname,JournDOB,JournContact,JournEmail,JournCity,Journalist_Image")] Journalist journalist, HttpPostedFileBase postedFile) { if (postedFile != null) { string path = Server.MapPath("~/Uploads/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (Helpers.Util.IsRecognisedImageFile(postedFile.FileName)) { // Here I want each image to have a unique path. Doesn't matter if the same image is uploaded. E // Each path is the same length. String filePath = Helpers.Util.GenerateUniqueString(); filePath = Helpers.Util.CalculateMD5Hash(filePath); String fileExtension = Path.GetExtension(postedFile.FileName); String full = filePath + fileExtension; postedFile.SaveAs(path + full); journalist.Journalist_Image = full; string abc = journalist.Journalist_Image + journalist.journFname + journalist.JournLname + journalist.journDOB + journalist.journContact + journalist.journEmail + journalist.journCity; using (StreamWriter file = new StreamWriter(@"D:\WriteLines2.txt")) file.Write(abc); } else { ViewBag.Message = "Please upload a valid image."; return(View(journalist)); } } db.Journalists.Add(journalist); db.SaveChanges(); procedureExe(); return(RedirectToAction("Register", "Account")); }