Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to set/change folder permission in VB .NET 3.5

Posted on 2008-06-24
4
Medium Priority
?
4,213 Views
Last Modified: 2013-11-26
Hi,

I am trying to change a folder (and all its sub folders and files) permission in Visual studio 2008 and VB .Net 3.5. Also I can not use windows AD as it is not implemented.

What is the best way to do this?

I have looked around and there is some information about setting file/folder permissions s but its all older stuff and I hear there is new way to do this in VS 2008. But I can not find it.

What I want to do it change a folder (and all files and sub files) permission to full access do stuff and then change it to read only and execute.

I am doing this using Visual Basic and .NET 3.5.

Thanks


0
Comment
Question by:soousky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 11

Accepted Solution

by:
melmers earned 500 total points
ID: 21872083
Hi,

you can do this with .NET 2.0 functions.
Here an example to set the folder Permissions

I hope this helps

 
 'Needed imports
 Imports System.Security.AccessControl
 Imports System.IO
 
 'Code snippet
 Dim CurrentPath as String = "C:\TestPath"
 Dim UserName as String = "DOMAIN\MyUser" 
 
 Dim dInfo As New DirectoryInfo(CurrentPath)
 Dim dSecInfo As DirectorySecurity = dInfo.GetAccessControl(AccessControlSections.Access)
 Dim myRuleValue As Integer = 0
 
 myRuleValue =  FileSystemRights.FullControl   'Add your wanted Access here
 Dim myRule as FileSystemAccessRule
 myRule = New FileSystemAccessRule(UserName myRuleValue, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit Or InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow)
 dSecInfo.AddAccessRule(myRule)
 dSecInfo.SetAccessRule(myRule)
 dInfo.SetAccessControl(dSecInfo)

Open in new window

0
 

Author Closing Comment

by:soousky
ID: 31470411
Thanks
0
 
LVL 3

Expert Comment

by:IUFITS
ID: 23983074
Good code, just one comment, this line needs to have a comma after UserName:
myRule = New FileSystemAccessRule(UserName myRuleValue, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit Or InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow)
dSecInfo.AddAccessRule(myRule)
dSecInfo.SetAccessRule(myRule)
dInfo.SetAccessControl(dSecInfo)
Open in New Window Select All
0
 

Expert Comment

by:coolneip
ID: 35436335
This worked great!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question