Theory5 Posted December 11, 2008 Report Posted December 11, 2008 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 SubThis is the browse button which opens the folderbrowser.I keep getting a security error, and I have tried to resolve it.Help? Quote
alexander Posted December 12, 2008 Report Posted December 12, 2008 exactly the error please :hyper: Buffy 1 Quote
Theory5 Posted December 13, 2008 Author Report Posted December 13, 2008 Oh, whoops. Yea that would help. :-) I will put it up on monday. Quote
Theory5 Posted January 8, 2009 Author Report Posted January 8, 2009 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 SubEnd Class---------------------------------------when it has this error it hilights the <SerializableAttribute> _ thingThe 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. Quote
Buffy Posted January 8, 2009 Report Posted January 8, 2009 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 Quote
Theory5 Posted January 9, 2009 Author Report Posted January 9, 2009 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? Quote
Buffy Posted January 13, 2009 Report Posted January 13, 2009 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.