ASP C# WebSite to load a simple CSV File
-
Hi All, 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
Well you could try: 0)
@"\\td47vc\public\Joe\ASP\Test";
- Using the IP of the server instead of the server name (10.xx.xx.xx instead of \\someserver01). Maybe it's on a different VLAN and it does not know it by name 2) If it still doesn't work then it's clearly a matter of credentials/rights. That one only you and/or the admin can fix. :)
I used to think.... Finally I realized it's no good.
modified on Tuesday, December 7, 2010 4:28 AM
-
Well you could try: 0)
@"\\td47vc\public\Joe\ASP\Test";
- Using the IP of the server instead of the server name (10.xx.xx.xx instead of \\someserver01). Maybe it's on a different VLAN and it does not know it by name 2) If it still doesn't work then it's clearly a matter of credentials/rights. That one only you and/or the admin can fix. :)
I used to think.... Finally I realized it's no good.
modified on Tuesday, December 7, 2010 4:28 AM
do you really want double backslashes everywhere? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.
-
do you really want double backslashes everywhere? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.
-
Nice. I missed it completely. Just focused on the start. Fixed. :)
I used to think.... Finally I realized it's no good.
you'll have to try again I'm afraid, if you want a double backslash, either give four, or use '@'; three backslashes is no good. I prefer the '@' approach, as that takes and shows the string as intended. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.
-
you'll have to try again I'm afraid, if you want a double backslash, either give four, or use '@'; three backslashes is no good. I prefer the '@' approach, as that takes and shows the string as intended. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.
-
Yep that's what I did. Just before you fixed my "code" the second time :laugh: I guess I'm better of just fooling around. :)
I used to think.... Finally I realized it's no good.
looking great now. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.
-
Hi All, 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
-
Hi All, 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
what about setting your connection string in web inf instead of code :)
-
what about setting your connection string in web inf instead of code :)
-
Hi All, 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
Try mapping virtual path to physical path using Server object. For example where you are doing
string pathName = "\\td47vc\\public\\Joe\\ASP\\Test";
instead do it something like
string pathName = Server.MapPath("~/Joe/Asp/Test.csv");
Where you need to make sure you are passing correct virtual path to MapPath call. You need to specify it relative to your application root.
I Web Development Free Lancer
Share your experience with others Check my Blog...