Posted on 2007-07-31
Last Modified: 2012-06-21
Hello All:
I am trying to write a log string from a C# program to a network share folders, unfortunately when I try to do this they give me a unauthorizedaccessexception. My code looks like below

FileStream newfile = new FileStream(@"\\shareserver\Attachments\test.txt", FileMode.CreateNew, FileAccess.ReadWrite);
            TextWriter tw = new StreamWriter(newfile);

now if I just put \\shareserver\Attachments in the browser, the directory pops up. I have full administration server rights to this folder and server. So why the exception? Can someone help please!

Thank You!
Question by:pengbsam
    1 Comment
    LVL 4

    Accepted Solution

    The exception is happening because the code accessing the folder is not trusted. You can change this using the caspol utility.

    An article explaining how CASPol works;

    Check out the section entitled 'To grant full trust to the assembly and the document'

    Caspol tips:

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now