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

Folder permissions in .NET

P: n/a
I have a folder on a local machine that has the access security
settings set in Windows so that only the administrator can perform
write or create operations on the folder. Everyone else is given read
only access to the folder.
I am trying to write a vb.net program that can create and modify files
and folders in the above mentioned folder. I am running into problems
with access permissions when I try to create a new sub-directory in the

folder because the users running the program do not have access to the
folder. I would like to give the vb.net program full and unrestricted
access to the folder without having to give the user that runs the
program the same access. Does anyone know how to do this in vb.net? I
can't have an administrator password box pop up in the program because
the users don't have the administrator password and I don't want them
to.

Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi,

Have you tried impersonation?

http://www.dotnet247.com/247referenc...28/144136.aspx
FileIOPermission
http://msdn.microsoft.com/library/de...sctorTopic.asp
Ken
--------------

"hiram" <oy*****@earthlink.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I have a folder on a local machine that has the access security
settings set in Windows so that only the administrator can perform
write or create operations on the folder. Everyone else is given read
only access to the folder.
I am trying to write a vb.net program that can create and modify files
and folders in the above mentioned folder. I am running into problems
with access permissions when I try to create a new sub-directory in the

folder because the users running the program do not have access to the
folder. I would like to give the vb.net program full and unrestricted
access to the folder without having to give the user that runs the
program the same access. Does anyone know how to do this in vb.net? I
can't have an administrator password box pop up in the program because
the users don't have the administrator password and I don't want them
to.
Nov 21 '05 #2

P: n/a
Try this:

Imports System.Security.Permissions

Dim strPath As String = "C:\MyPath"
Dim strSubDirectory As String = IO.Path.Combine(strPath,
"MySubDirectory")

Dim fp As New FileIOPermission(FileIOPermissionAccess.AllAccess,
strPath)
fp.Assert()
IO.Directory.CreateDirectory(strSubDirectory)
fp.RevertAssert()
fp = Nothing

Add the Dim fp... behind a button...

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #3

P: n/a
Thanks Ken,
The impersonation code at www.dotnet247.com solved the problem.

Nov 21 '05 #4

P: n/a
This code did not work for this problem. I had found this code on msdn
before during my search. I am not exactly sure what the
FileIOPermissionAccess class does. I do know that it will not allow me
to access a directory that I don't already have permissions on.

Thanks for the suggestion.

Nov 21 '05 #5

P: n/a
Its always worked for me in the situation you described. Yes, of course
impersonating the administrator is used to, but in my experience I've seen
it used more in web applications rather than Windows progs.

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.