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
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