Easy Question Re: FileIOPermission

I am writing a very simple C# application to help with my kids' reading.  The app consists of a form with a button that brings up randomly one of a hundred words stored in an array and the play button plays me reading that word stored in an individual .wav file.  The program plays fine on my computer but when I run it on their computer I get the following error message:

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 System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessPermission.Demand()
   at System.IO.Directory.GetCurrentDirectory()
   at TopWords.Form1.button2_Click_1(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The Zone of the assembly that failed was:
Internet

My first version of the code did not have the Directory.GetCurrentDirectory() method and looked for the .wav files in a set place.  I modified it this morning and now get the message as above.  Here is the code from the button click method:  
private void button2_Click_1(object sender, EventArgs e)
        {
        if (label1.Text != "          ")
        {
           
            FileIOPermission f = new FileIOPermission(PermissionState.None);
            f.AllLocalFiles = FileIOPermissionAccess.AllAccess;
            string currentDirectory = Directory.GetCurrentDirectory();
            System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
            string FileName;
            FileName = currentDirectory +"\\"+label1.Text+".wav";
            myPlayer.SoundLocation = @FileName;
            myPlayer.Play();
         
        }
        }

Any help would be appreciated...I am very novice with C# and .Net.
Thanks,
Doug.
djmaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Doug,

It sounds like you are running the application on one machine from a folder on your development machine.  There are zones in the .NET security framework.  My Computer gets full trust by default, but anything else is considered a partially trusted environment.

The term is "Code Access Security", and has a pretty large footprint.

Understanding .NET Code Access Security
http://www.codeproject.com/KB/security/UB_CAS_NET.aspx
0
djmaAuthor Commented:
No, I am running as a standalone application from a desktop machine loading the file from my server.  It is funny, the application (this is my first c# app) took me half an hour to write and this error has taken me hours to track down.  .NET is extremely complicated for a middle aged newbie.

I am looking through the Code Access Security link which co-incidentally I came across when doing my first pass through for a solution.  Although I will try and code this myself if you could tell my which namespace I need and how to call for FullTrust...it would be appreciated.
Thanks,
Doug.
0
Bob LearnedCommented:
One way to solve this is to make sure that the computer has My Computer zone set to Full Trust.


Start Menu | Administrative Tools | Microsoft .NET Framework 2.0 Configuration | Configure Code Access Security Policy | Adjust Zone Security

Make changes to this computer
My Computer is selected by default
Slider needs to be at the top (Full Trust)
0
grayeCommented:
Be aware that you kid's PC might not have the control panel applet installed.
Take a look at the following article that provides a technique installing the missing applet (and for adjusting CAS without the control panel appet):  http://home.hot.rr.com/graye/Articles/CodeAccessSecurity.htm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
djmaAuthor Commented:
Thanks everyone for your help.  I was able to fix it by adjusting the Intranet zone in Internet Explorer and adding my server drive to the list.  Nevertheless, this seems extremely complicated for an old fart like me who only wanted to write a quick app for his kids.  Anyway, I guess I should be using a less sophisticated (and complicated) tool.  I could have done the whole thing in a few minutes using FoxPro but I thought it would be fun to use c#.  Anyway, I am now wiser.  Thanks again.
Doug.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.