473,385 Members | 1,326 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,385 software developers and data experts.

Folder level permissions using asp.net

111 100+
Hi,
I am developing an application in which a user can create folders and set the permission to the specific users. When the folder is screated at the first time no user should have permissions on the folder. But i found that all the users are able to access the folder.
How can I change the folder permissions using asp.net code. Thanks in advance.


Thanks & Regards
Bharath Reddy VasiReddy
Oct 27 '08 #1
1 2267
jg007
283 100+
This is some code that I was playing with, it is in vb.net but you might be able to convert it

it is not my tidiest code but it basically adds the current user to the ACL for a folder and sets ' administrators ' as the owner, I had some problems setting the owner before I gave permissions



Expand|Select|Wrap|Line Numbers
  1.  
  2. Imports System.IO
  3. Imports System.Security.Permissions
  4. Imports System.Security.Principal
  5.  
  6.  
  7. Public Class Form1
  8.  
  9.  
  10.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  11.         Dim self = System.Security.Principal.WindowsIdentity.GetCurrent()
  12.         Dim Rulz = New System.Security.AccessControl.FileSystemAccessRule(self.Name, System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow) ' create ACL 
  13.         Dim mydir As New DirectoryInfo("c:\test")
  14.         Dim vals As System.Security.AccessControl.FileSystemAccessRule
  15.         Dim x = mydir.GetAccessControl()
  16.         Dim permlists = x.GetAccessRules(True, True, GetType(System.Security.Principal.NTAccount))
  17.         Dim nt As New System.Security.Principal.NTAccount("", "Administrators")
  18.         Dim gr As System.Security.Principal.IdentityReference = nt
  19.  
  20.         Dim tempown = x.GetOwner(GetType(System.Security.Principal.NTAccount)) ' check current owner
  21.         MsgBox(tempown.Value)
  22.  
  23.         x.AddAccessRule(Rulz)  ' add ACL to X
  24.  
  25.         mydir.SetAccessControl(x) ' set access control oin folder using x
  26.  
  27.         x.SetOwner(nt) ' set owner for folder to administrators
  28.  
  29.         mydir.SetAccessControl(x) ' set access control oin folder using x
  30.  
  31.         Dim num As Integer = 0
  32.  
  33.         For Each vals In permlists ' check current permissions
  34.  
  35.             ListBox1.Items.Add(vals.IdentityReference.Value & " - " & vals.FileSystemRights.ToString)
  36.  
  37.              num += 1
  38.  
  39.         Next
  40.  
  41.  
  42.  
  43.     End Sub
  44. End Class
  45.  
  46.  
Oct 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: could ildg | last post by:
I want to check if a folder named "foldername" is empty. I use os.listdir(foldername)== to do this, but it will be very slow if the folder has a lot of sub-files. Is there any efficient ways to do...
0
by: Praveen | last post by:
Hello. I am writing some code that accepts a DFS Link and Username and grants that User permissions to the physical directory that the DFS Link corresponds to. I am using the System.Management...
7
by: Tom | last post by:
Can anyone give me any advice on how to secure a folder on a network server so that documents in the folder can only be opened through an Access database or by the database admin. I need to store...
2
by: | last post by:
Let me explain step wise. 1.. I have a site running on port 5555 2.. If contains web.config file with contains <Forms> authentication. 3.. The site contains a sub-folder named "MembersArea"...
6
by: Jeff | last post by:
Hi - I understand how to create a directory folder, but how can I programatically create a _shared_ directory folder and set its permissions?? (I'm using VB.NET.) Thanks for your help. -...
5
by: Mitchell S. Honnert | last post by:
Is there a way, given the full path of a folder on a network, that one can programatically tell if you have Read access to that folder? I have an application where the user is able to select a...
8
by: paquer | last post by:
Database Users need to have Read/Write etc... permissions to the folder where the Database resides in order to create the lock file. I have read only users. I have set up the Shortcut that links...
2
by: Thierry Kennes | last post by:
Hello, I'm trying to get the permissions on a shared folder using NetShareGetInfo api. I've got this function above that is supposed to give me the permission thanks to shi2_permission. The...
2
by: csharpula csharp | last post by:
Hello, I am trying to run a code which has an access to some folder that contains files and folders,the strange thing is that this folder becomes read only ,I change it before running the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.