添加文件扩展名?

时间:2016-09-21 13:49:41

标签: c# asp.net asp.net-mvc asp.net-mvc-5

我想在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();
         }
     }
 }

1 个答案:

答案 0 :(得分:0)

var extension = new FileInfo(file.FileName).Extension.ToUpper();

然后在

中传递
mailMessage.Attachments.Add(new Attachment(file.InputStream, file.FileName, extension));