Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi
I am creating one simple page which has one form. Its code is like below :
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using System.Net; @using System.Net.Mail; @{ if(IsPost) { //Way 1: to get attachment var fileSavePath = ""; var uploadedFile = Request.Files[0];//Here not getting file name var fileName = Path.GetFileName(uploadedFile.FileName); fileSavePath = Server.MapPath("~/media/" + fileName); uploadedFile.SaveAs(fileSavePath); FileInfo info = new FileInfo(fileSavePath); string[] ext = fileName.Split('.'); //Way 2 : var a = Request["fluld"];//Getting file name only var b = Request.Files;//Getting null here string d = Path.GetFullPath(Request["fluld"]); string c = string.Empty; try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("[email protected]"); mail.To.Add("[email protected]"); mail.Subject = "Test Mail"; mail.Body = "This is for testing SMTP mail from GMAIL"; System.Net.Mail.Attachment attachment; attachment = new System.Net.Mail.Attachment("filepath"); mail.Attachments.Add(attachment); SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "******"); SmtpServer.EnableSsl = true; //SmtpServer.Send(mail); //MessageBox.Show("mail Send"); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } } <form method="post"> <input type="file" name="fluld" id="fluld" /> <input type="submit" value="Sub"/> </form>
I am not able to get file for email attachment with this Request.Files. Help me with this. Any thing I need to add?
Request.Files
Thanks
Dipa
Atleast your form should have enctype = "multipart/form-data". As <form method="post" enctype="multipart/form-data">
<form method="post" enctype="multipart/form-data">
Hi,
Thanks, I forgot that. It works.
Hi Yasir,
I have one more doubt. When mail sent successfully it should get redirect to another page. How to do that? Can you help me with this? I am not getting it.
Thanks,
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Get file upload for email attachment
Hi
I am creating one simple page which has one form. Its code is like below :
I am not able to get file for email attachment with this
Request.Files
. Help me with this. Any thing I need to add?Thanks
Dipa
Atleast your form should have enctype = "multipart/form-data". As
<form method="post" enctype="multipart/form-data">
Hi,
Thanks, I forgot that. It works.
Hi Yasir,
I have one more doubt. When mail sent successfully it should get redirect to another page. How to do that? Can you help me with this? I am not getting it.
Thanks,
Dipa
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.