public IActionResult FileMediaCreate(FormTable f, IList <IFormFile> FilePicture, IFormFile FileDownload) { foreach (var FilePath in FilePicture) { if (FilePath != null) { string extention = Path.GetExtension(FilePath.FileName); string filenewname = DateTime.Now.ToString("ddmmyyyyhhmmsstt") + "pfn"; string finalpath = "/fpicpath/" + filenewname + extention; FileStream FN = new FileStream(IHEN.WebRootPath + finalpath, FileMode.Create); FilePath.CopyTo(FN); FN.Close(); f.FilePath = finalpath; ViewBag.Message = "media file successful save path in online database"; } } if (FileDownload != null) { string extention = Path.GetExtension(FileDownload.FileName); string filenewname = DateTime.Now.ToString("ddmmyyyyhhmmsstt") + "dld"; string finalpath = "/fpicpath/" + filenewname + extention; FileStream FN = new FileStream(IHEN.WebRootPath + finalpath, FileMode.Create); FileDownload.CopyTo(FN); FN.Close(); f.FileDownload = finalpath; ViewBag.Message = "media file successful save path in online database"; try { //Email flow ............write Here....... MailMessage oEmial = new MailMessage(); oEmial.To.Add(f.Email); oEmial.From = new MailAddress("*****@*****.**"); oEmial.Bcc.Add("*****@*****.**"); oEmial.Subject = "CV this is the subject of EMAIL" + f.Name; oEmial.Body = "THIS IS THE Body of Email " + f.Name; oEmial.Attachments.Add(new Attachment(IHEN.WebRootPath + finalpath)); //SMTPClind.......Servie use for Email sending....... SmtpClient oSmtp = new SmtpClient(); oSmtp.Credentials = new System.Net.NetworkCredential("sialkotem@gmail", "sialkot7868"); oSmtp.EnableSsl = true; oSmtp.Port = 465;//587//25 oSmtp.Host = "SMTP.Gmail.com"; oSmtp.Send(oEmial); } catch (Exception e) { ViewBag.Message = "Error Emial Portion" + e.Message; return(View()); } } ORM.FormTable.Add(f); ORM.SaveChanges(); return(View()); }
public void Demo() { //Creating paths (nothing is changed on disk) FilePath file = (FilePath)@"C:\Hello\World"; DirPath directory = file.Parent; // C:\Hello RelFilePath relative = file - directory; // World relative = relative.AppendPath(".txt"); // World.txt DirPath otherDirectory = (DirPath)@"C:\New"; FilePath newFile = otherDirectory + relative; // C:\New\World.txt FilePath pdfFile = newFile.GetWithExtension("pdf"); // C:\New\World.pdf DirPath otherDir = otherDirectory.CombineDir("Strong", "Typed"); // C:\New\Strong\Typed FilePath otherFile = otherDir.CombineFile("Test.txt"); // C:\New\Strong\Typed\Test.txt //Exploring disk IEnumerable <FilePath> files = directory.GetFiles("*", SearchOption.AllDirectories); IEnumerable <DirPath> directories = directory.GetDirectories(); var baseName = file.NameWithoutExtension; bool fileExists = file.Exists(); bool dirExists = directory.Exists(); //Operations on disk directory.CreateDirectory(); file.DeleteFile(); file.WriteAllText("Hello World"); file.ClearReadOnlyAttribute(); file.SetLastWriteTimeUtc(DateTime.UtcNow); directory.DeleteDir(); file.Move(pdfFile); newFile.CopyTo(otherFile); var newTarget = newFile.CopyTo(otherDir); // otherDir + newFile.Name; otherDir.CopyDirectory(otherDirectory); //Use path as a string File.ReadAllBytes(file.Path); }