使用vb.net读取行数

chi*_*nnu 2 vb.net

如何计算没有.我们上传的文件中的行可能是文本文件,也可能是csv或excel文件.我使用代码获取记录计数如下:

Dim FileCount = From lin1 As String In File.ReadAllLines(hidFilePath.Value.ToString())
Let dd = lin1.Count
Select dd
Dim file_count As Integer =  FileCount.Count
Run Code Online (Sandbox Code Playgroud)

但在某些情况下,我的错误计数.它没有显示确切的数量.

请帮助,我应该能够得到计数而不循环文件中的每个记录.

谢谢.

RB.*_*RB. 6

ReadAllLines 返回一个字符串数组,因此您可以简单地获取数组的长度.

Dim file_count As Integer = _
    File.ReadAllLines(hidFilePath.Value.ToString()).Length
Run Code Online (Sandbox Code Playgroud)