We have an app we use to manage changes to our VOIP system. It uses an upload of a CSV that's built by a custom export out of the CISCO system that controls the phones. It was failing, I think, on a bad row in the .csv file where there was a "-" character, that is removing the character allowed the file to process all the way through. The method that reads the file is fed by a StreamReader and the StaticConfig object is the entity we store the record for each line in. This is the method that read the rows of the .csv:
while ((LineBuffer = sr.ReadLine()) != null)
{
// loop through all 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 the locationID
var LocationID = (from l in voipDB.Locations
where 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 to me though that this would fail on a "-" character though so I feel like I'm missing something. Looking at the MSDN write ups for .Split and Convert.ToChar I don't see anything that would fail. Can anyone tell me why it'd fail or where? Any useful sources of information regarding this? Many thanks in advance!