コード例 #1
0
 public string uploadResumeFile()
 {
     if (Uploadfile.HasFile)
     {
         Regex fileExtension = new Regex(@"^.+\.(doc|docx|Pdf|text)");
         Match MatchResult   = fileExtension.Match(Uploadfile.FileName);
         if (MatchResult.Success)
         {
             Uploadfile.SaveAs(Server.MapPath("Resume/" + Page.Session["user"].ToString() + Uploadfile.FileName));
         }
         else
         {
             LblFileError.Text = "Please Select a .doc/.docx/.pdf/.text file only";
         }
     }
     return(Page.Session["user"].ToString() + Uploadfile.FileName);
 }
コード例 #2
0
        public async Task <IActionResult> Upload(FileCreate model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;


                if (model.FileToUpload != null)
                {
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "files");

                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.FileToUpload.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);

                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await model.FileToUpload.CopyToAsync(stream);
                    }
                }
                if (signInManager.IsSignedIn(User))
                {
                    this.email = User.Identity.Name;
                    Console.WriteLine(User.Identity.Name);
                }


                Uploadfile obj = new Uploadfile
                {
                    Email    = this.email,
                    filepath = uniqueFileName
                };
                _context.Add(obj);
                await _context.SaveChangesAsync();

                return(View("index"));
            }

            return(View());
        }