HOME > .NET Framework > Forum > สร้างเมนูแต่ใช้โค้ดเรียกไฟล์ในโฟลล์เดอร์มาเป็นลิสเมนู และแยกประเภทโดย ทำได้ไหมค่ะ ใครรู้ช่วยบอกหน่อยค่ะ vb2010 asp vs2010 vb.net
สร้างเมนูแต่ใช้โค้ดเรียกไฟล์ในโฟลล์เดอร์มาเป็นลิสเมนู และแยกประเภทโดย ทำได้ไหมค่ะ ใครรู้ช่วยบอกหน่อยค่ะ vb2010 asp vs2010 vb.net
Imports System.IO
Imports System.Collections.Generic
Public Class Documnet
Inherits System.Web.UI.Page
Dim PathMSDS As String = "C:\APC\CS1\CS1\REPORT"
Dim myDirInfo As DirectoryInfo
Dim myFolderInfo As DirectoryInfo
Dim arrFolderInfo As Array
Dim _dirFile As String
Dim RootMaster = New Menu
Dim RootMenu = New MenuItem
Dim RootTmp = New MenuItem
Dim SubTmp = New MenuItem
Dim arrMenu() As String
Dim tarray As New ArrayList()
Dim SearchPath As String = "C:\MSDS\"
Sub BuildTree()
Dim strName As String = HttpContext.Current.User.Identity.Name.ToString
Dim rootdir = New DirectoryInfo("C:\APC\CS1\CS1\REPORT")
Dim rootnode = New TreeNode(rootdir.Name, rootdir.FullName)
Dim rootSub = New MenuItem(rootdir.Name, rootdir.FullName)
'DocumentMenu.Items.Add(rootSub)
Menu1.Items.Add(rootSub)
'RecursiveSearch(rootdir, rootSub)
RecursiveSearch2(rootdir, rootSub)
'TreeView1.Nodes.Add(rootnode)
'traversetree(rootdir, rootnode)
End Sub
Private Sub RecursiveSearch(ByRef CurrentMenu, ByRef CurrentSubMenu)
Dim dir As DirectoryInfo
For Each dir In CurrentMenu.GetDirectories
Dim SubMenu As New MenuItem(dir.Name, dir.FullName)
' Dim LstFiles() As String
' LstFiles = Directory.GetFiles("path ")
'For i As Int32 = 0 To LstFiles.Length - 1
' MenuItem(Days.name ,
' Next
CurrentSubMenu.Childitems.add(SubMenu)
RecursiveSearch(dir, SubMenu)
Next
Dim myFile As FileInfo
For Each myFile In CurrentMenu.GetFiles
Dim MenuFile As New MenuItem(Mid(myFile.Name, 1, Len(myFile.Name) - 4), myFile.FullName)
'MsgBox(Menu1.Items.Count)
'MenuFile.NavigateUrl = myFile.FullName
CurrentSubMenu.Childitems.Add(MenuFile)
Next
End Sub
Private Sub RecursiveSearch2(ByRef CurrentMenu, ByRef CurrentSubMenu)
Dim dir As DirectoryInfo
For Each dir In CurrentMenu.GetDirectories
Dim SubMenu As New MenuItem(dir.Name, dir.FullName)
CurrentSubMenu.Childitems.add(SubMenu)
RecursiveSearch(dir, SubMenu)
Next
Dim myFile As FileInfo
For Each myFile In CurrentMenu.GetFiles
Dim MenuFile As New MenuItem(Mid(myFile.Name, 1, Len(myFile.Name) - 4), myFile.FullName)
'MsgBox(Menu1.Items.Count)
'MenuFile.NavigateUrl = myFile.FullName
CurrentSubMenu.Childitems.Add(MenuFile)
Next
End Sub
Private Sub traversetree(ByRef CurrentDir, ByRef CurrentNode)
Dim dir As DirectoryInfo
For Each dir In CurrentDir.GetDirectories
Dim node As New TreeNode(dir.Name, dir.FullName)
CurrentNode.ChildNodes.Add(node)
traversetree(dir, node)
Next
Dim myFile As FileInfo
For Each myFile In CurrentDir.GetFiles
Dim newNode As TreeNode = New TreeNode(myFile.Name, myFile.FullName)
newNode.NavigateUrl = myFile.FullName
CurrentNode.ChildNodes.Add(newNode)
Next
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack = False Then BuildTree()
End Sub
Private Sub DocumentMenu_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs)
MsgBox(sender.ToString & " " & e.Item.Value)
Select Case UCase(Right(e.Item.Value, 4))
Case ".PDF"
Response.ContentType = "Application/pdf"
Case ".DOC"
Case Else
End Select
frame1.Attributes.Add("src", e.Item.Value)
Me.frame1.InnerHtml = e.Item.Value
End Sub
Protected Sub Menu1_MenuItemClick(sender As Object, e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemClick
If UCase(Right(e.Item.Value, 4)) = ".PDF" Then
MultiView1.ActiveViewIndex = 1
frame1.Attributes.Add("src", e.Item.Value)
Else
frame1.Attributes.Add("src", "")
End If
End Sub
Protected Sub lkButtonBack_Click(sender As Object, e As EventArgs) Handles lkButtonBack.Click
MultiView1.ActiveViewIndex = 0
End Sub
End Class