[英]Send Email with multiple attachements using asp.net c#
I am trying to send attachment using following code. 我正在尝试使用以下代码发送附件。 But i keep getting error
Could not find a part of the path
. 但是我一直出错,
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
我正在从
ApplyForJob.aspx.cs
App_Code/Helper.cs
文件夹下的ApplyForJob.aspx.cs
文件调用sendEmail函数
Below is the part of SendEmail
function 以下是
SendEmail
功能的一部分
// 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
我已将路径更改为
~/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/
我如何使路径正确指向存储在
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 其他详细信息: 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.) 这将在App_Data文件夹中找到Example.xml文件(App_Data是放置数据文件的好地方。)
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. 这将在根目录中找到Example.txt文件。 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"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.