c# - SOLVED Issue reading an cvs file in the server -
i having issues reading cvs file in server. know sure not folder permission issue because able upload , delete file in server.
the problem here: using (streamreader sr = file.opentext(@"fulldomain/mycvsfolder/promocodes.cvs"))
this code works in local if change file location local path @"c:etc" appreaciate help!
code:
protected void btnpreviewfile_click(object sender, eventargs e) { datatable dt = new datatable(); string line = null; int = 0; try{ using (streamreader sr = file.opentext(@"fulldomain/mycvsfolder/promocodes.cvs")) { while ((line = sr.readline()) != null) { string[] data = line.split(','); if (data.length > 0) { if (i == 0) { foreach (var item in data) { dt.columns.add(new datacolumn()); } i++; } datarow row = dt.newrow(); row.itemarray = data; dt.rows.add(row); labelalert.text = "preview good"; //display data in gridview control gridview1.datasource = dt; gridview1.databind(); } } } }catch(exception ex){ labelalert.text = ex.tostring(); } }
here solution mihai gave me.
i replace line
`using (streamreader sr = file.opentext(@"fulldomain/mycvsfolder/promocodes.cvs"))`
with
`using (streamreader sr = file.opentext(server.mappath("/mycvsfolder/promocodes.cvs")))`
Comments
Post a Comment