Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

unauthorizedaccessexception

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);
            tw.Write("testing");
            tw.Close();

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!
0
pengbsam
Asked:
pengbsam
1 Solution
 
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;
http://msdn.microsoft.com/msdnmag/issues/05/11/CodeAccessSecurity/default.aspx?loc=&side=true

Check out the section entitled 'To grant full trust to the assembly and the document'
http://msdn2.microsoft.com/en-us/library/ms404837(VS.80).aspx

Caspol tips:
http://www.dotnetspider.com/kb/Article413.aspx
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now