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

security permissions for creating a file

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
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

Nov 17 '05 #2

P: n/a
Hi Nicholas,

I tried a console application and as admin I have no restriction in any
directory.

regards Mark

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
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


Nov 17 '05 #3

P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
Hi Nicholas,

I tried a console application and as admin I have no restriction in any
directory.

regards Mark

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
> 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
>
>



Nov 17 '05 #4

P: n/a
hi,

post the text of the exception.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
Hi Nicholas,

I tried a console application and as admin I have no restriction in any
directory.

regards Mark

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
> 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
>
>



Nov 17 '05 #5

P: n/a
hi

Request for the permission of type
System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

regards
Mark
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
schrieb im Newsbeitrag news:ON**************@TK2MSFTNGP12.phx.gbl...
hi,

post the text of the exception.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
Hi Nicholas,

I tried a console application and as admin I have no restriction in any
directory.

regards Mark

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
> 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
>
>



Nov 17 '05 #6

P: n/a
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]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:e2**************@TK2MSFTNGP14.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
Hi Nicholas,

I tried a console application and as admin I have no restriction in any
directory.

regards Mark

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
> 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
>
>



Nov 17 '05 #7

P: n/a
You loading the executable from a network share.
Programs that are loaded from a network are not trusted to access the local
file system, you have to grant "fulltrust" to the the share you are loading
this application from using caspol.exe.

Willy.
"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
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]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:e2**************@TK2MSFTNGP14.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
> Hi Nicholas,
>
> I tried a console application and as admin I have no restriction in any
> directory.
>
> regards Mark
>
>
>
> "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb > im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
>> 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]
>> - mv*@spam.guard.caspershouse.com
>>
>> "Mark" <Sc********@gmx.net> wrote in message
>> news:dc*************@news.t-online.com...
>> > 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
>> >
>> >
>>
>>
>
>



Nov 17 '05 #8

P: n/a
"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
hi,

what I am trying:

1. I create a file x.cs with notepad nothing more than a main <snip> 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)
If you're running the exe from a local hard drive (as opposed to somewhere
on your network), it sounds like you might have modified your CAS policy.
To verify what permissions your executable is being assigned under your
current CAS policy, follow the steps listed in the "How can I test my policy
changes?" section at
http://msdn.microsoft.com/library/en...ecpoladmin.asp.
If your assembly is local, and it's granted anything other than an
unrestricted permission set, your CAS policy has been modified from its
default configuration.

If you are running with modified policy, was it a deliberate change or not?
If it wasn't deliberate, you might want to simply revert to the default
configuration (after backing up your current configuration). If it was
deliberate, then adding a new code group to allow your application to run as
desired might be a better approach.

If your assembly is granted unrestricted permissions under policy, might the
problem stem from use of assembly-level permissions attributes? In
particular, might you be using any attributes with
SecurityAction.RequestOptional?

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]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:e2**************@TK2MSFTNGP14.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
> Hi Nicholas,
>
> I tried a console application and as admin I have no restriction in any
> directory.
>
> regards Mark
>
>
>
> "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb > im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
>> 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]
>> - mv*@spam.guard.caspershouse.com
>>
>> "Mark" <Sc********@gmx.net> wrote in message
>> news:dc*************@news.t-online.com...
>> > 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
>> >
>> >
>>
>>
>
>



Nov 17 '05 #9

P: n/a
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:OL**************@TK2MSFTNGP14.phx.gbl...
You loading the executable from a network share.
Actually, it sounds like he probably isn't.

Programs that are loaded from a network are not trusted to access the
local file system, you have to grant "fulltrust" to the the share you are
loading this application from using caspol.exe.
Granting full trust in order to allow writing to one file is a wee bit of
overkill, no? <g>


Willy.
"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
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]" <mv*@spam.guard.caspershouse.com>
schrieb
im Newsbeitrag news:e2**************@TK2MSFTNGP14.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
> Hi Nicholas,
>
> I tried a console application and as admin I have no restriction in
> any
> directory.
>
> regards Mark
>
>
>
> "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>

schrieb
> im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
>> 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]
>> - mv*@spam.guard.caspershouse.com
>>
>> "Mark" <Sc********@gmx.net> wrote in message
>> news:dc*************@news.t-online.com...
>> > 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
>> >
>> >
>>
>>
>
>



Nov 17 '05 #10

P: n/a

"Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com> wrote in message
news:uI**************@TK2MSFTNGP15.phx.gbl...
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:OL**************@TK2MSFTNGP14.phx.gbl...
You loading the executable from a network share.
Actually, it sounds like he probably isn't.


Could be, it would not be the first time someone thinks a mapped drive is a
local disk.
Programs that are loaded from a network are not trusted to access the
local file system, you have to grant "fulltrust" to the the share you are
loading this application from using caspol.exe.


Granting full trust in order to allow writing to one file is a wee bit of
overkill, no? <g>


Nicole,
Sure it is overkill, but at least it's a start, because I'm not sure the OP
knows about CAS at all, if he knew about it, he probably figured the
exception was CAS related, which he didn't.
If he knows about CAS, he might have screwed it's local policy settings
somehow when running from a local disk, which I doubt seriously but I
(whish) could be wrong.
Willy.
Nov 17 '05 #11

P: n/a
hi

Request for the permission of type
System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

regards
Mark

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
schrieb im Newsbeitrag news:ON**************@TK2MSFTNGP12.phx.gbl...
hi,

post the text of the exception.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
Hi Nicholas,

I tried a console application and as admin I have no restriction in any
directory.

regards Mark

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
> 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
>
>



Nov 17 '05 #12

P: n/a
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.

thanks and regards
Mark
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:e2**************@TK2MSFTNGP14.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
Hi Nicholas,

I tried a console application and as admin I have no restriction in any
directory.

regards Mark

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb im Newsbeitrag news:es**************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mark" <Sc********@gmx.net> wrote in message
news:dc*************@news.t-online.com...
> 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
>
>



Nov 17 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.