c# - Method fails read all rows from .csv -
c# - Method fails read all rows from .csv -
we have app utilize manage changes our voip system. uses upload of csv that's built custom export out of cisco scheme controls phones. failing, think, on bad row in .csv file there "-" character, removing character allowed file process way through. method reads file fed streamreader , staticconfig object entity store record each line in. method read rows of .csv:
while ((linebuffer = sr.readline()) != null) { // loop through lines found in file string[] tmpstring = linebuffer.split(convert.tochar(",")); if (tmpstring[0] != "") { staticconfig staticentry = new staticconfig(); int extension; if (int32.tryparse(tmpstring[0].trim(), out extension)) { staticentry.directorynumber = extension; staticentry.building = tmpstring[9].trim(); staticentry.longdistance = (tmpstring[7].trim() == "1"); staticentry.classrestricted = (tmpstring[6].trim() == "1"); staticentry.voicemail = (tmpstring[8].trim() == "1"); staticentry.location = tmpstring[5].trim(); staticentry.userfname = tmpstring[1].trim(); staticentry.userlname = tmpstring[2].trim(); staticentry.userid = tmpstring[3].trim(); staticentry.employeenumber = tmpstring[4].trim(); staticentry.uploaddate = uploadtime; //get locationid var locationid = (from l in voipdb.locations l.locationname == staticentry.building select l.locationid).firstordefault(); if (locationid != guid.empty) staticentry.locationid = locationid; else { location newlocation = new location(); newlocation.locationid = guid.newguid(); newlocation.locationname = staticentry.building; newlocation.islocked = false; newlocation.issubmitted = false; voipdb.addtolocations(newlocation); staticentry.locationid = newlocation.locationid; voipdb.savechanges(); } voipdb.staticconfigs.addobject(staticentry); processed++; } } }
it makes no sense me though fail on "-" character though sense i'm missing something. looking @ msdn write ups .split , convert.tochar don't see fail. can tell me why it'd fail or where? useful sources of info regarding this? many in advance!
c# csv
Comments
Post a Comment