我有以下代碼:返回使用Server.Mappath的路徑與不夾存在
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, "[email protected]", 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"’
嘗試過,但仍然在返回的路徑中額外的未知文件夾。 – Maven
任何在提到「發佈」的web.config或IIS應用程序設置?我的猜測是這是一個錯誤的帖子也許..?此外,可能沒有什麼區別,但@「內容\文章\」 +年+ @「\」 + mnth + @「\」應該使用/,而不是\,因爲它是一個相對URL,而不是文件路徑。 –