Newbie question about permissions on network folder

G

Guest

Hi,

I'm trying to run a pretty simple code to rename a set of files located on a
network folder I have access to. When I run this from a local disk it works
fine. But when I copy the .EXE to the network and try to run the program from
there it comes back with the following exception message:

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

I tried adding the following code:
*-----------------------------------
Dim f As New FileIOPermission(PermissionState.None)
f.AddPathList(FileIOPermissionAccess.AllAccess, "F:\my network
folder")
*-------------------------------------

but it made no difference.

The troublesome code goes below:

*------------------------------
Private Sub ChangeFileName(ByVal strFrom As String, ByVal strTo As String,
ByRef di As DirectoryInfo, _
ByRef lblStatus As Label)

Dim entries() As FileSystemInfo
Try
entries = di.GetFileSystemInfos(strFrom)

If entries.Length = 1 Then
File.Move(txtPath.Text & entries(0).Name, txtPath.Text &
strTo)
lblStatus.Text = "Done"
lblStatus.Visible = True
Else
MsgBox("There was more/less than one file to be renamed from
" & strFrom, MsgBoxStyle.OKOnly)
lblStatus.Text = "Unable"
lblStatus.Visible = True
End If

Catch ex As Exception
MsgBox("There was a problem trying to access the directory " &
txtPath.Text & vbCrLf & _
"The message was: " & vbCrLf & ex.Message, _
MsgBoxStyle.OKOnly & MsgBoxStyle.Exclamation)
lblStatus.Text = "Unable"
lblStatus.Visible = True
End Try
End Sub
 
C

Chris

Claudio said:
Hi,

I'm trying to run a pretty simple code to rename a set of files located on a
network folder I have access to. When I run this from a local disk it works
fine. But when I copy the .EXE to the network and try to run the program from
there it comes back with the following exception message:

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

I tried adding the following code:
*-----------------------------------
Dim f As New FileIOPermission(PermissionState.None)
f.AddPathList(FileIOPermissionAccess.AllAccess, "F:\my network
folder")
*-------------------------------------

but it made no difference.

The troublesome code goes below:

*------------------------------
Private Sub ChangeFileName(ByVal strFrom As String, ByVal strTo As String,
ByRef di As DirectoryInfo, _
ByRef lblStatus As Label)

Dim entries() As FileSystemInfo
Try
entries = di.GetFileSystemInfos(strFrom)

If entries.Length = 1 Then
File.Move(txtPath.Text & entries(0).Name, txtPath.Text &
strTo)
lblStatus.Text = "Done"
lblStatus.Visible = True
Else
MsgBox("There was more/less than one file to be renamed from
" & strFrom, MsgBoxStyle.OKOnly)
lblStatus.Text = "Unable"
lblStatus.Visible = True
End If

Catch ex As Exception
MsgBox("There was a problem trying to access the directory " &
txtPath.Text & vbCrLf & _
"The message was: " & vbCrLf & ex.Message, _
MsgBoxStyle.OKOnly & MsgBoxStyle.Exclamation)
lblStatus.Text = "Unable"
lblStatus.Visible = True
End Try
End Sub

You are having issues with security. If you goto Accessories -> Dot Net
Security Wizard you can adjust you the settings for your app. Put it
fully trusted and you'll see that it works. If you need to depoly this
app you'll have to look into security profiles and such for deploying
your app.

Good luck
Chris
 
G

Guest

Chris said:
You are having issues with security. If you goto Accessories -> Dot Net
Security Wizard you can adjust you the settings for your app. Put it
fully trusted and you'll see that it works. If you need to depoly this
app you'll have to look into security profiles and such for deploying
your app.

Good luck
Chris

Hi Chris,

Thanks for this.
A quick note for other users who may fall into the same issue.

On my installation of Visual Studio there was no link for the DotNet
Security Wizard, so alternatively, you may access it via
Control Panel->Admin Tools-> Microsoft .NET Framework Configuration
(dont try Microsoft .NET Framework Wizards).
Once in there select <Runtime Security Policy> and click on <Increase
Assembly Trust>

Thanks again Chris.

Claudio
 
Top