c# - 系统找不到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
}
}
解决方案
推荐阅读
- react-native - TypeError:TypeError:未定义不是一个对象(评估'_this._setComponentRef.bind')
- java - 如何从具有'O(log n)'_时间复杂度的集合中删除最大值?
- opengl - 使用 GLM 正交投影矩阵将三角形顶点放在错误的位置
- python - 对于嵌套的for语句,python和c++的结果是不同的
- apache-spark - 无法在 Spark 结构化流中转换 Kafka Json 数据
- c - GtkFixed 的用法:内部小部件忽略坐标
- javascript - redux-from initialValues 设置不适用于选择选项
- conda - 在基础 conda 上使用 pipenv
- php - 如何修复显示数组中的多张图片
- android - 有没有什么方法可以从图库中选择或从相机拍摄的纵向模式显示横向图像