CopyDirectory method gives permission error

P

Patch61

I am new to .Net programming, but I am experienced with VB6. I am using VB
2008 Express to write a small program to copy a directory structure and files
from a CD to a folder on C: drive.

I have a form with 2 buttons; one to do the copying and one to cancel.

Here is my code for the copying button:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
My.Computer.FileSystem.CopyDirectory("F:\WAFS Blocks - Test",
"C:\HES\WAFS\WAFS Blocks", FileIO.UIOption.AllDialogs)
End Sub

When I click button1, I get an error that says:

............
Application attempted to perform an operation not allowed by the security
policy. To grant this application the required permission, contact your
system administrator, or use the Microsoft .NET Framework Configuration tool.

Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089'
............

My IT department has no idea what to do about this. They have given my user
account full admin rights with the same results.

What do I need to do to correct this? I need to deploy this on several
systems in several office locations.

Thanks in advance for any help.
 
Z

zacks

I am new to .Net programming, but I am experienced with VB6. I am using VB
2008 Express to write a small program to copy a directory structure and files
from a CD to a folder on C: drive.

I have a form with 2 buttons; one to do the copying and one to cancel.

Here is my code for the copying button:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        My.Computer.FileSystem.CopyDirectory("F:\WAFS Blocks - Test",
"C:\HES\WAFS\WAFS Blocks", FileIO.UIOption.AllDialogs)
    End Sub

When I click button1, I get an error that says:

...........
Application attempted to perform an operation not allowed by the security
policy. To grant this application the required permission, contact your
system administrator, or use the Microsoft .NET Framework Configuration tool.

Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089'
...........

My IT department has no idea what to do about this. They have given my user
account full admin rights with the same results.

What do I need to do to correct this? I need to deploy this on several
systems in several office locations.

Thanks in advance for any help.

I have never used this method, and doubt I ever will now since I have
switched to C#.NET. But, looking as MSDN help, in the list of
exceptions that this method can raise, one is "The Source Directory is
a root directory". Now the remarks does not explicitely mention that
the source direcotyr cannot be the root directory, but it makes one
wonder.
 
K

kimiraikkonen

I am new to .Net programming, but I am experienced with VB6. I am using VB
2008 Express to write a small program to copy a directory structure and files
from a CD to a folder on C: drive.

I have a form with 2 buttons; one to do the copying and one to cancel.

Here is my code for the copying button:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        My.Computer.FileSystem.CopyDirectory("F:\WAFS Blocks - Test",
"C:\HES\WAFS\WAFS Blocks", FileIO.UIOption.AllDialogs)
    End Sub

When I click button1, I get an error that says:

...........
Application attempted to perform an operation not allowed by the security
policy. To grant this application the required permission, contact your
system administrator, or use the Microsoft .NET Framework Configuration tool.

Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089'
...........

My IT department has no idea what to do about this. They have given my user
account full admin rights with the same results.

What do I need to do to correct this? I need to deploy this on several
systems in several office locations.

Thanks in advance for any help.

If you're copying the file over a LAN, having full admin rights will
not help you. Check for sharing / security permissions depending your
operating system.

If it's a local disk, try to copy the same directory manually (copy-
paste) and see if error happens again.
 
P

Patch61

Thank you for replying, but as you can see from my code, neither the source
nor the destination is a root directory.
 
P

Patch61

Thank you for replying. I have tried this with both a network source and a
local source with the same results. I have full admin access/permissions.
 
C

Chris Dunaway

I am new to .Net programming, but I am experienced with VB6. I am using VB
2008 Express to write a small program to copy a directory structure and files
from a CD to a folder on C: drive.

I have a form with 2 buttons; one to do the copying and one to cancel.

Here is my code for the copying button:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
My.Computer.FileSystem.CopyDirectory("F:\WAFS Blocks - Test",
"C:\HES\WAFS\WAFS Blocks", FileIO.UIOption.AllDialogs)
End Sub

When I click button1, I get an error that says:

...........
Application attempted to perform an operation not allowed by the security
policy. To grant this application the required permission, contact your
system administrator, or use the Microsoft .NET Framework Configuration tool.

Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089'
...........

My IT department has no idea what to do about this. They have given my user
account full admin rights with the same results.

What do I need to do to correct this? I need to deploy this on several
systems in several office locations.

Thanks in advance for any help.

Where is the program running? Are you running it from a network
share? Or is the program located on the local hard drive? If running
from a network share, you need to grant trust to the application.

F: looks like a mapped drive. You might try copying using the full
UNC of the path instead of the mapped drive.

Good Luck

Chris
 

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

Top