I am trying to send attachment using following code. But i keep getting error Could not find a part of the path
.
I am Calling sendEmail function from ApplyForJob.aspx.cs
file which is in under folder App_Code/Helper.cs
Below is the part of SendEmail
function
// Create a new Smpt Client
var mailclient = new SmtpClient();
System.Net.Mail.Attachment attachment1;
attachment1 = new System.Net.Mail.Attachment(HttpContext.Current.Server.MapPath("~/App_Data/uploads/" + am1));
mail.Attachments.Add(attachment1);
I have changed path to ~/App_Data/uploads/" + am1
App_Data/uploads/" + am1
../App_Data/uploads/" + am1
But none of the options seem to be working.
How can i make path correctly point towards file which is stored in App_Data/Uploads/
General Folder Structure
App_Data
..Upload
....resume1.docx
....resume2.docx
....resume3.docx
....resume4.docx
....resume4.docx
App_Code
..Helper.cs
English
..Default.aspx
..Default.aspx.cs
..ApplyForJob.aspx
..ApplyForJob.aspx.cs
Spanish
Problem was resolved by using
HttpContext.Current.Request.MapPath
Other Details: http://forums.asp.net/t/1813648.aspx http://www.dotnetperls.com/mappath
您需要使用
Server.MapPath("Path as String")
This will locate the Example.xml file in the App_Data folder (App_Data is a good place to put data files.)
attachment1 = new System.Net.Mail.Attachment(HttpContext.Current.Server.MapPath("~/App_Data/Example.xml"));
This will locate the Example.txt file in the root directory. This can be used in a file in any directory in the application.
attachment1 = new System.Net.Mail.Attachment(HttpContext.Current.Request.MapPath("~/Example.txt"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.