2012-01-12 70 views
0

我想創建一個程序,我可以保存自己的文件並能夠在打開程序時輸入密碼。一旦我輸入密碼,我就可以訪問,更改並打開我選擇放入的文件。有關我如何做到這一點的任何想法或鏈接?任何幫助是極大的讚賞。我確實嘗試過,但是我得到了UnauthorizedAccessException。我明白了,當它到達: 對於每個mDirectory作爲IO.DirectoryInfo在mNodeDirectory.GetDirectories在TreeView1_BeforeExpand如何創建我自己的Windows資源管理器

    Private mRootPath As String = "C:\Users" 
Property RootPath As String 
    Get 
     Return mRootPath 
    End Get 
    Set(ByVal value As String) 
     mRootPath = value 
    End Set 
End Property 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    Dim mRootNode As New TreeNode 
    mRootNode.Text = RootPath 
    mRootNode.Tag = RootPath 
    mRootNode.Nodes.Add("*DUMMY*") 
    TreeView1.Nodes.Add(mRootNode) 
End Sub 

Private Sub TreeView1_BeforeCollapse(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeCollapse 
    ' clear the node that is being collapsed 
    e.Node.Nodes.Clear() 
    ' add a dummy TreeNode to the node being collapsed so it is expandable 
    e.Node.Nodes.Add("*DUMMY*") 
End Sub 

Private Sub TreeView1_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand 
    ' clear the expanding node so we can re-populate it, or else we end up with duplicate nodes 
    e.Node.Nodes.Clear() 
    ' get the directory representing this node 
    Dim mNodeDirectory As IO.DirectoryInfo 
    mNodeDirectory = New System.IO.DirectoryInfo(e.Node.Tag.ToString) 
    ' add each subdirectory from the file system to the expanding node as a child node 
    For Each mDirectory As IO.DirectoryInfo In mNodeDirectory.GetDirectories 
     ' declare a child TreeNode for the next subdirectory 
     Dim mDirectoryNode As New TreeNode 
     ' store the full path to this directory in the child TreeNode's Tag property 
     mDirectoryNode.Tag = mDirectory.FullName 
     ' set the child TreeNodes's display text 
     mDirectoryNode.Text = mDirectory.Name 
     ' add a dummy TreeNode to this child TreeNode to make it expandable 
     mDirectoryNode.Nodes.Add("*DUMMY*") 
     ' add this child TreeNode to the expanding TreeNode 
     e.Node.Nodes.Add(mDirectoryNode) 
    Next 
End Sub 

末級

順便說一句,我沒有寫在上面的代碼,我想它關閉鏈接我發現

+0

*我得到UnauthorizedAccessException * ...在什麼時候? – IAbstract 2012-01-12 01:54:53

+0

你應該真正專注於你遇到的單個問題,並以這種方式處理問題:你的標題並不反映你所問的問題。有一點背景範圍提出您遇到的具體問題以及發生問題的可疑代碼。您應該始終給出您從網上覆制的代碼的鏈接,以便作者獲得適當的信用。 – IAbstract 2012-01-12 02:01:52

+0

這將有助於瞭解您正在使用的Windows版本。 XP沒有適用於Windows 7的管理默認設置。 – IAbstract 2012-01-12 02:06:20

回答

1

是否有可能您沒有管理權限?

也許你應該嘗試不同的mRootPath 將文件夾添加到c:\ Users需要管理員權限。

+0

嘿,我關閉vs10並以管理員身份重新打開 – TMan 2012-01-12 02:02:33

+0

儘管仍然沒有工作 – TMan 2012-01-12 02:08:07

+0

@Jordan:OPs示例中的代碼不會添加任何文件夾。它只是獲取目錄信息。也許嘗試使用'Directory'靜態方法。獲取'DirectoryInfo'可能會執行一些額外的操作... – IAbstract 2012-01-12 02:13:43

0

要給予您的應用程序管理員權限,請首先進入您的項目屬性,然後單擊Application選項卡中的View Windows Settings按鈕。用<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />替換現有的requestedExecutionLevel標籤。

相關問題