文件访问权限 [英] File Access Permission

查看:137
本文介绍了文件访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试打开我在项目解决方案目录中的目录中创建的标准文本文件,并且收到UnauthorizedAccessException.该应用程序被设置为完全信任的应用程序.我正在通过文件的完整路径(包括驱动器号)访问文件,并且在StreamReader的构造函数中生成了异常.文件夹上的权限是从根驱动器继承的,并且所有者/创建者具有完全的读/写权限.

我知道我应该阅读.NET安全性的完整内容,但这是一个快速而又肮脏的测试应用程序,我的截止日期非常紧迫.我希望我做的事情明显不对.

非常感谢收到任何想法.

帕特里克···
代码如下:

private void buttonDrawGraph_Click( object sender, EventArgs e )
{
	char[] splitCharacter = new char[] { '','' };
	try
	{
		using ( StreamReader textFileReader = new StreamReader( @"D:\Dev\Projects\DLP\DLP\data" ) )
		{
			while ( ( string oneLine = textFileReader.ReadLine() ) != null ) 
					{
					}
		}
	}
	catch ( System.IO.FileNotFoundException ) 
	{
		MessageBox.Show( "Could not open file ''" + textBoxDataFile.Text + "''" );
	}
}



解决方案

它可能与安全性无关.

当操作系统由于 I/O 错误或 security 错误而拒绝访问时,将引发UnauthorizedAccessException异常."

Patrick Skelton写道:

我知道我应该阅读.NET安全性的完整内容,但这是一种快速而又肮脏的方法测试应用程序,我的申请期限很紧.



没有足够的时间来正确地做它. :rolleyes:

Patrick Skelton写道:

我希望我做的事情明显不对.



由于您未提供任何代码以供审核,因此很难确定现在不这样做.但是,既然您说它不起作用,那么是的,您显然做错了.


Doh-非常抱歉.愚蠢的错误.代码试图打开目录,而不是目录中的文件.

猜猜我需要放慢脚步,停止像无头鸡一样奔跑.

抱歉,如果我浪费了任何人的时间.

-帕特里克


Hi,

I am trying to open a standard text file that I have created in a directory within the project solution directory and I get an UnauthorizedAccessException. The application is set to be a full-trust application. I am accessing the file by its full path, including the drive letter), and the exception is being generated in the constructor of a StreamReader. The permissions on the folder are inherited from the root drive and Owner/Creator has full read/write permission.

I know I should read the complete ins-and-outs of .NET security, but this is a quick-and-dirty test application and I am on a very tight deadline. I am hoping I am doing something obvious wrong.

Any ideas very gratefully received.

Best wishes, Patrick

The code is as follows:

private void buttonDrawGraph_Click( object sender, EventArgs e )
{
	char[] splitCharacter = new char[] { '','' };
	try
	{
		using ( StreamReader textFileReader = new StreamReader( @"D:\Dev\Projects\DLP\DLP\data" ) )
		{
			while ( ( string oneLine = textFileReader.ReadLine() ) != null ) 
					{
					}
		}
	}
	catch ( System.IO.FileNotFoundException ) 
	{
		MessageBox.Show( "Could not open file ''" + textBoxDataFile.Text + "''" );
	}
}



The line where the StreamReader is created causes the exception.

解决方案

It may not be security related.

"An UnauthorizedAccessException exception is thrown when the operating system denies access because of an I/O error or a security error."

Patrick Skelton wrote:

I know I should read the complete ins-and-outs of .NET security, but this is a quick-and-dirty test application and I am on a very tight deadline.



Never enough time to do it right. :rolleyes:

Patrick Skelton wrote:

I am hoping I am doing something obvious wrong.



Since you have provided no code for review it would be difficult to determine that now wouldn''t it. However, since you say it isn''t working, then yes you have obviously done something wrong.


Doh - very sorry. Stupid mistake. The code was trying to open a directory and not a file within the directory.

Guess I need to slow down and stop running round like a headless chicken.

Sorry if I have wasted anyone''s time.

-Patrick


这篇关于文件访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆