Public Class Main
Inherits StaticSiteMapProvider
Dim conn As New ConnectionVB
Dim _rootNode As SiteMapNode = Nothing
Dim _siteMapFileName As String
Dim SiteMapNodeName As String = "siteMapNode"
Public Sub DynamicSiteMapProvider()
End Sub
Public Shadows Function RootNode() As SiteMapNode
Return BuildSiteMap()
End Function
Public Overrides Sub Initialize(name As String, attributes As NameValueCollection)
//Me.Initialize(name, attributes)
_siteMapFileName = attributes("siteMapFile")
End Sub
Protected Overrides Function GetRootNodeCore() As SiteMapNode
Return RootNode()
End Function
Protected Overrides Sub clear()
SyncLock Me
_rootNode = Nothing
//Me.clear()
End SyncLock
End Sub
Public Overrides Function BuildSiteMap() As SiteMapNode
SyncLock Me
If _rootNode Is Nothing Then
clear()
Dim siteMapXml As XmlDocument = LoadSiteMapXml()
Dim rootElement As XmlElement = CType(siteMapXml.GetElementsByTagName(SiteMapNodeName)(0), XmlElement)
AddDynamicNodes(rootElement)
GenerateSiteMapNodes(rootElement)
End If
End SyncLock
Return _rootNode
End Function
Private Function LoadSiteMapXml() As XmlDocument
Dim siteMapXml As XmlDocument = New XmlDocument()
siteMapXml.Load(AppDomain.CurrentDomain.BaseDirectory + _siteMapFileName) //I got an error here
Return siteMapXml
End Function
Protected Sub AddDynamicNodes(rootElement As XmlElement)
Dim teams As XmlElement = AddDynamicChildElement(rootElement, "", "FootballTeams", "List of football team")
End Sub
Protected Function AddDynamicChildElement(parentElement As XmlElement, url As String, title As String, description As String) As XmlElement
Dim childElement As XmlElement = parentElement.OwnerDocument.CreateElement(SiteMapNodeName)
childElement.SetAttribute("url", url)
childElement.SetAttribute("title", title)
childElement.SetAttribute("description", description)
parentElement.AppendChild(childElement)
Return childElement
End Function
Protected Sub GenerateSiteMapNodes(rootElement As XmlElement)
_rootNode = GetSiteMapNodeFromElement(rootElement)
AddNode(_rootNode)
CreateChildNodes(rootElement, _rootNode)
End Sub
Protected Sub CreateChildNodes(parentElement As XmlElement, parentNode As SiteMapNode)
For Each XmlElement As XmlNode In parentElement.ChildNodes
If XmlElement.Name = SiteMapNodeName Then
Dim childNode As SiteMapNode = GetSiteMapNodeFromElement(CType(XmlElement, XmlElement))
AddNode(childNode, parentNode)
CreateChildNodes(CType(XmlElement, XmlElement), childNode)
End If
Next
End Sub
Protected Function GetSiteMapNodeFromElement(rootElement As XmlElement) As SiteMapNode
Dim newSiteMapNode As SiteMapNode
Dim url As String = rootElement.GetAttribute("url")
Dim title As String = rootElement.GetAttribute("title")
Dim description As String = rootElement.GetAttribute("description")
newSiteMapNode = New SiteMapNode(Me, (url + title).GetHashCode().ToString(), url, title, description)
Return newSiteMapNode
End Function
End Class
このコードを実行すると、パスが見つからないという例外がスローされます。
siteMapXml.Load(AppDomain.CurrentDomain.BaseDirectory + _siteMapFileName)
それがエラーをスローするコード行です。
ここにエラーがあります:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'c:\Users\Julian\documents\visual studio 2012\WebSites\WebSite1\'.
そこにブレークポイントを置いてパスを確認しようとしましたが、すでに正しいパスです。
このエラーの原因がわかりません。