2010-03-04 18 views
2

我有一个功能ParseHtmlTable(字符串htmlContent)怎么办。我读的文件内容和发送这些内容到功能参数

现在在那个函数中我想传递html文件的内容。现在我可以通过只写文件名的路径来实现。然后我必须读取该文件。但是我不知道如何读取这个文件?

那么如何打开特定的文件并读取文件的内容并将这些内容发送给函数的参数呢?

编辑: System.IO.File.ReadAllText(路径)可以读取所有的HTML文件,但没有一个文件,我有它不通过这个function.What读的原因是可以有?对此,解决方案有哪些?

回答

4

您是否尝试过使用

string s = System.IO.File.ReadAllText(path); 

File.ReadAllText Method (String)

编辑评论

要itterate在目录中的文件,你最多可以尝试使用Directory.GetFiles Method (String)

foreach (string filename in Directory.GetFiles(path)) 
{ 
    //do what you need here 
} 
+1

拉德班级系统.IO.Directory。 – 2010-03-04 06:16:06

+0

我以前没有和** agilityPack **一起工作过,但我个人不会尝试使用正则表达式来解析html ... http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu- way.html – 2010-03-04 06:24:37

+0

http://stackoverflow.com/questions/100358/looking-for-c-html-parser – 2010-03-04 06:26:31