public void ParseCSV(DotNetNuke.Services.FileSystem.FileInfo fileInfo, int startIndex) { using (CsvReader reader = new CsvReader(new StreamReader(fileInfo.PhysicalPath), true)) { int tabModuleId = DataProvider.Instance().GetTabModuleIdByFileId(fileInfo.FileId); int lineNumber = 0; if (startIndex == 0) { DataProvider.Instance().ClearTempLocations(); } else { lineNumber = startIndex; reader.MoveTo(startIndex - 1); } try { while (reader.ReadNextRecord()) { lineNumber++; Location location = new Location(); location.LocationId = Convert.ToInt32(GetValue(reader, "UNIQUE_KEY"), CultureInfo.InvariantCulture); location.ExternalIdentifier = GetValue(reader, "EXTERNAL_IDENTIFIER"); location.Name = GetValue(reader, "LOCATION_NAME"); string address1 = GetValue(reader, "ADDRESS1"); string address2 = GetValue(reader, "ADDRESS2"); location.City = GetValue(reader, "CITY"); string state = GetValue(reader, "STATE"); location.PostalCode = GetValue(reader, "ZIP"); location.Phone = GetValue(reader, "PHONE_NUMBER"); location.LocationDetails = GetValue(reader, "LOCATION_DETAILS"); location.Website = GetValue(reader, "WEBSITE"); location.PortalId = this.portalId; string locationType = GetValue(reader, "TYPE_OF_LOCATION"); if (locationType == string.Empty) { locationType = "Default"; } string country = GetValue(reader, "COUNTRY"); DataTable dt = DataProvider.Instance().GetLocationTypes(); int locationTypeId = -1; foreach (DataRow dr in dt.Rows) { if (Convert.ToString(dr["LocationTypeName"], CultureInfo.InvariantCulture) == locationType) { locationTypeId = Convert.ToInt32(dr["LocationTypeID"], CultureInfo.InvariantCulture); location.LocationTypeId = locationTypeId; } } if (locationTypeId == -1) { locationTypeId = DataProvider.Instance().InsertLocationType(locationType); location.LocationTypeId = locationTypeId; } location.RegionId = ResolveState(state); if (location.RegionId < 1) { location.RegionId = Convert.ToInt32(null, CultureInfo.InvariantCulture); } location.CountryId = ResolveCountry(country); if (location.CountryId < 1) { ModuleController objModules = new ModuleController(); location.CountryId = Dnn.Utility.GetIntSetting(objModules.GetTabModuleSettings(tabModuleId), "DefaultCountry").Value; } location.CsvLineNumber = lineNumber; location.Address = address1; // Address2 is informational only - See Pat Renner. location.Address2 = address2; GeocodeResult geocodeResult = GetGeoCoordinates(tabModuleId, address1, location.City, location.RegionId, location.PostalCode, location.CountryId); if (geocodeResult.Successful) { location.Latitude = geocodeResult.Latitude; location.Longitude = geocodeResult.Longitude; } location.Approved = true; try { location.SaveTemp(geocodeResult.Successful); } catch (SqlException ex) { Exceptions.LogException(ex); } } } catch (ArgumentException exc) { Exceptions.LogException(exc); this.FileMove(false); } if (lineNumber == 0) { this.FileMove(false); } } }