Run the .NET program from a mapped drive or shared folder

I wrote a C # Windows Forms application for combining files and folders from a remote folder on one machine (the "source" folder is the mapped drive - "Z: \ folder") with another remote folder on the other machine (the "destination" folder is the way UNC to the shared folder is "\\ computer_name \ sharedfolder"). I have Full permissions for both folders. When I run the program on my local computer, it works fine, but when I try to run it from the source folder, it crashes with a security exception.

The crash occurs when the DirectoryInfo constructor is called for the target folder (for example, DirectoryInfo (@ "\\ computer_name \ sharedfolder). I assume that the problem is that I am running the program from the mapped drive. / P>


Specific exception: A permission request of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' failed.


UPDATE

Okay, I got my application in Visual Studio 2008 (it was previously encoded in 2005), aimed at the .NET 3.5 platform, compiled and retried.

I got the same error.


UPDATE - RESOLUTION

I tried this with .NET 3.5 and it did not work, then I noticed that you said 3.5 SP1. Service Pack required.

The problem is resolved. Thanks.

+7
c # unc
source share
2 answers
+8
source share

You need to enable FullTrust permissions for the application. .NET applications running on a network share receive permissions to access the local network and, therefore, work in an isolated software environment.

Here is the batch file that I wrote for one of our test applications that run from the network. It should launch you with a few changes.

@ECHO OFF SET CASPOL=%windir%\Microsoft.NET\Framework\v2.0.50727\CasPol.exe CLS %CASPOL% -pp off %CASPOL% -m -ag 1.2 -url file://server/directory/* FullTrust 

As stated above, .NET 3.5 eliminates this behavior.

+6
source share

All Articles