在这里,我有一个csv数据文件,每行8个字符串。我需要从csv中读取它,并通过ListView控件在屏幕上显示它。
我创建了一个List<string[]>
,用于将数据添加到ListView
控件中。而且我需要将数据从csv读取到List中。我使用的系统是工业HMI,它使用WinCE OS,供应商声称它完全支持.NET Compact Framework。
我遇到的问题是,当我使用File.ReadLines(path)
读取行格式的csv文件时,编译时发生错误,并且消息显示“ System.IO.File
”不包含“ ReadLines”的定义
我也尝试过StreamReader
,同样的问题。
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
using System.Collections.Generic;
using System.Reflection;
using System.Collections;
using System.IO;
using System.Linq;
public partial class dmScr
{
public List<string> file = new List<string>();
public List<string[]> inforead = new List<string[]>();
void fileload_Click(System.Object sender, System.EventArgs e)
{
string fileName = (CB_filelist.SelectedItem != null) ?
GetStorageCard() + CB_filelist.SelectedItem.ToString() :
"";
if(fileName != null && fileName != "")
{
fileRead(fileName);
}
LV_event.Items.Clear();
inforead.ForEach(x =>
{
ListViewItem lvi = new ListViewItem(x);
LV_event.Items.Add(lvi);
});
}
private void fileRead(string fileName)
{
foreach(string[] item in File.ReadLines(fileName))
inforead.Add(s);
}
}
}
工业HMI供应商是Beijer,如果您从事相关领域的工作会很熟悉。
答案 0 :(得分:3)
我不确定CE是否支持File.ReadLines
(不太确定,请不要在此引用我的意思)
但是StreamReader
有一个称为StreamReader.ReadLine
的方法
示例
using (StreamReader sr = new StreamReader(path))
{
while (sr.Peek() >= 0)
{
Console.WriteLine(sr.ReadLine());
}
}