Thursday, May 5, 2011

How to access local folders when code is runned from a network share

Hi, I'm running an application from a network share, this application then try to verify if the path "C:\temp" exist and return true or false.

If the code is runned localy, there's no problem. If it's runned from a network share, I get the result false, even if the folder exist localy.

The code is C# on framework 2.0

Thank you

From stackoverflow
  • This has to do with the security policy settings of the .NET framework. By default, code running from the intranet zone (which UNC path are assigned to) are not fully trusted, limiting some of your code to succeed.

    You can use the configuration wizards to change these settings if required. Open a Visual Studio command prompt and run "Configwizards.exe".

    See also this link for information about CAS configuration.

  • You would need to run under elevated priviledges to see this. It part of the Code Access Security model.

    I would recommend using an application data folder as returned by Environment.GetFolderPath instead of a hard-coded path.

    overslacked : I don't normally upvote answers that propose solutions contrary to what the OP wants, but I've seen this problem occur so many times that I think it's important that developers really start using user-specific storage paths.
    Reed Copsey : @overslacked: Well, I told him how to get there (run under elevated privs) as well the cause of this problem (CAS)... I just don't think it's the "best" option in this case, hence my suggestion afterwards.

0 comments:

Post a Comment