Jump to content
Science Forums

Recommended Posts

Posted

Hey I am new to VB and I am trying to figure out how to find a folder or file in the FolderBrowserDialog and paste it to a text box. so far I have:

 

 

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click

<SerializableAttribute> _

<ComVisibleAttribute(True)> _

<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Constructor Or AttributeTargets.Method, AllowMultiple := True, _

Inherited := False)> _

Public NotInheritable Class FileIOPermissionAttribute _

Inherits CodeAccessSecurityAttribute

 

Dim instance As Security.Permissions.FileIOPermissionAttribute

If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

TextBox1.Text = FolderBrowserDialog1.SelectedPath

End If

 

End Sub

This is the browse button which opens the folderbrowser.

I keep getting a security error, and I have tried to resolve it.

Help?

  • 4 weeks later...
Posted

okay, i have been busy lately so here is the error:

Security Exception was unhandled:

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

 

here is the exact program:

 

--------------------------------------------------------------------------

Imports System.Security.Permissions.FileIOPermission

 

 

Public Class Form1

 

Private Sub saved_files_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

End Sub

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

End Sub

 

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click

<SerializableAttribute> _

<ComVisibleAttribute(True)> _

<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Constructor Or AttributeTargets.Method, AllowMultiple := True, _

Inherited := False)> _

Public NotInheritable Class FileIOPermissionAttribute _

Inherits CodeAccessSecurityAttribute

 

Dim instance As Security.Permissions.FileIOPermissionAttribute

If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

TextBox1.Text = FolderBrowserDialog1.SelectedPath

End If

 

End Sub

 

Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs)

 

End Sub

 

Private Sub FolderBrowserDialog1_HelpRequest(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

End Sub

 

Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click

 

End Sub

 

Private Sub FolderBrowserDialog1_HelpRequest_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FolderBrowserDialog1.HelpRequest

 

End Sub

End Class

---------------------------------------

when it has this error it hilights the <SerializableAttribute> _ thing

The Idea of this is a file browser that allows me to copy and paste files and folders and move them around.

If you guys want to see the whole program I can send you the file just give me your email address.

Posted

First question is why you have a SerializableAttribute tag inside of an event in the first place.

 

If you do have a good reason, then it's quite obvious that there's no permission to write the file, and that's likely to be because you're lacking the serialization tags for the enclosing class and it may be trying to write to a protected location.

 

It is easier to get forgiveness than permission, :shrug:

Buffy

Posted

So then how would I write in the security permissions? I found most of that part in the microsoft visual basic help but it never said where to put them. Do I even need a <SerializableAttribute> _ for what I am doing?

Posted
So then how would I write in the security permissions? I found most of that part in the microsoft visual basic help but it never said where to put them. Do I even need a <SerializableAttribute> _ for what I am doing?

 

If you don't have a specific reason to put the <SerializableAttribute> in, then you shouldn't.

 

There is a security library--called, creatively Security--in the Microsoft .Net runtime that gives you all sorts of programmatic control over creating users, adding groups, defining permissions on files and directories, etc. etc.but none of it will work unless the program is run by someone who has permission to make those changes to the security of the system.

 

What you need to do if you want this to work is 1) figure out where it is trying to write the file and then 2) figure out why *you* don't have permission to write to that location, something that you may or may not have the ability to change. You do this through the Windows Explorer more often than writing code to do it, although as I said, you can if you have a reason to.

 

What is allowed us is disagreeable, what is denied us causes us intense desire, :phones:

Buffy

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...