The code that I have listed here works when I ReadAllText from a local file. What I need to be able to do is replace the path "C:\LocalFiles\myFile.csv" with "https://mySite.blah/myFile.csv".
I have tried several methods, but can't seem to be able to get the csv file loaded into a string variable. If I could just do that, then the code would work for me.
var csv = System.IO.File.ReadAllText(@"C:\LocalFiles\myFile.csv");
StringBuilder sb = new StringBuilder();
using (var p = ChoCSVReader.LoadText(csv).WithFirstLineHeader())
{
p.Configuration.NullValue = null;
if (p.Configuration.CSVRecordFieldConfigurations.IsNullOrEmpty())
{
p.Configuration.NullValue = null;
}
// ChoIgnoreFieldValueMode.DBNull = ChoIgnoreFieldValueMode.Empty();
using (var w = new ChoJSONWriter(sb))
w.Write(p);
}
string fullJson = sb.ToString();
If I simply replace the path, I get an error message that says that the path is invalid.
You need to get the string using a web request:
or using a Webclient:
Then pass
data
into your reader instead of using theSystem.IO.File.ReadAllText(@"C:\LocalFiles\myFile.csv");
Both of the above examples assume that the file is publicly accessible at that url without authentication or specific header values.