473,785 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FileIOPermissio n question

Hi NG !
I have the following piece of code below. the first try/catch part
would return true although I do not have permission to access this
computer. The second try/catch part would return false.
Do I misunderstand the meaning of FileIOPermissio n ?
From MSDN: "Controls the ability to access files and folders"

???
Thanks for education!
Regards Marcel (Schaf)

private bool _HasRemoteAcces s() {
string sRemotePath = @"\\192.168.2.2 \C$\Temp\Text.t xt";
bool bHasAccess = true;

//returns true
try {
FileIOPermissio n permission = new
FileIOPermissio n(FileIOPermiss ionAccess.Write , sRemotePath);
permission.Dema nd();
} catch (System.Securit y.SecurityExcep tion se) {
bHasAccess = false;
}

//returns false
try {
string[] sRemoteFiles = Directory.GetFi les(sRemotePath );
} catch (Exception e) {
bHasAccess = false;
}
return bHasAccess;
}

Jun 22 '06 #1
6 2476
Hi,

What if you do a Console.Write( e.Message ) ?

It will give you the exact problem with the GetFiles method
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"schaf" <sc***@2wire.ch > wrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Hi NG !
I have the following piece of code below. the first try/catch part
would return true although I do not have permission to access this
computer. The second try/catch part would return false.
Do I misunderstand the meaning of FileIOPermissio n ?
From MSDN: "Controls the ability to access files and folders"

???
Thanks for education!
Regards Marcel (Schaf)

private bool _HasRemoteAcces s() {
string sRemotePath = @"\\192.168.2.2 \C$\Temp\Text.t xt";
bool bHasAccess = true;

//returns true
try {
FileIOPermissio n permission = new
FileIOPermissio n(FileIOPermiss ionAccess.Write , sRemotePath);
permission.Dema nd();
} catch (System.Securit y.SecurityExcep tion se) {
bHasAccess = false;
}

//returns false
try {
string[] sRemoteFiles = Directory.GetFi les(sRemotePath );
} catch (Exception e) {
bHasAccess = false;
}
return bHasAccess;
}

Jun 22 '06 #2

Hi!
What if you do a Console.Write( e.Message ) ?

It will give you the exact problem with the GetFiles method
I do not have problems with the second try and catch, because this acts
like I expect, but the first one should give me a SecurityExcepti on
because I have no permission to access the files on this computer. So
to conclude if I test the file access with the FileIOPermissio n class,
I get the wrong result. But why ?

Regrads
Marcel


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"schaf" <sc***@2wire.ch > wrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Hi NG !
I have the following piece of code below. the first try/catch part
would return true although I do not have permission to access this
computer. The second try/catch part would return false.
Do I misunderstand the meaning of FileIOPermissio n ?
From MSDN: "Controls the ability to access files and folders"

???
Thanks for education!
Regards Marcel (Schaf)

private bool _HasRemoteAcces s() {
string sRemotePath = @"\\192.168.2.2 \C$\Temp\Text.t xt";
bool bHasAccess = true;

//returns true
try {
FileIOPermissio n permission = new
FileIOPermissio n(FileIOPermiss ionAccess.Write , sRemotePath);
permission.Dema nd();
} catch (System.Securit y.SecurityExcep tion se) {
bHasAccess = false;
}

//returns false
try {
string[] sRemoteFiles = Directory.GetFi les(sRemotePath );
} catch (Exception e) {
bHasAccess = false;
}
return bHasAccess;
}


Jun 23 '06 #3
schaf wrote:

Hi!
What if you do a Console.Write( e.Message ) ?

It will give you the exact problem with the GetFiles method


I do not have problems with the second try and catch, because this acts
like I expect, but the first one should give me a SecurityExcepti on
because I have no permission to access the files on this computer. So
to conclude if I test the file access with the FileIOPermissio n class,
I get the wrong result. But why ?

Regrads
Marcel


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"schaf" <sc***@2wire.ch > wrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
> Hi NG !
> I have the following piece of code below. the first try/catch part
> would return true although I do not have permission to access this
> computer. The second try/catch part would return false.
> Do I misunderstand the meaning of FileIOPermissio n ?
>>From MSDN: "Controls the ability to access files and folders"
> ???
> Thanks for education!
> Regards Marcel (Schaf)
>
> private bool _HasRemoteAcces s() {
> string sRemotePath = @"\\192.168.2.2 \C$\Temp\Text.t xt";
> bool bHasAccess = true;
>
> //returns true
> try {
> FileIOPermissio n permission = new
> FileIOPermissio n(FileIOPermiss ionAccess.Write , sRemotePath);
> permission.Dema nd();
> } catch (System.Securit y.SecurityExcep tion se) {
> bHasAccess = false;
> }
>
> //returns false
> try {
> string[] sRemoteFiles = Directory.GetFi les(sRemotePath );
> } catch (Exception e) {
> bHasAccess = false;
> }
> return bHasAccess;
> }
>


Hi Schaf,

If you inspect the exception that is occurring in the second try...catch
block, you may be surprised. From what I can see, you are trying to call
Directory.GetFi les() on a file. You've defined sRemotePath to be a file,
i.e. "test.txt" and you are using Directory.GetFi les() on that file... I
don't think this will work. You can only list the files of a directory.

That may be why the exception is occurring, in the second try...catch block.

-- Tom Spink
Jun 23 '06 #4

"schaf" <sc***@2wire.ch > wrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
| Hi NG !
| I have the following piece of code below. the first try/catch part
| would return true although I do not have permission to access this
| computer. The second try/catch part would return false.
| Do I misunderstand the meaning of FileIOPermissio n ?

Yes, you do. FileIOPermissio n is about Code Access Security (CAS) not about
Windows security. Windows permissions are resource permissions based on
"user" identity (has the user permissions to access the resource?), while
CAS are base on "code" identity (does the "code" have access permissions to
the resource).
Please search the MSDN doc's for more info on the subject, CAS is a complex
issue so you might start with
http://msdn.microsoft.com/library/de...ctices0001.asp
to get an high level picture before you dive into the details.
Willy.
Jun 23 '06 #5
Hi Tom !
Of course you are right, but what I would like to ask is, that with the
current logged on user I do not have permission to access anything on
the computer 192.168.2.2. So why do I get a FileIOPermissio n = true for
my demand ?
If I test it with the first try/catch then I get true and would fail in
a File.Copy() command. So why true is the return, if I do not have
access on the whole computer ?

Thanks
Regards Schaf
schaf wrote:

Hi!
What if you do a Console.Write( e.Message ) ?

It will give you the exact problem with the GetFiles method


I do not have problems with the second try and catch, because this acts
like I expect, but the first one should give me a SecurityExcepti on
because I have no permission to access the files on this computer. So
to conclude if I test the file access with the FileIOPermissio n class,
I get the wrong result. But why ?

Regrads
Marcel


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"schaf" <sc***@2wire.ch > wrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
> Hi NG !
> I have the following piece of code below. the first try/catch part
> would return true although I do not have permission to access this
> computer. The second try/catch part would return false.
> Do I misunderstand the meaning of FileIOPermissio n ?
>>From MSDN: "Controls the ability to access files and folders"
> ???
> Thanks for education!
> Regards Marcel (Schaf)
>
> private bool _HasRemoteAcces s() {
> string sRemotePath = @"\\192.168.2.2 \C$\Temp\Text.t xt";
> bool bHasAccess = true;
>
> //returns true
> try {
> FileIOPermissio n permission = new
> FileIOPermissio n(FileIOPermiss ionAccess.Write , sRemotePath);
> permission.Dema nd();
> } catch (System.Securit y.SecurityExcep tion se) {
> bHasAccess = false;
> }
>
> //returns false
> try {
> string[] sRemoteFiles = Directory.GetFi les(sRemotePath );
> } catch (Exception e) {
> bHasAccess = false;
> }
> return bHasAccess;
> }
>


Hi Schaf,

If you inspect the exception that is occurring in the second try...catch
block, you may be surprised. From what I can see, you are trying to call
Directory.GetFi les() on a file. You've defined sRemotePath to be a file,
i.e. "test.txt" and you are using Directory.GetFi les() on that file... I
don't think this will work. You can only list the files of a directory.

That may be why the exception is occurring, in the second try...catch block.

-- Tom Spink


Jun 23 '06 #6
schaf wrote:
Hi Tom !
Of course you are right, but what I would like to ask is, that with the
current logged on user I do not have permission to access anything on
the computer 192.168.2.2. So why do I get a FileIOPermissio n = true for
my demand ?
If I test it with the first try/catch then I get true and would fail in
a File.Copy() command. So why true is the return, if I do not have
access on the whole computer ?

Thanks
Regards Schaf
schaf wrote:
>
> Hi!
>
>> What if you do a Console.Write( e.Message ) ?
>>
>> It will give you the exact problem with the GetFiles method
>
> I do not have problems with the second try and catch, because this acts
> like I expect, but the first one should give me a SecurityExcepti on
> because I have no permission to access the files on this computer. So
> to conclude if I test the file access with the FileIOPermissio n class,
> I get the wrong result. But why ?
>
> Regrads
> Marcel
>
>>
>>
>> --
>> --
>> Ignacio Machin,
>> ignacio.machin AT dot.state.fl.us
>> Florida Department Of Transportation
>>
>>
>> "schaf" <sc***@2wire.ch > wrote in message
>> news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
>> > Hi NG !
>> > I have the following piece of code below. the first try/catch part
>> > would return true although I do not have permission to access this
>> > computer. The second try/catch part would return false.
>> > Do I misunderstand the meaning of FileIOPermissio n ?
>> >>From MSDN: "Controls the ability to access files and folders"
>> > ???
>> > Thanks for education!
>> > Regards Marcel (Schaf)
>> >
>> > private bool _HasRemoteAcces s() {
>> > string sRemotePath = @"\\192.168.2.2 \C$\Temp\Text.t xt";
>> > bool bHasAccess = true;
>> >
>> > //returns true
>> > try {
>> > FileIOPermissio n permission = new
>> > FileIOPermissio n(FileIOPermiss ionAccess.Write , sRemotePath);
>> > permission.Dema nd();
>> > } catch (System.Securit y.SecurityExcep tion se) {
>> > bHasAccess = false;
>> > }
>> >
>> > //returns false
>> > try {
>> > string[] sRemoteFiles = Directory.GetFi les(sRemotePath );
>> > } catch (Exception e) {
>> > bHasAccess = false;
>> > }
>> > return bHasAccess;
>> > }
>> >


Hi Schaf,

If you inspect the exception that is occurring in the second try...catch
block, you may be surprised. From what I can see, you are trying to call
Directory.GetFi les() on a file. You've defined sRemotePath to be a file,
i.e. "test.txt" and you are using Directory.GetFi les() on that file... I
don't think this will work. You can only list the files of a directory.

That may be why the exception is occurring, in the second try...catch
block.

-- Tom Spink


Hi Scaf,

Unfortunately, FileIOPermissio n is not what you think it is.
FileIOPermissio n applies to the code, e.g. is your code allowed to call
FileIO operations. Well, yes, your code IS allowed to call FileIO
operations. But, the result of calling that and being blocked by security
permissions is totally unrelated.

Take a look at the GetAccessContro l() method of the FileInfo object.

Hope this helps,
-- Tom Spink
Jun 23 '06 #7

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

Similar topics

0
1375
by: Mircea Pleteriu | last post by:
Hi all, I have this code sample FileIOPermission fp = new FileIOPermission(PermissionState.Unrestricted); fp.Deny(); StreamWriter sw = new StreamWriter(@"c:\test.txt");
0
3854
by: Ant Corrie | last post by:
I am at a loss as to why this is not working. I am trying to setup a TextWriterTraceListener in my application config file and then execute the app from the network. I get a security exception (listed below) even though I have StrongNamed my application and used the .NET Configuration Tool to create a Code Access Group in the Machine Policy that gives FullTrust to assemblies with the StrongName that I created. If you uncomment the code...
0
1730
by: paul | last post by:
I just installed Windows XP SP2 on my web server. Now when I run one of the web applications I get the following error: ArgumentException: Illegal characters in path.] System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String str) +276 System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, String pathListOrig, Boolean checkForDuplicates, Boolean
0
1133
by: John Delange | last post by:
Hello, I wrote a .NET Windows.Forms User Control that needs to be runned through Internet Explorer, like in this article: http://www.15seconds.com/issue/030610.htm. This control needs to 1.) Run on the Internet and 2.) have FileIOPermission... Is there a way of deployment where the final user (the user who's just surfing on the internet) doesn't have to set the FileIOPermission to the assembly manually? Like the way signed ActiveX...
1
2186
by: Marquis | last post by:
I have put the C# Form onito the Internet as an ActiveX Control. However, I cannot do the FileOpen Dialog as I don't have permission, how to solve this problem? Below is the error code: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at...
3
12061
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (machine.config) ---> System.Security.SecurityException: Request for the permission of type
1
2797
by: innes | last post by:
Hi, I'm trying to test permission to access the file system, using FileIOPermission, but can't seem to get it to work. See my sample app below, for an app that tries to demand a permission to read a specified path, and then calls Directory.GetFiles on that path. The Demands on FileIOPermissions (I tried 3 variations) all work, and then when I call Directory.GetFiles an exception is thrown... saying
2
1414
by: Dave | last post by:
Yesterday I posted: **************************** I'm trying to download a file from the Web Server to the user's desktop using myWebClient.DownloadFile as described by Microsoft at http://msdn.microsoft.com/en-us/library/ez801hhe.aspx. 2 Questions:
1
9897
by: Oleg Subachev | last post by:
I try to write some info to file in the CLR Trigger under SQL Server 2005. But I get the following error: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. How can I grant FileIOPermission to my assembly running under SQL Server ? Oleg Subachev
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.