Look at the link
TextFieldParseris in the namespace Microsoft.VisualBasic.FileIO. Therefore, you need to add a link toMicrosoft.VisualBasic.dll
String path = @"D:\CSV\data.csv";
using (TextFieldParser parser = new TextFieldParser(path))
{
parser.SetDelimiters(new string[] { "," });
parser.HasFieldsEnclosedInQuotes = true;
while (!parser.EndOfData)
{
string[] fields = parser.ReadFields();
column1 = fields[0];
column2 = fields[1];
column3 = int.Parse(fields[2]);
column4 = double.Parse(fields[3]);
}
}
I suggest you upload the file to a temporary location, and then use the temp file path to analyze the CSV.
, ResponseStream
:
String ftpserver = "ftp://ftp.atozfdc.com.au/data.csv";
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpserver));
reqFTP.UsePassive = false;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential("username", "password");
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream responseStream = response.GetResponseStream();
using (TextFieldParser parser = new TextFieldParser(responseStream))
{
}
responseStream.Close();
response.Close();