none
WPF Desktop App - Write file permissions

    Question

  • I have been working on a WPF desktop app for a while now, and I am struggling to deploy it.  The problem seems to be that the app does not have permissions to save the file I am creating.  Although I should say the code works fine running locally through Visual Studio.

    I am OneClick deploying the app, and just want to give it full access although just knowing how to give it write permission is all I need.  The app is only to be used by a few members of staff on our intranet, so trust is not really an issue here.

    If anyone can point me in the direction of a quick solution that would be great, and you'll save me alot of time trying to figure out all the documentation which I am failing to work out what to do with so far.

    Additional info: I am deploying over a web address, which I think means Internet Zone.

    Thanks

    John

    Tuesday, August 31, 2010 2:38 PM

Answers

  • Assuming this is a WPF Desktop application, i.e. a .application and not an .xbap (otherwise it'd be a Browser app) you are most likely running into issues with Windows ACLs or LUA (Vista/Win7) differences.  If it is a partial trust .xbap, you can indeed save files to the local file system -- even in partial trust -- you'll just need to go through a SaveFileDialog.

    Here's how to check each:

    ACL issues:

    - Get File properties on the folder (Right Click / Properties) where you are trying to create a file.  Ensure the user your application is running as has write permissions to this path.

    LUA issues:

    - This is a little more difficult since you cannot directly elevate .applications. Simply start the application's exe through an elevated command prompt directly, or right click on the .exe (not .application) and click "Run as Administrator".  If this solves your problem, you need to write files elsewhere as you won't be able to implicitly elevate when running as a ClickOnce app.

    Otherwise, please post the call stack and exception message you see when your application throws an exception.

    Hope this helps,
    Matt


    SDET : Deployment/Hosting
    • Marked as answer by JCorker Wednesday, September 01, 2010 8:59 AM
    Tuesday, August 31, 2010 5:49 PM

All replies

  • Assuming this is a WPF Desktop application, i.e. a .application and not an .xbap (otherwise it'd be a Browser app) you are most likely running into issues with Windows ACLs or LUA (Vista/Win7) differences.  If it is a partial trust .xbap, you can indeed save files to the local file system -- even in partial trust -- you'll just need to go through a SaveFileDialog.

    Here's how to check each:

    ACL issues:

    - Get File properties on the folder (Right Click / Properties) where you are trying to create a file.  Ensure the user your application is running as has write permissions to this path.

    LUA issues:

    - This is a little more difficult since you cannot directly elevate .applications. Simply start the application's exe through an elevated command prompt directly, or right click on the .exe (not .application) and click "Run as Administrator".  If this solves your problem, you need to write files elsewhere as you won't be able to implicitly elevate when running as a ClickOnce app.

    Otherwise, please post the call stack and exception message you see when your application throws an exception.

    Hope this helps,
    Matt


    SDET : Deployment/Hosting
    • Marked as answer by JCorker Wednesday, September 01, 2010 8:59 AM
    Tuesday, August 31, 2010 5:49 PM
  • Tuesday, August 31, 2010 5:55 PM
  • Hi Zee.

       Note that it's not possible for a Desktop (non-browser) WPF application to be CAS partial-trust, so such suggestions are not particularly helpful.

    -Matt


    SDET : Deployment/Hosting
    Tuesday, August 31, 2010 6:24 PM