473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How check is app has file write security permissions?

Is there an easy way to check using .NET 2.0?

Thanks in advance,

-Ed
Sep 28 '06 #1
4 5722
Hi,

Ed Sutton wrote:
Is there an easy way to check using .NET 2.0?

Thanks in advance,

-Ed
Try to write, and catch the Exception.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Sep 28 '06 #2
|I answer to my own question, I wrote the following which does what I
needed.
/// <summary>
/// Returns true if specified identity name has the file system
rights for the specified file
/// </summary>
private static bool IdentityHasAccces(string identityName,
FileInfo fileInfo,
FileSystemRights
fileSystemRights)
{
identityName = identityName.ToUpper();
AuthorizationRuleCollection authorizationRuleCollection =
fileInfo.GetAccessControl().GetAccessRules(true, true,
typeof(NTAccount));
foreach (FileSystemAccessRule fileSystemAccessRule in
authorizationRuleCollection)
{
if (identityName ==
fileSystemAccessRule.IdentityReference.Value.ToUpp er())
{
return AccessControlType.Allow ==
fileSystemAccessRule.AccessControlType &&
fileSystemRights ==
(fileSystemAccessRule.FileSystemRights & fileSystemRights);
}
}
return false;
}
if (false ==
IdentityHasAccces(System.Security.Principal.Window sIdentity.GetCurrent().Name,

dbFileInfo,
FileSystemRights.Read | FileSystemRights.Write))
{
return;
}
|
Sep 29 '06 #3
Hi Laurent,

Thank you for your reply.
Try to write, and catch the Exception.
Good idea, that would have been much easier. I ended up writing a lot
of code using the following method:
/// <summary>
/// Returns true if specified identity name has the file system
/// rights for the specified file
/// </summary>
private static bool IdentityHasAccces(string identityName,
FileInfo fileInfo,
FileSystemRights
fileSystemRights)
{
identityName = identityName.ToUpper();
AuthorizationRuleCollection authorizationRuleCollection =
fileInfo.GetAccessControl().GetAccessRules(true,
true,typeof(NTAccount));

foreach (FileSystemAccessRule fileSystemAccessRule in
authorizationRuleCollection)
{
if (identityName ==
fileSystemAccessRule.IdentityReference.Value.ToUpp er())
{
return AccessControlType.Allow ==
fileSystemAccessRule.AccessControlType && fileSystemRights
==(fileSystemAccessRule.FileSystemRights & fileSystemRights);
}
}
return false;
}

Example Usage:
--------------

if (false ==
IdentityHasAccces(System.Security.Principal.Window sIdentity.GetCurrent().Name,
dbFileInfo,
FileSystemRights.Read | FileSystemRights.Write))
{
return;
}

Oct 3 '06 #4
Hi,

Ed Sutton wrote:
Hi Laurent,

Thank you for your reply.
>Try to write, and catch the Exception.


Good idea, that would have been much easier. I ended up writing a lot
of code using the following method:
When did you get my message on your newsreader? I replied on the 28th of
Sept, 10 minutes after you posted. One day later you posted again in the
same thread, giving no indication that you had read my post. Maybe you
should consider using a different provider if my post showed late. It
would have saved you from writing the long code :-)

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
I have seen the posts on various places on the internet about .NET framework mismatch issues and I don't think that is my problem. ; ) When I execute the following C++.NET code: String...
3
by: walid | last post by:
Hi all, I was wondering if anybody knows why Image.save(pathstring) is allowed in ASP.net without any security permissions . the user can create an image and save it in the web page directory,...
12
by: Mark | last post by:
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...
0
by: paul | last post by:
I just installed Windows XP SP2 on my web server. Now when I run one of the web applications I get the following error: ArgumentException: Illegal characters in path.] ...
8
by: Bryan Dickerson | last post by:
The full message is: Request for permission of the type 'System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. ...
1
by: hames.bond | last post by:
G'day, I have 2 Win2K servers, 1 is my database server, 1 runs IIS On the IIS machine I have an ASP.NET 2 application that makes a call to a proprietry 3rd party COM Object/DLL that makes a...
1
by: jmurphy95 | last post by:
Hi there, I have a Windows application that I'm running from a shared drive that needs to access file/directory resources on other drives. I've done a lot of reading, but a lot of the material...
6
by: alex | last post by:
Hi, this always works: private ConsoleToTextbox myConsole; Console.SetOut(myConsole); But now (a few weeks later i started this project again) i get a non handeld security exception from...
3
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.