Copying files Permission

  • Thread starter Thread starter ReidarT
  • Start date Start date
R

ReidarT

I am copying a file from a network drive to a local PC.
Could someone give me a short example on how to get permission to copy the
file from R: to C:
I have figured out that if I use
Imports System.Security.Permissions

and

Dim oFp As FileIOPermission = New _

FileIOPermission(FileIOPermissionAccess.AllAccess, "R: ....

Am I on the track?

regards

reidarT
 
ReidarT,

You can't really give yourself permissions if you don't have them
already.

You can use the FileIOPermission class to determine whether or not you
have the permission (based on where your app was loaded from).

What you would do is create an instance of the FileIOPermission
instance, passing the complete paths of the file names you want to move
(with read access for the file being copied, and write access for the file
being copied to).

Once you have that, you can call Demand on the permission, and it will
throw a security exception if the framework will permit you to make the
call.

Hope this helps.
 
Hi! Were you able to get it working? I am faced with the same problem.
If you were, may I ask you to post the code here, please.

Many Thanks in Advance
 
Hi Mike,

UnauthorizedAccessException: the only way to avoid this is not in your
code. Ask an admin on that machine to grant more permission (ACL) for
you (i.e. the account you logged in on the local computer) on the file
to copy.

SecurityException: Adjust code access security for your assembly. The
easiest way to do this is by using .NET tools in Control
Panel/Administrative Tools. Note that you cannot adjust this in your
code. IOPermission.Demand() just check for permission and make things
fail fast if not granted.

Regards,
Thi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top