Solved

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

Posted on 2008-06-24
4
4,206 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 125 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Format Transaction Number 19 49
Check only one toolstripmenu item 12 60
.Net remove carriage returns, line feeds and tabbs 5 36
Data Analysis 7 59
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

732 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