本文整理匯總了C#中System.Web.SiteMapNode類的典型用法代碼示例。如果您正苦於以下問題:C# SiteMapNode類的具體用法?C# SiteMapNode怎麽用?C# SiteMapNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SiteMapNode類屬於System.Web命名空間,在下文中一共展示了SiteMapNode類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: LoadSiteMapData
// The LoadSiteMapData() method loads site navigation
// data from persistent storage into a DataTable.
DataTable siteMap = LoadSiteMapData();
// Create a SiteMapNodeCollection.
SiteMapNodeCollection nodes = new SiteMapNodeCollection();
// Create a SiteMapNode and add it to the collection.
SiteMapNode tempNode;
DataRow row;
int index = 0;
while (index < siteMap.Rows.Count)
{
row = siteMap.Rows[index];
// Create a node based on the data in the DataRow.
tempNode = new SiteMapNode(SiteMap.Provider,
row["Key"].ToString(),
row["Url"].ToString());
// Add the node to the collection.
nodes.Add(tempNode);
++index;
}
示例2: LoadSiteMapFromStore
protected virtual void LoadSiteMapFromStore()
{
string pathToOpen;
lock (this)
{
// If a root node exists, LoadSiteMapFromStore has already
// been called, and the method can return.
if (rootNode != null)
{
return;
}
else
{
pathToOpen = HttpContext.Current.Server.MapPath("~" + "\\" + sourceFilename);
if (File.Exists(pathToOpen))
{
// Open the file to read from.
using (StreamReader sr = File.OpenText(pathToOpen))
{
// Clear the state of the collections and rootNode
rootNode = null;
siteMapNodes.Clear();
childParentRelationship.Clear();
// Parse the file and build the site map
string s = "";
string[] nodeValues = null;
SiteMapNode temp = null;
while ((s = sr.ReadLine()) != null)
{
// Build the various SiteMapNode objects and add
// them to the ArrayList collections. The format used
// is: URL,TITLE,DESCRIPTION,PARENTURL
nodeValues = s.Split(',');
temp = new SiteMapNode(this,
HttpRuntime.AppDomainAppVirtualPath + "/" + nodeValues[0],
HttpRuntime.AppDomainAppVirtualPath + "/" + nodeValues[0],
nodeValues[1],
nodeValues[2]);
// Is this a root node yet?
if (null == rootNode &&
string.IsNullOrEmpty(nodeValues[3]))
{
rootNode = temp;
}
// If not the root node, add the node to the various collections.
else
{
siteMapNodes.Add(new DictionaryEntry(temp.Url, temp));
// The parent node has already been added to the collection.
SiteMapNode parentNode =
FindSiteMapNode(HttpRuntime.AppDomainAppVirtualPath + "/" + nodeValues[3]);
if (parentNode != null)
{
childParentRelationship.Add(new DictionaryEntry(temp.Url, parentNode));
}
else
{
throw new Exception("Parent node not found for current node.");
}
}
}
}
}
else
{
throw new Exception("File not found");
}
}
}
return;
}