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 FileIOPermission ? From MSDN: "Controls the ability to access files and folders"
???
Thanks for education!
Regards Marcel (Schaf)
private bool _HasRemoteAccess() {
string sRemotePath = @"\\192.168.2.2\C$\Temp\Text.txt";
bool bHasAccess = true;
//returns true
try {
FileIOPermission permission = new
FileIOPermission(FileIOPermissionAccess.Write, sRemotePath);
permission.Demand();
} catch (System.Security.SecurityException se) {
bHasAccess = false;
}
//returns false
try {
string[] sRemoteFiles = Directory.GetFiles(sRemotePath);
} catch (Exception e) {
bHasAccess = false;
}
return bHasAccess;
} 6 2447
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.googlegr oups.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 FileIOPermission ?From MSDN: "Controls the ability to access files and folders" ??? Thanks for education! Regards Marcel (Schaf)
private bool _HasRemoteAccess() { string sRemotePath = @"\\192.168.2.2\C$\Temp\Text.txt"; bool bHasAccess = true;
//returns true try { FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Write, sRemotePath); permission.Demand(); } catch (System.Security.SecurityException se) { bHasAccess = false; }
//returns false try { string[] sRemoteFiles = Directory.GetFiles(sRemotePath); } catch (Exception e) { bHasAccess = false; } return bHasAccess; }
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 SecurityException
because I have no permission to access the files on this computer. So
to conclude if I test the file access with the FileIOPermission 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.googlegr oups.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 FileIOPermission ?From MSDN: "Controls the ability to access files and folders" ??? Thanks for education! Regards Marcel (Schaf)
private bool _HasRemoteAccess() { string sRemotePath = @"\\192.168.2.2\C$\Temp\Text.txt"; bool bHasAccess = true;
//returns true try { FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Write, sRemotePath); permission.Demand(); } catch (System.Security.SecurityException se) { bHasAccess = false; }
//returns false try { string[] sRemoteFiles = Directory.GetFiles(sRemotePath); } catch (Exception e) { bHasAccess = false; } return bHasAccess; }
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 SecurityException because I have no permission to access the files on this computer. So to conclude if I test the file access with the FileIOPermission 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.googlegr oups.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 FileIOPermission ? >>From MSDN: "Controls the ability to access files and folders" > ??? > Thanks for education! > Regards Marcel (Schaf) > > private bool _HasRemoteAccess() { > string sRemotePath = @"\\192.168.2.2\C$\Temp\Text.txt"; > bool bHasAccess = true; > > //returns true > try { > FileIOPermission permission = new > FileIOPermission(FileIOPermissionAccess.Write, sRemotePath); > permission.Demand(); > } catch (System.Security.SecurityException se) { > bHasAccess = false; > } > > //returns false > try { > string[] sRemoteFiles = Directory.GetFiles(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.GetFiles() on a file. You've defined sRemotePath to be a file,
i.e. "test.txt" and you are using Directory.GetFiles() 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
"schaf" <sc***@2wire.ch> wrote in message
news:11**********************@m73g2000cwd.googlegr oups.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 FileIOPermission ?
Yes, you do. FileIOPermission 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.
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 FileIOPermission = 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 SecurityException because I have no permission to access the files on this computer. So to conclude if I test the file access with the FileIOPermission 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.googlegr oups.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 FileIOPermission ? >>From MSDN: "Controls the ability to access files and folders" > ??? > Thanks for education! > Regards Marcel (Schaf) > > private bool _HasRemoteAccess() { > string sRemotePath = @"\\192.168.2.2\C$\Temp\Text.txt"; > bool bHasAccess = true; > > //returns true > try { > FileIOPermission permission = new > FileIOPermission(FileIOPermissionAccess.Write, sRemotePath); > permission.Demand(); > } catch (System.Security.SecurityException se) { > bHasAccess = false; > } > > //returns false > try { > string[] sRemoteFiles = Directory.GetFiles(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.GetFiles() on a file. You've defined sRemotePath to be a file, i.e. "test.txt" and you are using Directory.GetFiles() 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
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 FileIOPermission = 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 SecurityException > because I have no permission to access the files on this computer. So > to conclude if I test the file access with the FileIOPermission 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.googlegr oups.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 FileIOPermission ? >> >>From MSDN: "Controls the ability to access files and folders" >> > ??? >> > Thanks for education! >> > Regards Marcel (Schaf) >> > >> > private bool _HasRemoteAccess() { >> > string sRemotePath = @"\\192.168.2.2\C$\Temp\Text.txt"; >> > bool bHasAccess = true; >> > >> > //returns true >> > try { >> > FileIOPermission permission = new >> > FileIOPermission(FileIOPermissionAccess.Write, sRemotePath); >> > permission.Demand(); >> > } catch (System.Security.SecurityException se) { >> > bHasAccess = false; >> > } >> > >> > //returns false >> > try { >> > string[] sRemoteFiles = Directory.GetFiles(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.GetFiles() on a file. You've defined sRemotePath to be a file, i.e. "test.txt" and you are using Directory.GetFiles() 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, FileIOPermission is not what you think it is.
FileIOPermission 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 GetAccessControl() method of the FileInfo object.
Hope this helps,
-- Tom Spink This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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");
|
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...
|
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.]
...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
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...
|
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,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
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...
|
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...
| |