Re: StreamWriter causes SecurityException when attempting to write to network drive..need help

From: Nicole Calinoiu (calinoiu)
Date: 08/22/05

  • Next message: Paul Clement: "Re: Can't determine if a file exists"
    Date: Mon, 22 Aug 2005 11:58:10 -0400

    <> wrote in message
    > Nicole,
    > Since I probably will not be able to accomplish executing the
    > application from a network and then write a report file to a network
    > drive, how do I go about checking before hand if the application has
    > security permission to open then write to a file?

    The most suitable approach would probably be to demand the necessary
    FileIOPermission in your code, presumably when your application loads. (I'm
    guessing that you'll probably want to demand unrestricted FileIOPermission
    given that it sounds like you want the user to be able to save to any local
    or network location at any time.) Just be careful to call into a separate
    method to make the demand since the Demand method only evaluates the higher
    level callers, not the method from which the Demand call itself is made.

    Just so you know, it's also possible to prevent the loading of your
    application if it does not have the appropriate permissions. Since you'll
    presumably want to actually run the assembly in order to display a custom
    message to the users in case of missing permissions, this probably isn't the
    approach you'll want to take. However, just in case you would prefer it for
    some reason, the basic approach is to add a "request minimum" security
    attribute at the assembly level. e.g.:

    [assembly: FileIOPermission(SecurityAction.RequestMinimum, Unrestricted =

    >>you've probably managed to forget the pain of it all over time...
    > Oh, no. I relive the frustration from time to time during sustaining
    > activites. ;) There are times when I think it would be cool to be an
    > applications programmer, but then again writing low level code for the
    > embedded world has its advantages. Then again, getting the a low level
    > driver working correctly can get frustrating also. Just the every day
    > activity of a software person.
    > Mark

  • Next message: Paul Clement: "Re: Can't determine if a file exists"