我有以下代码:
var dir = @"Content\Posts\" + yr + @"\" + mnth + @"\";
var a = Path.Combine(dir, dy.ToString() + pId.ToString() + ".txt");
//a contains: "Content\\Posts\\2013\\8\\file01.txt"
stts = obj.NotifyMail(title, writeup, "author@gmail.com", a);
而不是在 NotifyMail 函数中我有这个:
public bool NotifyMail(string subject, string body, string toAdd, string filePath)
{
…
string attachments = HttpContext.Current.Server.MapPath(filePath);
//NOW here attachments contains: "G:\\Program Files\\Derby\\Work\\Development\\proj\\proj\\`Post`\\Content\\Posts\\2013\\8\\file01.txt"
var attchmnts = new LinkedResource(attachments);
attchmnts.ContentId = "attchmnts";
…
}
现在问题在于NotifyMail
何时attachments
通过Server.MapPath
返回包含无效文件夹的路径来检索物理文件路径,即Post
该文件夹不存在于任何地方,甚至在硬盘驱动器中也不存在,我不知道它是如何被拾取的回来。但是说这个由于这个问题LinkedResource(attachments);
是抛出异常:
{"Could not find a part of the path ‘G:\\Program Files\\Derby\\Work\\Development\\proj\\proj\\Post\\Content\\Posts\\2013\\8\\file01.txt"’