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!
Who is Participating?
Tommie Nathaniel Carter, Jr., MBAFounderCommented:
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:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.