我想在attatchement中获取文件的扩展名,不知道如何做到这一点,下面是我的代码,在mailMessage.Add中添加输入流,文件名如何添加扩展名?下面是我的代码
if (unauthenticatedEnquiryViewModel.File != null) // this finds overall null
{
foreach (var file in unauthenticatedEnquiryViewModel.File) // loop through every File
{
if (file != null) //Finds induvidual null
{
mailMessage.Attachments.Add(new Attachment(file.InputStream, file.FileName, file.);
mailMessage.Body = mailbuilder.ToString();
}
}
}
答案 0 :(得分:0)
var extension = new FileInfo(file.FileName).Extension.ToUpper();
然后在
中传递mailMessage.Attachments.Add(new Attachment(file.InputStream, file.FileName, extension));