English 中文(简体)
在NET中,核对现有用户可能写给名录
原标题:In .NET, check that the current user may write to a directory

In .NET, is there a simple way to check whether the current user has access to create a file in a directory? Something equivalent to the C++ _access function, would be ideal.

我不想使用审判和错误(重弹档案,然后删除):除了看似黑客外,其他软件正在监测该目录,以便存档。

我不想使用系统。 名录服务:研究异常低价证券,解决集团成员问题,以及不同集团成员的许可如何相互作用,似乎容易发生,也过于困难。 必须在某个地方、没有的地方发挥“是”或“纳伊”的作用?

提前感谢!

[edit] as a bonus, if it would work for a network share as well, that d be cool.

最佳回答
FileIOPermission writePermission = new FileIOPermission(FileIOPermissionAccess.Write, filename);
if (SecurityManager.IsGranted(writePermission)){
    //write here
} else {
    //some error message
}
问题回答

预先检查许可是一个临时项目。 更不用说是复杂的,通过整个《欧洲刑法》清单计算,并计算有效的许可。

此外,没有保障。 仅仅因为你事先主动检查许可,并不意味着在你试图创建档案的时候,所赢得的许可就发生了变化。

,要么与Demand();否则,该电话就投下了 SecurityException,而你则需要追捕和采取行动。

根据我的经验,必要的检查比较容易。

还应当指出的是,在Windows 7,虽然在概念上你可以书写查阅名录,但除非你经高额许可重新运行,否则仍然无法工作。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签