/// <summary>
 /// Assumes UTF8 encoding.
 /// </summary>
 private static DataTable LoadCsvIntoTable(string path)
 {
     using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
     {
         var csv = new CsvHelper();
         csv.Read(stream, Encoding.UTF8);
         return csv.Table;
     }
 }
Example #2
0
        private static UploadModel CreateTableFromCsvFile(FileUpload upload)
        {
            var model = new UploadModel();

            if (!upload.HasFile)
            {
                model.Error = "Please select a file to upload.";
                model.Table = null;
            }
            else
            {
                var csv = new CsvHelper();
                csv.Read(upload.PostedFile.InputStream, Encoding.UTF8);

                if (!csv.Table.Columns.Contains("Principal"))
                    model.Error = "Missing Column: Principal";

                if (!csv.Table.Columns.Contains("Operation"))
                    model.Error = "Missing Column: Operation";

                if (!csv.Table.Columns.Contains("Resource"))
                    model.Error = "Missing Column: Resource";

                if (csv.Table.Rows.Count > MaximumRowCount)
                    model.Error = string.Format("This test harness is intended for small data sets only. Please limit the size of your file to {0} rows or less.", MaximumRowCount);

                model.Table = csv.Table;
            }

            return model;
        }