I’m developing a ASP.NET 4.5 application which reads a log file of another application which is in server My Documents folder.
It works well when I run in debug mode but not once deployed.
Gives following error :
‘C:\Users\Performance\My Folder\Log\’ is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
I have given Network Service and IISUSER read/write access to this file.(only this file and not folder)
This my code :
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();
}
}
I’m passing the directory as C:\Users\Performance\My Folder\Log\
What is going wrong? BTW am using anonymous/ forms authentication. This machine is not in the domain.
The user the application is running as needs read access to all parent folders of the log file otherwise you will receive an access violation.