好的,我的问题是,当我尝试访问文件时,路径的文件名来自 DataTable,它只是找不到该文件。
当我从文本文件中解析文件名或只是在字符串中硬编码时,我已经对其进行了测试......当然这项工作>_<
当我从数据表中字符串文件名时,只是不知道差异在哪里。
它构建的字符串如下所示:
C:\Server\system/somefile.dat
这是代码:
string accountConnectionString = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
LoadFileChecks();
}
public SqlConnection GetAccountConnection()
{
SqlConnection connection = new SqlConnection(accountConnectionString);
connection.Open();
return connection;
}
public DataTable getFilecheck()
{
using (var con = GetAccountConnection())
{
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tFilecheck", con);
DataTable ds = new DataTable("Filecheck");
da.Fill(ds);
con.Close();
return ds;
}
}
public void LoadFileChecks()
{
DataTable table = getFilecheck();
string localPath = Application.StartupPath;
foreach (DataRow row in table.Rows)
{
string line = row["sFilename"].ToString();
string FilePath = localPath + "\\" + line;
if (!File.Exists(FilePath))
{
MessageBox.Show("File not found");
continue;
}
}
}