用于创建文件的安全权限 [英] security permissions for creating a file

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

问题描述

你好,


在一个简单的控制台应用程序中我尝试用以下代码创建一个文件:


FileStream file = new FileStream (" test.txt",FileMode.OpenOrCreate,

FileAccess.Write);

StreamWriter sw = new StreamWriter(file);

sw.Write(" Hello");

sw.Close();

file.Close();


我将得到一个错误System.Security.SecurityException


是否只有一种方法可以避免这种情况以及如何做到这一点?


谢谢并且问候

马克

Hello,

in a simple console application I try to create a file with some code like:

FileStream file = new FileStream("test.txt", FileMode.OpenOrCreate,
FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.Write("Hello");
sw.Close();
file.Close();

I will get an error System.Security.SecurityException

Are there only one way to avoid this and how this can be done?

Thanks and regards
Mark

推荐答案

马克,


你得到这个例外因为您没有权利在其设置的目录中创建或打开

文件。您需要尝试在目录中创建

文件您有权使用,或者,如果该文件存在,请检查

文件的权利,以确保您可以打开它进行写作。

希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Mark" <钪******** @ gmx.net>在消息中写道

news:dc ************* @ news.t-online.com ...
Mark,

You get this exception because you don''t have rights to create or open
the file in the directory that it is set in. You need to try and create the
file in a directory that you have rights to, or, if the file exists, check
the rights on the file to make sure that you can open it for writing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
你好,
FileStream file = new FileStream(" test.txt",FileMode.OpenOrCreate , FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.Write(" Hello");
sw.Close();
file.Close();

我会收到错误System.Security.SecurityException

是否只有一种方法可以避免这种情况以及如何做到这一点?

感谢和问候
Mark
Hello,

in a simple console application I try to create a file with some code
like:

FileStream file = new FileStream("test.txt", FileMode.OpenOrCreate,
FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.Write("Hello");
sw.Close();
file.Close();

I will get an error System.Security.SecurityException

Are there only one way to avoid this and how this can be done?

Thanks and regards
Mark



嗨尼古拉斯,

我尝试了一个控制台应用程序,作为管理员,我在任何

目录中都没有限制。


关于Mark


Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com> schrieb

im Newsbeitrag新闻:es ************** @ tk2msftngp13.phx.gbl ...
Hi Nicholas,

I tried a console application and as admin I have no restriction in any
directory.

regards Mark

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
Mark,
你得到了这个例外,因为你没有权利在它设置的目录中创建或打开文件。你需要尝试在文件中创建
您有权访问的目录,或者,如果该文件存在,请检查文件上的权限,以确保您可以打开它进行写作。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv * @ spam。 guard.caspershouse.com

标记 <钪******** @ gmx.net>在消息中写道
新闻:dc ************* @ news.t-online.com ...
Mark,

You get this exception because you don''t have rights to create or open
the file in the directory that it is set in. You need to try and create the file in a directory that you have rights to, or, if the file exists, check
the rights on the file to make sure that you can open it for writing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
你好,

FileStream file = new FileStream(" test.txt",FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.Write(" Hello");
sw.Close();
file.Close ();

我会得到一个错误System.Security.SecurityException

是否只有一种方法可以避免这种情况以及如何做到这一点?
Mark
Hello,

in a simple console application I try to create a file with some code
like:

FileStream file = new FileStream("test.txt", FileMode.OpenOrCreate,
FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.Write("Hello");
sw.Close();
file.Close();

I will get an error System.Security.SecurityException

Are there only one way to avoid this and how this can be done?

Thanks and regards
Mark




您确定安全例外是否适用于然后打开文件?

从哪里加载应用程序?你是从网络运行它吗?b $ b股票还是互联网?如果是这样,那么应用程序将被授予

a有限权限设置。

-

- Nicholas Paldino [.NET / C#MVP ]

- mv*@spam.guard.caspershouse.com

" Mark" <钪******** @ gmx.net>在消息中写道

news:dc ************* @ news.t-online.com ...
Are you sure that the security exception is for opening the file then?
Where is the application loaded from? Are you running it from a network
share, or the internet? If so, then the application is going to be granted
a limited permission set.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
嗨尼古拉斯,

我尝试了一个控制台应用程序,作为管理员,我对任何
目录没有任何限制。

关于Mark

Nicholas Paldino [ .NET / C#MVP]" < mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag新闻:es ************** @ tk2msftngp13.phx.gbl ...
Hi Nicholas,

I tried a console application and as admin I have no restriction in any
directory.

regards Mark

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
Mark,
您得到此例外是因为您无权在其设置的目录中创建或打开该文件。您需要尝试创建
Mark,

You get this exception because you don''t have rights to create or
open
the file in the directory that it is set in. You need to try and create


文件位于您有权访问的目录中,或者,如果文件存在,则检查
文件的权限以确保您可以将其打开以进行写入。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com

标记 <钪******** @ gmx.net>在消息中写道
新闻:dc ************* @ news.t-online.com ...
file in a directory that you have rights to, or, if the file exists,
check
the rights on the file to make sure that you can open it for writing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
>你好,
>
>在一个简单的控制台应用程序中,我尝试使用一些代码创建一个文件
>喜欢:
>
> FileStream file = new FileStream(" test.txt",FileMode.OpenOrCreate,
> FileAccess.Write);
> StreamWriter sw = new StreamWriter(file);
> sw.Write(" Hello");
> sw.Close();
> file.Close();
>
>我将收到一个错误System.Security.SecurityException
>
>是否只有一种方法可以避免这种情况以及如何做到这一点?
>
>谢谢和问候
>马克
>
>
> Hello,
>
> in a simple console application I try to create a file with some code
> like:
>
> FileStream file = new FileStream("test.txt", FileMode.OpenOrCreate,
> FileAccess.Write);
> StreamWriter sw = new StreamWriter(file);
> sw.Write("Hello");
> sw.Close();
> file.Close();
>
> I will get an error System.Security.SecurityException
>
> Are there only one way to avoid this and how this can be done?
>
> Thanks and regards
> Mark
>
>





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

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