public List <Covenant> LoadCovenents(string fileName) { var returnVal = new List <Covenant>(); using (var reader = new StreamReader(fileName)) { var csvReader = new CsvHelper.CsvReader(reader); while (csvReader.Read()) { ///todo: this is very brittle var record = csvReader.CurrentRecord; long bankId = 0; float maxDefualt = 1.0f; long facilityId = 0; if (long.TryParse(record[0], out facilityId)) { float.TryParse(record[1], out maxDefualt); long.TryParse(record[2], out bankId); returnVal.Add(new Covenant() { BankId = bankId, FacilityId = facilityId, MaxDefaultLikelihood = maxDefualt, BannedState = record[3].Trim() }); } } } return(returnVal); }
public Dictionary <long, Facility> LoadFacility(string fileName) { var returnVal = new Dictionary <long, Facility>(); using (var reader = new StreamReader(fileName)) { var csvReader = new CsvHelper.CsvReader(reader); while (csvReader.Read()) { ///todo: this is very brittle ///amount,interest_rate,id,bank_id var record = csvReader.CurrentRecord; int amount = int.Parse(record[0], System.Globalization.NumberStyles.AllowDecimalPoint); float interest = float.Parse(record[1]); long id = int.Parse(record[2]); long bankId = long.Parse(record[2]); returnVal.Add(id, new Facility() { Id = id, Amount = amount, InterestRate = interest, BankId = bankId }); } } return(returnVal); }
/// <summary> /// Read start csv file /// </summary> /// <param name="path">path to file</param> /// <returns></returns> public IEnumerable <Student> ReadFile(string path) { const int SkipThreeItems = 3; using var reader = new StreamReader(path); using var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture); var records = new List <Student>(); csv.Read(); csv.ReadHeader(); while (csv.Read()) { if (csv.Context.Record.Length != csv.Context.HeaderRecord.Length) { throw new InvalidDataException("Wrong number of parameters"); } var listOfSubjects = new List <Subject>(); for (int index = SkipThreeItems; index < csv.Context.Record.Length; index++) { var subject = new Subject(csv.Context.HeaderRecord[index], csv.GetField <int>(index)); listOfSubjects.Add(subject); } records.Add(new Student(csv.GetField(0), csv.GetField(1), csv.GetField(2), listOfSubjects)); } return(records); }
public override ContentItem GetById(ValidUrl url_, ContentViewType viewType_) { //ContentItem item = _db.GetCollection<ContentItem>(COLLNAME).AsQueryable<ContentItem>().Where(x => x.Url.Id == url_.Id && x.ContentView.ViewType == viewType_).FirstOrDefault<ContentItem>(); ContentItem item = _db.GetCollection <ContentItem>(COLLNAME).Find(Query.And(Query.EQ("Url.Id", url_.Id), Query.EQ("ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault <ContentItem>(); if (item == null) { DependencyManager.Logger.Log(new LogEventInfo(LogLevel.Debug, ECMSSettings.DEFAULT_LOGGER, "Specific content not found now going to search for default content.")); item = _db.GetCollection <ContentItem>(COLLNAME).Find(Query.And(Query.EQ("ContentView.SiteId", url_.SiteId), Query.EQ("ContentView.ViewName", url_.View), Query.EQ("ContentView.ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault <ContentItem>(); } //TODO : Optimize this if (item != null) { using (StringReader streamReader = new StringReader(item.Body[0].ToString())) { using (var csv = new CsvHelper.CsvReader(streamReader)) { //csv.Configuration.IgnoreQuotes = true; csv.Read(); item.Body = JObject.FromObject(csv.GetRecord(typeof(object))); } } } return(item); }
//***********************************ReadFile*********************************** // This would only be used if we wanted to edit the by talking to alexa // This method is not implemented. private void ReadFile() { if (System.IO.File.Exists(FilePath)) { // Stream file and read using (var fs = new System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite)) { //Read file stream using (var tr = new System.IO.StreamReader(fs)) { // Read csv file. CsvHelper.CsvReader csvR = new CsvHelper.CsvReader(tr); try { while (csvR.Read()) { string item = csvR.GetField <string>(0); string property = csvR.GetField <string>(1); } } catch { } // close tr.Dispose(); fs.Dispose(); fs.Close(); } } } }
private IEnumerable <Document> ReadCsv() { using (var reader = new StreamReader(path)) using (var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture)) { return(csv.GetRecords <Document>().ToList()); } }
public IEnumerable <T> GetRecords <T>() { IEnumerable <T> records = null; CsvHelper.CsvReader csvReader = OpenCsvReader <T>(_csvPath); records = csvReader.GetRecords <T>(); return(records); }
static void Main(string[] args) { //Create our service PushService push = new PushService(); //Wire up the events push.Events.OnDeviceSubscriptionExpired += new PushSharp.Common.ChannelEvents.DeviceSubscriptionExpired(Events_OnDeviceSubscriptionExpired); push.Events.OnDeviceSubscriptionIdChanged += new PushSharp.Common.ChannelEvents.DeviceSubscriptionIdChanged(Events_OnDeviceSubscriptionIdChanged); push.Events.OnChannelException += new PushSharp.Common.ChannelEvents.ChannelExceptionDelegate(Events_OnChannelException); push.Events.OnNotificationSendFailure += new PushSharp.Common.ChannelEvents.NotificationSendFailureDelegate(Events_OnNotificationSendFailure); push.Events.OnNotificationSent += new PushSharp.Common.ChannelEvents.NotificationSentDelegate(Events_OnNotificationSent); push.Events.OnChannelCreated += new PushSharp.Common.ChannelEvents.ChannelCreatedDelegate(Events_OnChannelCreated); push.Events.OnChannelDestroyed += new PushSharp.Common.ChannelEvents.ChannelDestroyedDelegate(Events_OnChannelDestroyed); //Configure and start Apple APNS // IMPORTANT: Make sure you use the right Push certificate. Apple allows you to generate one for connecting to Sandbox, // and one for connecting to Production. You must use the right one, to match the provisioning profile you build your // app with! var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Resources/myMood-prod-push-cert.p12")); //IMPORTANT: If you are using a Development provisioning Profile, you must use the Sandbox push notification server // (so you would leave the first arg in the ctor of ApplePushChannelSettings as 'false') // If you are using an AdHoc or AppStore provisioning profile, you must use the Production push notification server // (so you would change the first arg in the ctor of ApplePushChannelSettings to 'true') push.StartApplePushService(new ApplePushChannelSettings(appleCert, "d1scov3r!")); //push.QueueNotification(NotificationFactory.Apple() // .ForDeviceToken("14e9c79db41cf4aa205cb72e7d60cede573cfa1867f1427ddd7372ef19c29b3a") // .WithAlert("Remember to send yourself a myMood report before handing back the iPad") // .WithSound("default") // ); using (var csv = new CsvHelper.CsvReader(new StreamReader(typeof(Device).Assembly.GetManifestResourceStream(typeof(Device).Assembly.GetName().Name + ".devices.csv")))) { while (csv.Read()) { var device = csv.GetRecord <Device>(); //Fluent construction of an iOS notification //IMPORTANT: For iOS you MUST MUST MUST use your own DeviceToken here that gets generated within your iOS app itself when the Application Delegate // for registered for remote notifications is called, and the device token is passed back to you push.QueueNotification(NotificationFactory.Apple() .ForDeviceToken(device.DeviceId) .WithAlert("Remember to send yourself a myMood report before handing back the iPad!") //.WithSound("default") ); } } //Stop and wait for the queues to drains push.StopAllServices(true); Console.WriteLine("Queue Finished, press return to exit..."); Console.ReadLine(); }
public List <T> Read <T, M>(TextReader file) where T : class where M : class { var csv = new CsvHelper.CsvReader(file); DefaultConfiguration(csv); csv.Configuration.RegisterClassMap(typeof(M)); return(csv.GetRecords <T>().ToList()); }
public FileInitializedInMemoryDataStore(string fileName) { using (StreamReader sr = new StreamReader(fileName)) { CsvReader reader = new CsvHelper.CsvReader(sr); reader.Configuration.Delimiter = ","; reader.Configuration.RegisterClassMap <HotelInfoMap>(); hotels = reader.GetRecords <HotelInfo>().ToList(); } }
public List <T> Read <T>(TextReader file) where T : class { Configuration c = new Configuration() { BadDataFound = null }; var csv = new CsvHelper.CsvReader(file, c); DefaultConfiguration(csv); return(csv.GetRecords <T>().ToList()); }
public static void ReadAddressBookCsv() { string path = @"C:\Users\prajv\source\repos\AddressBookDay13\AddressBook.csv"; var reader = new StreamReader(path); var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture); var records = csv.GetRecords <AddressBook>().ToList(); foreach (AddressBook contact in AddressBook.Records) { Console.WriteLine("FullName : " + contact.firstName + " " + contact.lastName); } }
public IEnumerable <T> LoadFile <T>(string inputFile) { IEnumerable <T> records; using (var fileReader = File.OpenText(inputFile)) { CsvHelper.CsvReader r = new CsvHelper.CsvReader(fileReader); records = r.GetRecords <T>().ToList(); } return(records); }
private void Form1_Load(object sender, EventArgs e) { //read remember csv using (var reader = new StreamReader(Functions.bingPathToAppDir("\\data\\RememberMe.csv"))) using (var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture)) { csv.Read(); csv.ReadHeader(); while (csv.Read()) { var record = new user { Username = csv.GetField("Username"), Password = csv.GetField("Password"), UserType = csv.GetField("UserType") }; UserR = record; } } //re login if remember file includes info if (UserR.Password != " " && UserR.Username != " ") { tBname.Text = UserR.Username; tBpassword.Text = UserR.Password; for (int i = 0; i < Program.records.Count; i++) { if (Program.records[i].Username == tBname.Text) { if (Program.records[i].Password == tBpassword.Text) { Flag = true; CurrentUser.Username = Program.records[i].Username; CurrentUser.Password = Program.records[i].Password; CurrentUser.UserType = Program.records[i].UserType; break; } } } if (Flag == true) { lbFlag.ForeColor = System.Drawing.Color.Green; cB1.Checked = true; cB1.Enabled = false; lbFlag.Text = "Sucsesfull Login"; testc(); btnLgn.Enabled = false; btnSignup.Enabled = false; } } }
public void Import(string fileName) { if (!File.Exists(fileName)) return; using (var stream = new StreamReader(fileName)) { var reader = new CsvHelper.CsvReader(stream); _transactions = reader.GetRecords<ImportRecord>().OrderBy(x => x.Date).ThenByDescending(x => x.Amount).ToList(); } UpdateTransactions(); UpdateAccountBalances(); }
public List <T> Read <T>(string filename) { var path = basePath + "/" + filename; using (var reader = new StreamReader(path)) using (var csv = new _CsvHelper.CsvReader(reader)) { csv.Configuration.PrepareHeaderForMatch = (string header, int index) => header.ToLower(); csv.Configuration.Delimiter = ","; var records = csv.GetRecords <T>().ToList(); return(records.ToList()); } }
private void Personalinformation_Load(object sender, EventArgs e) { using (var reader = new StreamReader(Functions.bingPathToAppDir("\\data\\users.csv"))) using (var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture)) { csv.Read(); csv.ReadHeader(); while (csv.Read()) { var record = new user { Username = csv.GetField("Username"), Password = csv.GetField("Password"), UserType = csv.GetField("UserType"), Name = csv.GetField("Name"), Surname = csv.GetField("Surname"), Phonenumber = csv.GetField("Phonenumber"), Address = csv.GetField("Address"), Email = csv.GetField("Email"), Photo = csv.GetField("Photo") }; records.Add(record); } } for (int i = 0; i < records.Count; i++) { if (records[i].Username == Login.CurrentUser.Username) { textBoxName.Text = records[i].Name; textBoxSurname.Text = records[i].Surname; maskedTextBoxNumber.Text = records[i].Phonenumber; tBadress.Text = records[i].Address; textBoxEmail.Text = records[i].Email; base64Text = records[i].Photo; byte[] imageBytes = Convert.FromBase64String(records[i].Photo); // Convert byte[] to Image using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) { pictureBox1.Image = Image.FromStream(ms, true); } } Program.records[i] = records[i]; } Clear(); ClearUndo(); }
public void CsvHelper() { long poorHash = 0; using (var fs = File.OpenRead(Path)) using (var reader = new StreamReader(fs)) using (var csv = new CSH.CsvReader(reader)) { foreach (var row in csv.GetRecords <Row>().Take(TakeRows)) { poorHash += row.CreationDate; } } //System.Diagnostics.Debug.WriteLine("CSVHelper: " + poorHash); }
private bool LoadStudentFile(string path) { bool return_value = false; var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); var sr = new StreamReader(fs); var csv = new CsvHelper.CsvReader(sr); csv.Configuration.MissingFieldFound = null; csv.Configuration.BadDataFound = null; IEnumerable <COEStudentRecord> records = csv.GetRecords <COEStudentRecord>(); _StudentRecords = records.ToList(); Debug.WriteLine(_StudentRecords.Count); return_value = true; return(return_value); }
public static IEnumerable <ContractVolume> GetContractVolumes(DateTime folderDate) { ContractVolumeFolder = DirectoryNames.GetDirectoryName("ttapiContractVolume") + DirectoryNames.GetDirectoryExtension(BusinessDays.GetBusinessDayShifted(-1)); var sr = new StreamReader(ContractVolumeFolder + "/ContractList.csv"); var reader = new CsvHelper.CsvReader(sr); reader.Configuration.RegisterClassMap(new MyClassMap()); ContractVolumeList = reader.GetRecords <ContractVolume>().ToList(); for (int i = 0; i < ContractVolumeList.Count(); i++) { string[] words = ContractVolumeList[i].instrumentName.Split(); ContractVolumeList[i].SeriesKey = words[words.Count() - 1]; } return(ContractVolumeList); }
/// Add a string of text to a table public void AddStringTable(string text) { // Create the dictionary that will contain these values var stringTable = new Dictionary <string, string>(); using (var reader = new System.IO.StringReader(text)) { using (var csv = new CsvHelper.CsvReader(reader)) { var records = csv.GetRecords <Yarn.LocalisedLine>(); foreach (var record in records) { stringTable[record.LineCode] = record.LineText; } } } AddStringTable(stringTable); }
public List <String> GetStockSymbols() { List <string> myStringColumn = new List <string>(); using (var fileReader = File.OpenText(csvPath)) using (var csvResult = new CsvHelper.CsvReader(fileReader, CultureInfo.InvariantCulture)) { csvResult.Read(); csvResult.ReadHeader(); while (csvResult.Read()) { string stringField = csvResult.GetField <string>("Symbol"); myStringColumn.Add(stringField); } } return(myStringColumn); }
/// <summary> /// Queries the reporting endpoint with the specified filters and interpolated classes /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="U"></typeparam> /// <param name="reportingFilters"></param> /// <param name="betaEndPoint"></param> /// <returns></returns> private ICollection <T> QueryBetaOrCSVMap <T, U>(QueryFilter reportingFilters, bool betaEndPoint = false) where T : JSONResult where U : CSVConfig.ClassMap { var successOrWillTry = false; var results = new List <T>(); if (betaEndPoint) { // Switch to JSON Output try { reportingFilters.FormattedOutput = ReportUsageFormatEnum.JSON; var activityresults = ResponseReader.RetrieveData <T>(reportingFilters); results.AddRange(activityresults); successOrWillTry = true; } catch (Exception ex) { Logger.LogError(ex, $"Failed for JSON Format with message {ex.Message}"); } } if (!successOrWillTry) { // Switch to CSV Output reportingFilters.FormattedOutput = ReportUsageFormatEnum.Default; reportingFilters.BetaEndPoint = false; var CSVConfig = new CSVConfig.Configuration() { Delimiter = ",", HasHeaderRecord = true }; CSVConfig.RegisterClassMap <U>(); var resultscsv = new CSV.CsvReader(ResponseReader.RetrieveDataAsStream(reportingFilters), CSVConfig); results.AddRange(resultscsv.GetRecords <T>()); } Logger.LogInformation($"Found {results.Count} while querying successOrWillTry:{successOrWillTry}"); return(results); }
/// <summary> /// This will return all the movies with the related ID and only show 1 per country /// </summary> /// <param name="id">Id of movie</param> /// <returns>Metadata array of all the movies found</returns> public Metadata[] FilterMovies(int id) { //Note: This reads the CVS file var reader = new StreamReader(Environment.CurrentDirectory + "/Docs/metadata.csv"); using (var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture)) { //Note: I am doing a LINQ query to try and sort the data var reslts = csv.GetRecords <Metadata>() .OrderBy(i => i.MovieId) //Note: "i.Duration.Length == 8" is set to make sure we only get a valid time based on the spec of having HH:MM:SS .Where(i => i.MovieId == id && i.Duration.Length == 8) //Note: This part was kinda new for me as I was still getting back 2 of the same county .Distinct(new DistinctItemComparer()) .Select(i => i).OrderBy(o => o.Language).ToArray(); return(reslts); } }
public List <Movie> ReadCSVFile(string location) { try { using (var reader = new StreamReader(location, Encoding.Default)) { using (var csv = new CsvHelper.CsvReader(reader, System.Globalization.CultureInfo.CurrentCulture)) { csv.Configuration.RegisterClassMap <Moviesmap>(); var records = csv.GetRecords <Movie>().ToList(); return(records); } } } catch (Exception e) { throw new Exception(e.Message); } }
public List <MenuItem> CallAPI() { List <MenuItem> menuList; List <string> myStringColumn = new List <string>(); using (var fileReader = File.OpenText(inFile)) using (var csvResult = new CsvHelper.CsvReader(fileReader)) { while (csvResult.Read()) { string stringField = csvResult.GetField <string>("Header Name"); myStringColumn.Add(stringField); } } return(menuList); }
public IEnumerable <EmployeeDetails> Read() { var records = new List <EmployeeDetails>(); try { using (var csvReader = new CsvHelper.CsvReader(_textReader)) { csvReader.Configuration.HasHeaderRecord = true; records = csvReader.GetRecords <EmployeeDetails>().ToList(); } } catch (Exception ex) { _logger.Error(ex); throw; } return(records); }
private void Form1_Load(object sender, EventArgs e) { listView1.Visible = false; btnUpdate.Enabled = false; btnDelete.Enabled = false; if (!System.IO.File.Exists(Functions.bingPathToAppDir("\\data\\reminder.csv"))) { System.IO.FileStream f = System.IO.File.Create(Functions.bingPathToAppDir("\\data\\reminder.csv")); f.Close(); } using (var reader = new StreamReader(Functions.bingPathToAppDir("\\data\\reminder.csv"))) using (var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture)) { csv.Read(); csv.ReadHeader(); while (csv.Read()) { var record = new calender { username = csv.GetField("username"), type = csv.GetField("type"), note = csv.GetField("note"), date = csv.GetField("date"), clock = csv.GetField("clock") }; records.Add(record); } } listView1.Items.Clear(); foreach (var person in records) { if (Login.CurrentUser.Username == person.username) { var row = new string[] { person.type, person.note, person.date, person.clock }; var lvi = new ListViewItem(row); lvi.Tag = person; listView1.Items.Add(lvi); } } }
private void CloseCsvReader() { if (_csvReader != null) { _csvReader.Dispose(); _csvReader = null; } if (_streamReader != null) { _streamReader.Dispose(); _streamReader = null; } if (_pathOfStreamReader != null) { File.Delete(_pathOfStreamReader); _pathOfStreamReader = null; } }
private void Button2_Click(object sender, EventArgs e) { var filename = @"D:\temp\action_windows-6axis\action_data_1.csv"; StreamReader SRFile = new StreamReader(filename); var csv = new CsvHelper.CsvReader(SRFile, CultureInfo.InvariantCulture); var records = csv.GetRecords <SensorData>().ToList(); SRFile.Close(); //关闭文件 List <double> df = new List <double>(); foreach (var data in records) { df.AddRange(data.getSensorDataList()); } double[] df1 = df.ToArray(); //Console.WriteLine(df1.Length); var df2 = np.array(df1); Shape newshape = ((df1.Length / 43), 43); //Console.WriteLine((string)dad); var dataMat = df2.reshape(newshape); Console.WriteLine(dataMat.Shape); //Console.WriteLine((string)dataMat[":,-1"].reshape(-1,1)); int i = 0; while (i < dataMat.size) { i++; Console.WriteLine((string)dataMat[i]); if (i > 5) { break; } } }
private void FormPhoneBook_Load(object sender, EventArgs e) { if (!System.IO.File.Exists(Functions.bingPathToAppDir("\\data\\phonebook.csv"))) { System.IO.FileStream f = System.IO.File.Create(Functions.bingPathToAppDir("\\data\\phonebook.csv")); f.Close(); } // load recods from users csv file using (var reader = new StreamReader(Functions.bingPathToAppDir("\\data\\phonebook.csv"))) using (var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture)) { csv.Read(); csv.ReadHeader(); while (csv.Read()) { var record = new phonebook { name = csv.GetField("name"), surname = csv.GetField("surname"), phonenumber = csv.GetField("phonenumber"), address = csv.GetField("address"), description = csv.GetField("description"), email = csv.GetField("email"), user = csv.GetField("user") }; records.Add(record); } } listView1.Items.Clear(); foreach (var person in records) { if (Login.CurrentUser.Username == person.user) { var row = new string[] { person.name, person.surname, person.phonenumber, person.address, person.description, person.email }; var lvi = new ListViewItem(row); lvi.Tag = person; listView1.Items.Add(lvi); } } }
public static System.Data.DataTable Read(string FilePath) { List<string> headers = GetHeaderNames(FilePath); System.Data.DataTable table = GetEmptyDataTable(headers); System.Data.DataRow row; using (var fileReader = File.OpenText(FilePath)) using (var csvResult = new CsvHelper.CsvReader(fileReader)) { while (csvResult.Read()) { row = table.NewRow(); foreach (string s in headers) { row[s] = csvResult.GetField<string>(s); } table.Rows.Add(row); } } return table; }
public override ContentItem GetById(ValidUrl url_, ContentViewType viewType_) { //ContentItem item = _db.GetCollection<ContentItem>(COLLNAME).AsQueryable<ContentItem>().Where(x => x.Url.Id == url_.Id && x.ContentView.ViewType == viewType_).FirstOrDefault<ContentItem>(); ContentItem item = _db.GetCollection<ContentItem>(COLLNAME).Find(Query.And(Query.EQ("Url.Id", url_.Id), Query.EQ("ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault<ContentItem>(); if (item == null) { DependencyManager.Logger.Log(new LogEventInfo(LogLevel.Debug, ECMSSettings.DEFAULT_LOGGER, "Specific content not found now going to search for default content.")); item = _db.GetCollection<ContentItem>(COLLNAME).Find(Query.And(Query.EQ("ContentView.SiteId", url_.SiteId), Query.EQ("ContentView.ViewName", url_.View), Query.EQ("ContentView.ViewType", Convert.ToInt32(viewType_)))).FirstOrDefault<ContentItem>(); } //TODO : Optimize this if (item != null) { using (StringReader streamReader = new StringReader(item.Body[0].ToString())) { using (var csv = new CsvHelper.CsvReader(streamReader)) { //csv.Configuration.IgnoreQuotes = true; csv.Read(); item.Body = JObject.FromObject(csv.GetRecord(typeof(object))); } } } return item; }
public static void ReadAll_CsvHelper(DelimitedRecordReaderBenchmarkArguments args) { var config = new CH.Configuration.CsvConfiguration { BufferSize = args.BufferSize, AllowComments = true, IgnoreBlankLines = args.SkipEmptyLines, HasHeaderRecord = false, DetectColumnCountChanges = true, TrimFields = args.TrimWhiteSpaces, TrimHeaders = args.TrimWhiteSpaces }; using (var reader = new CH.CsvReader(new StreamReader(args.Path, args.Encoding, true, args.BufferSize), config)) { string s; if (args.FieldIndex < 0) { while (reader.Read()) { var record = reader.CurrentRecord; for (int i = 0; i < record.Length; i++) s = record[i]; } } else { while (reader.Read()) { for (int i = 0; i < args.FieldIndex + 1; i++) s = reader[i]; } } } }
private void PopulateCommandItems() { var fileName = @"C:\Users\Johandry.Amador\Documents\GitHub\ATK\Client\Visual Studio - C#\ATK\Properties\DataSources\Commands.csv"; var fileReader = File.OpenText(fileName); var csvReader = new CsvHelper.CsvReader(fileReader); while (csvReader.Read()) { CommandsList.Add(new Command() { ItemName = csvReader.CurrentRecord[3], ItemCommand = csvReader.CurrentRecord[0], ItemDescription = csvReader.CurrentRecord[4] }); } }