在c#.net中读取文件 [英] read file in c# .net
本文介绍了在c#.net中读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨...
我正在Windows Mobile 7中开发一个应用程序,需要在其中读取文本文件.我为此编写了代码,但是当我调试该代码时,它给出了错误方法访问异常" .相同的代码在C#Windows窗体应用程序中工作.
我不知道这是什么问题.请为此建议我并解决此问题.我的代码是这样的:
Hi...
I am developing an app in windows mobile 7 in which I need to read a text file. I wrote a code for that but when I debug that code, it gives an error "method access exception". Same code is working in C# windows form app.
I dont know what is the problem. Please suggest me for this and solve this problem. My code is like this:
namespace fileread
{
public partial class MainPage : PhoneApplicationPage
{
private string line;
// Constructor
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
StreamReader sr = new StreamReader(@"D:\abc.txt");
line = sr.ReadLine();
MessageBox.Show(line);
}
在行上发生错误:"line = sr.ReadLine();"
Error occured at line: "line = sr.ReadLine();"
推荐答案
由于Windows vista的安全性,根目录是受保护的区域.这很可悲,但这是Windows中的保护级别.但这只是设计使然".
祝你好运!
The root directory is a protected area since windows vista for security. It''s pathetic, but this is the level of protection in windows. But this is simply "by design".
Good luck!
这篇关于在c#.net中读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文