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

find whether a folder has read/write permission?

Hi,

I need to write some code to test whether a folder has read/write
permission. The idea is to try to read sub-directories in this folder,
if succeed, then test whether it's read-only. Any exception thrown means
we don't have permission to access this folder:

bool IsDirectoryAccessible(string path)
{
try
{
bool retVal = false;
System::IO::DirectoryInfo* dirInfo = new
System::IO::DirectoryInfo(Marshal::ToString(path)) ;

dirInfo->GetDirectories();
// GetDirectories() throw Exception if the folder is not accessible

if(IsReadOnly(path))
retVal = true;

return retVal;
}
catch (System::Exception* ex)
{
Util::Managed::Rethrow(ex);
}
}

But I think this algorithm is not so straight-forward. Anyone have
better idea of testing the folder accessibility?

Thanks a lot
Nov 17 '05 #1
2 5670
Take a look at the FileIOPermission class.

Also, if you need some examples in C++, you might need to try another group.

"Chen Zhuo" <ch*********@hotmail.com> wrote in message
news:es**************@TK2MSFTNGP12.phx.gbl...
Hi,

I need to write some code to test whether a folder has read/write
permission. The idea is to try to read sub-directories in this folder,
if succeed, then test whether it's read-only. Any exception thrown means
we don't have permission to access this folder:

bool IsDirectoryAccessible(string path)
{
try
{
bool retVal = false;
System::IO::DirectoryInfo* dirInfo = new
System::IO::DirectoryInfo(Marshal::ToString(path)) ;

dirInfo->GetDirectories();
// GetDirectories() throw Exception if the folder is not accessible

if(IsReadOnly(path))
retVal = true;

return retVal;
}
catch (System::Exception* ex)
{
Util::Managed::Rethrow(ex);
}
}

But I think this algorithm is not so straight-forward. Anyone have
better idea of testing the folder accessibility?

Thanks a lot

Nov 17 '05 #2
Thanks.. but still not sure how to get the current user's permission of
the specified folder? Could you give me some code segment?
Thanks ya

Btw, seems that GetDirectories() is too powerful... even I set C:\test
to be non-access to anyone, this API still can get the sub directories
under it!...
Peter Rilling wrote:
Take a look at the FileIOPermission class.

Also, if you need some examples in C++, you might need to try another group.

"Chen Zhuo" <ch*********@hotmail.com> wrote in message
news:es**************@TK2MSFTNGP12.phx.gbl...
Hi,

I need to write some code to test whether a folder has read/write
permission. The idea is to try to read sub-directories in this folder,
if succeed, then test whether it's read-only. Any exception thrown means
we don't have permission to access this folder:

bool IsDirectoryAccessible(string path)
{
try
{
bool retVal = false;
System::IO::DirectoryInfo* dirInfo = new
System::IO::DirectoryInfo(Marshal::ToString(path ));

dirInfo->GetDirectories();
// GetDirectories() throw Exception if the folder is not accessible

if(IsReadOnly(path))
retVal = true;

return retVal;
}
catch (System::Exception* ex)
{
Util::Managed::Rethrow(ex);
}
}

But I think this algorithm is not so straight-forward. Anyone have
better idea of testing the folder accessibility?

Thanks a lot


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Dalberg | last post by:
How can I enable "list folder contents" ntfs permission only programmatically? The docs for cacls and xcalcs do not have an example to set this up without setting up the other read permissions. ...
0
by: Samuel Shum | last post by:
Hello, I'm just wondering how I could set files and folders permission with VB.NET? I find there is a class "system.security.permissions" which seems to do the job but the samples are pretty...
2
by: Urs Eichmann | last post by:
We're developing a standard software application (ASP.NET) which will run on servers of various ISP in a shared/hosted environment. With the ISP I usually work with it is no problem to get a folder...
1
by: Alessandro Zucchi | last post by:
Hi all, I'm developing a ASP.Net application. The most important future is to generate PDF files that MUST BE saved on the disk (of the server). To achieve this goal I set write permission on...
4
by: Santaji | last post by:
Hi, We have an ASP.NET application which needs to write some files on the disk. For these we need to give ASP.NET user the Write permission for that particular folder. This is possible from...
0
by: Ashraf Moollan www.ssw.com.au | last post by:
Dear all, I am trying to read all the users permissions for a particular folder. E.g Everyone: Read Only Administrator: Full Control Guest: Read, Write or Something similar.
0
by: Sanja Tanasijevic | last post by:
I have serious problem setting read/write privilegues to the folder for customers upload files and photos including possibilities to read them too. Version of IIS is 5.1 and I set up this folder in...
2
by: Bill Fallon | last post by:
I have a VS2005 VB.Net windows form application deployed to a share drive. The windows explorer security permissions for this application (.exe) file is set for Everyone with List Folder/Read Data...
0
by: sureshkmsc | last post by:
I don't know. how to set the read/write permissions in database how to set the read/write permission.
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.