我正在开发一个 ASP.NET 4.5 应用程序,它读取服务器 My Documents 文件夹中另一个应用程序的日志文件。当我在调试模式下运行但没有部署一次时,它运行良好。给出以下错误:
'C:\Users\Performance\My Folder\Log\' 不是有效路径。确保路径名拼写正确并且您已连接到文件所在的服务器。
我已授予网络服务和 IISUSER 对此文件的读/写访问权限。(仅此文件而不是文件夹)
这是我的代码:
protected void lstArea_TextChanged(object sender, EventArgs e)
{
//create instance foe oledb connection class
OleDbConnection con = new OleDbConnection();
//Your datasource Location path currently i placed csv file in server location
string dsource = lstArea.SelectedValue;
//Put your datasource path in the connection string for example if you have csv files in C:\ directory change datasource= C:\
string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dsource + ";Extended Properties='text;HDR=No;FMT=Delimited';";
try
{
con.ConnectionString = constr;
//create instance for command object
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
// set your file name in the below query
cmd.CommandText = "select * from [wksplog.txt]";
//Open Oledb Connection to read CSV file
con.Open();
//Create one datatable to store data from CSV file
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader(), LoadOption.OverwriteChanges);
//Bind data in the Gridview
gvMain.DataSource = dt;
gvMain.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}
我将目录传递为 C:\Users\Performance\My Folder\Log\
出了什么问题?顺便说一句,我正在使用匿名/表单身份验证。这台机器不在域中。