首页 > 解决方案 > 系统找不到c#中指定的文件(不上传)

问题描述

今天早上我用 C# ASP.NET 开发的应用程序出现了一个以前从未出现过的问题

此应用程序将文件名存储在数据库的列中

当需要通过电子邮件发送附件时,应用程序会查找文件名并将其附加到邮件中

即使这些文件正确存在并阻止发送带附件的电子邮件,应用程序也无法在服务器的物理路径上找到附件

错误是

系统找不到指定的文件 'C:\inetpub\wwwroot\public\newfile.pdf'

该文件newfile.pdf而不是位于公用文件夹内

如何解决这个问题?

我的简化代码如下

List<string> listofattachments = new List<string>();


using (OdbcDataReader reader = cmd.ExecuteReader())
{
    if (reader.HasRows)
    {
        while (reader.Read())
        {
            listofattachments.Add(reader["attachment"].ToString());
        }
    }
}


foreach (string attachments in listofattachments)
{
   if (!string.IsNullOrEmpty(attachments))
   {
      mailMessagePlainText.Attachments.Add(new Attachment(@"C:\\inetpub\\wwwroot\\public\\" + attachments.Trim().ToString())); //line of error
   }
}

标签: c#file

解决方案


推荐阅读