Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 54279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:11:43+00:00 2026-05-10T17:11:43+00:00

This snippet works well if I try to write in a user directory but

  • 0

This snippet works well if I try to write in a user directory but as soon as I try to write in Program Files, it just executes silently and the file has not been copied (no exception). If I try to copy the file in C:\ or in C:\Windows I catch an UnauthorizedAccessException.

Do you know another way to get the permissions to write in that directory or to make it work another way?

Any help greatly appreciated! Thanks

using(FileStream fs=File.Open(source, FileMode.Open)){ }   try   {       FileIOPermission fp = new FileIOPermission(FileIOPermissionAccess.Write,                              AccessControlActions.Change, 'C:\\Program Files\\MyPath');       fp.Demand();  //<-- no exception but file is not copied     File.Copy('C:\\Users\\teebot\\Documents\\File.xml','C:\\Program Files\\MyPath\\File.xml',true);   }   catch(SecurityExceptions)   {       throw(s);   }  catch(UnauthorizedAccessException unauthroizedException) {     throw unauthroizedException; } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:11:43+00:00Added an answer on May 10, 2026 at 5:11 pm

    If you are running under Vista then the system just redirects writes to the program files folder, this is done so old program that keep their configuration in the program directory will continue to work when the user is not an Admin (or UAC is enabled).

    All you have to do is add a manifest to your program that specify the required access level, then the system assume your program is Vista-aware and turns off all those compatibility patches.

    You can see an example of a manifest file on my blog at:

    http://www.nbdtech.com/blog/archive/2008/06/16/The-Application-Manifest-Needed-for-XP-and-Vista-Style-File.aspx

    (the focus of the post is on getting the right version of the common controls, but the Vista security declarations are also there)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 73k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Well.. If you do the code: T value; then value… May 11, 2026 at 1:55 pm
  • added an answer Found the problem: I just need to COMPILE the solution… May 11, 2026 at 1:55 pm
  • added an answer Margins collapse, even with contained elements, so your inner div's… May 11, 2026 at 1:55 pm

Related Questions

This snippet of Perl code in my program is giving the wrong result. $condition
Does anybody knows why this snippet returns false even if the passed string is
I came across this snippet of code on MSDN: entityBuilder.Metadata = @res://*/AdventureWorksModel.csdl| res://*/AdventureWorksModel.ssdl| res://*/AdventureWorksModel.msl;
I wrote this snippet of code and I assume len is tail-recursive, but a
In an application I work on, any business logic error causes an exception to
I'm setting up a User Control driven by a XML configuration. It is easier
problem description: This model works fine with one user at a time. As soon
There are some good examples on how to calculate word frequencies in C#, but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.