Reputation: 698
I want to have an ASP C# WebSite that loads a simple CSV File and present it in a GridView control (at least for a start).
I already have a piece of code that do almost all of the work, what i miss / unable to make it work is setting correctly the "Data Source".
The CSV file that I want to load is located on different server in the network (path is "\td47vc\public\Joe\ASP\Test").
Here is the code I wrote:
public DataSet GetCSVFile(string fileName)
{
string pathName = "\\td47vc\\public\\Joe\\ASP\\Test";
string file = System.IO.Path.GetFileName(fileName);
OleDbConnection excelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties=Text;");
OleDbCommand excelCommand = new OleDbCommand(@"SELECT * FROM " + file, excelConnection);
OleDbDataAdapter excelAdapter = new OleDbDataAdapter(excelCommand);
excelConnection.Open();
DataSet ds = new DataSet();
excelAdapter.Fill(ds);
excelConnection.Close();
return ds;
}
I get the following error: '\td47vc\public\Joe\ASP\Test' 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.
Thanks,
GorovDude
Upvotes: 1
Views: 2824
Reputation: 4968
That comes up mostly because of code access security or other permission issue.
http://blogs.msdn.com/b/shawnfa/archive/2004/12/30/344554.aspx
This would anyways have performance bottleneck. It is highly recommended to have a local copy.
Upvotes: 0
Reputation: 2824
public DataSet GetCSVFile(string fileName)
{
string pathName = "\\\\td47vc\\public\\Joe\\ASP\\Test";
string file = System.IO.Path.GetFileName(fileName);
OleDbConnection excelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties=Text;");
OleDbCommand excelCommand = new OleDbCommand(@"SELECT * FROM " + file, excelConnection);
OleDbDataAdapter excelAdapter = new OleDbDataAdapter(excelCommand);
excelConnection.Open();
DataSet ds = new DataSet();
excelAdapter.Fill(ds);
excelConnection.Close();
return ds;
}
Upvotes: 1