Hi all, I am very new to .NET, however I am finding coding in C# very enjoyable!
I have written a very basic windows app, that gets the user to browse for a folder, then creates folders and moves files based on filenames. This all works perfectly on my pc, I can even access folders across the network, however as soon as I take my .exe and put it on any other computer, I get FileIOPermissions exceptions from anything I do. Type: Demand, Zone: Intranet.
I've googled all day, and I've found heaps of people with my problem, but no solutions!
I have a few of these tiny apps to make, so ideally I would like to compile into a single .exe which I can put on any computer and run without problems. Can I get .NET to use basic windows user permissions instead of its annoyingly over complicated .NET stuff?
I have tried adding:
PermissionSet permSet = new PermissionSet(PermissionState.None);
permSet.AddPermission(new SecurityPermission(PermissionState.Unrestricted));
permSet.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
but to no avail.
Any help would be greatly appreciated!
The program can be found here:
http://www.nomorepasting.com/getpaste.php?pasteid=1734&seen=true&langoverride=csharp
Loading
NathanPosted Jul 24, 2007, 9:17 PM
The folderisor miraculously started working yesterday afternoon, after no code changes from me... so I really don't know what the problem was lol. However, the second program I created that was suffering from the same problem still wouldnt work. I added the code you mentioned above and now it works :D yay!
Thanks so much!
Jan MontanoPosted Jul 24, 2007, 3:43 AM
I'm not sure if this will work, but we could try (^_^)
Please try to include this attribute above your namespace.
using System.Security.Permissions;
[assembly:PermissionSetAttribute(SecurityAction.RequestMinimum, Name = "FullTrust")]
namespace MyNamespace
Well, I was reading about requesting permissions in .NET Framework Developer's Guide and read something about that attribute. I'm not sure as of this time, what's the culprit in the FileIOPermission you're encountering. Might as well give this a shot.
NathanPosted Jul 24, 2007, 2:55 AM
Firstly, thank you for your response!
Yes, the other pc's are able to run the exe.
Yes, the other pc's have access to all the folders they are trying to read from, move from/to, create folders in, and anything else :)
The error seems to occur once the folder is selected in the dialogue, and the OK button is pressed.
Thanks again for your time!
Jan MontanoPosted Jul 24, 2007, 2:02 AM
You mentioned that you're encountering FileIOPermissions Exceptions as soon as you put it on any other computers right? But do those PCs have access to the folders you're browsing with your program? Can they also create folders manually in other pcs through the network?
Normally, if the user in those pcs, don't have suitable rights to access other pcs, then your program wiill result in an exception too.
Setting the approriate access rights for each user will do the trick. I saw your code, though I haven't tried it yet. But as long as you have access to those folders (meaning you could access it manually, your program should do fine). Try to access it manually before automating it with your code.
Yes you could use Windows user permissions, but is that what you really want? Or you just want them to be able to access certain folders of certain pcs?
Last but not the least, at what point does the exception occur? Are you able to run your exe from the other computers?
Cheers,
Jan