By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,910 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,910 IT Pros & Developers. It's quick & easy.

create shared new directory

P: n/a
I need to create a folder in code, and also set sharing to being shared to
everyone with full control (or some such variation of security)

What I'm doing now is:

If Not System.IO.Directory.Exists(My.Application.Info.Dir ectoryPath &
"\NewTestFolder") Then

System.IO.Directory.CreateDirectory(My.Application .Info.DirectoryPath &

End If

It appears there is a second parameter to the .CreateDirectory method, but
the type of "directorysecurity" which definitely sounds promising, but
trying to determine how to use this is proving a bit of a challenge.
Apr 7 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Hi Matt ,

If you want to configure the DACL of the directory to allow everyone on
your machine to full control this folder, then you are looking at the
correct parameter. The "DirectorySecurity Class" below contains the sample
code regarding how to setup the DirectorySecurity object:

The link below also contains some ACL programming stuff:
"How To Program ACLs"

However, if you want to share this directory with others from remote
computer through LAN file share, there is another story.

In file share, there are 2 stages of access check: DACL access check and
file share permission check. Only account authentication can pass these 2
permission sets stages, can it successfully access the shared files.

Sharing Permission set can be configured through "Permissions" button in
"Sharing" tabpage in folder property dialog, while NTFS DACL Permission set
can be configured through button in "Security" tabpage in folder property

..Net contains build-in support to configure the DACL permission of
directories/files and I have shown you the sample code snippet in the first
paragraph. To configure the share permission, there is no build-in support.
We have to p/invoke NetUseAdd Win32 API for this task. My original reply
below and the codeproject article demonstrates this idea with code snippet
in C#:
"How to create a file share using .NET framework"

Finally, the article below contains very detaild ACL programming in
..Net2.0, it should be informative if you are curious about security
programming in .Net:

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
Get notification to my posts through email? Please refer to

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 9 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.