PortalSiteMapproviderからアイテムを取得するときにSiteMapNodeからフィールド値を取得する
-
10-12-2019 - |
質問
PortalSiteMapproviderを使ってリストを照会しようとしています。これが私のコードです:
public List<string> GetChachedItems(string webUrl, SPQuery query)
{
SiteMapNodeCollection nodeCollection = new SiteMapNodeCollection();
PortalSiteMapProvider portalProvider = PortalSiteMapProvider.CurrentNavSiteMapProviderNoEncode;
PortalWebSiteMapNode webNode = portalProvider.FindSiteMapNode(webUrl) as PortalWebSiteMapNode;
if (webNode != null)
{
nodeCollection = portalProvider.GetCachedListItemsByQuery(
webNode, "test", query, SPContext.Current.Web);
}
List<string> itemCollection = new List<string>();
foreach(SiteMapNode node in nodeCollection)
{
itemCollection.Add(node.Title);
}
return itemCollection;
}
.
単一のリスト項目のタイトル列を取得することができます。しかし、リスト内の他のフィールドを取得する方法はわかりません。「年齢」という名前の列があるとしましょう。サイトマップノードのどこにありますか?
任意のアイデア?
解決
I saw a Demo in CodePlex at : http://spquerydemo.codeplex.com . It presents an extensive sample code for many ways of querying SharePoint.
I've found the solution.
This Code Works like a BOOM. Instead of "SiteMapNode" object you need "PortalListItemSiteMapNode" for indexer to work.
public List<string> GetChachedItems(string webUrl, SPQuery query)
{
SiteMapNodeCollection nodeCollection = new SiteMapNodeCollection();
PortalSiteMapProvider portalProvider = PortalSiteMapProvider.WebSiteMapProvider;
PortalWebSiteMapNode webNode = ((PortalSiteMapNode)portalProvider.CurrentNode).WebNode;
if (webNode != null)
{
nodeCollection = portalProvider.GetCachedListItemsByQuery(
webNode, "test", query, SPContext.Current.Web);
}
List<string> itemCollection = new List<string>();
var listItemNodes = portalProvider.GetCachedListItemsByQuery(
webNode,
"Test", query, SPContext.Current.Web);
foreach (PortalListItemSiteMapNode node in nodeCollection)
{
itemCollection.Add(node.Title + " " + node["age"]);
}
return itemCollection;
}
他のヒント
You can use Item
property of SiteMapNode
to gets or sets a custom attribute from the Attributes collection or a resource string based on the specified key!
所属していません sharepoint.stackexchange