hi,
what I am trying:
1. I create a file x.cs with notepad nothing more than a main
public static void Main( string[] args )
{
try
{
FileStream file = new FileStream("test.txt", FileMode.OpenOrCreate,
FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.Write("Hello");
sw.Close();
file.Close();
}
catch( Exception ex )
{
Console.WriteLine( ex.Message );
};
}
2. built it with csc.exe x.cs and got a x.exe
3. executing x.exe on commandline (local dir, no shares, as admin, no
domain, simple way)
4. got exception - I guess .NET told me that this application is not safe
writing files.
Request for the permission of type
System.Security.Permissions.FileIOPermission, mscorlib,
Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
regards
Mark
"Nicholas Paldino [.NET/C# MVP]" <
[email protected]>
schrieb
im Newsbeitrag news:
[email protected]...
Are you sure that the security exception is for opening the file
then?
Where is the application loaded from? Are you running it from a network
share, or the internet? If so, then the application is going to be granted
a limited permission set.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Hi Nicholas,
I tried a console application and as admin I have no restriction in
any
directory.
regards Mark
im Newsbeitrag Mark,
You get this exception because you don't have rights to create or
open
the file in the directory that it is set in. You need to try and create
the
file in a directory that you have rights to, or, if the file exists,
check
the rights on the file to make sure that you can open it for writing.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Hello,
in a simple console application I try to create a file with some
code
like:
FileStream file = new FileStream("test.txt",
FileMode.OpenOrCreate,
FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.Write("Hello");
sw.Close();
file.Close();
I will get an error System.Security.SecurityException
Are there only one way to avoid this and how this can be done?
Thanks and regards
Mark