コード例 #1
0
        public ActionResult UploadPaper(PaperUploadModels model)
        {
            var conference = db.Conferences.Find(model.ConferenceId);

            if (model.PostedFile != null)
            {
                string pathStr = "~/SubmittedPapers/Conf" + model.ConferenceId + "/";
                string path    = Server.MapPath(pathStr);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string strExt = (new FileInfo(pathStr + model.PostedFile.FileName)).Extension.ToLower();
                if ((strExt != ".pdf") && (strExt != ".doc") && (strExt != ".docx"))
                {
                    ViewBag.Message = "Invalid File Type";
                }
                else
                {
                    var   userId = User.Identity.GetUserId();
                    Users user   = db.Users.Find(userId);
                    if (System.IO.File.Exists(path + user.Id + strExt))
                    {
                        System.IO.File.Delete(path + user.Id + strExt);
                    }
                    model.PostedFile.SaveAs(path + user.Id + strExt);
                    ViewBag.Message = "File uploaded successfully.";
                    return(RedirectToAction("Create", "Papers", new { confId = model.ConferenceId }));
                }
            }
            return(View(model));
        }
コード例 #2
0
        public ActionResult UploadPaper(string conferenceId)
        {
            var model = new PaperUploadModels
            {
                ConferenceId = conferenceId,
                AuthorId     = User.Identity.GetUserId(),
            };

            return(View(model));
        }