我有一个Web应用程序,用于向订阅者发送电子邮件。现在我在从Web应用程序文件夹访问图像文件时遇到一些问题。这是我的代码:
string fbody = plainText.Replace("\"", "'");
if (fbody.Contains("src='cid:"))
{
var htmlView = AlternateView.CreateAlternateViewFromString(msg.Body, null, "text/html");
do
{
int src = fbody.IndexOf("src='cid:");
if (src != -1)
{
fbody = fbody.Remove(0, src + 9);
var dot = Regex.Match(fbody, @"\.(jpg|jpeg|gif|png)");
if (dot.Success)
{
int comma = fbody.IndexOf("'");
if (comma != -1)
{
if (!string.IsNullOrEmpty(fbody.Substring(0, comma)))
{
string imageSource = Path.Combine(HttpRuntime.AppDomainAppPath, "EmailFiles/" + fbody.Substring(0, comma)); // here I got image file
var leftImageLink = (dynamic)null;
switch (Path.GetExtension(imageSource).ToLower())
{
case ".jpg":
leftImageLink = new LinkedResource(imageSource, "image/jpg") // here error thrown could not access file
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
case ".jpeg":
leftImageLink = new LinkedResource(imageSource, "image/jpeg")
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
case ".gif":
leftImageLink = new LinkedResource(imageSource, "image/gif")
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
case ".png":
leftImageLink = new LinkedResource(imageSource, "image/png")
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
}
htmlView.LinkedResources.Add(leftImageLink);
}
}
}
}
}
while (fbody.Contains("src='cid:"));
msg.AlternateViews.Add(htmlView);
这里出了什么问题。我在imagesource获得文件,但没有leftImageLink。这里出了什么问题???