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;
}
.
단일 목록 항목의 제목 열을 얻을 수 있습니다.그러나 나는 다른 필드를 목록에서 얻는 방법을 모른다.내가 "나이"라는 열이 있다고 가정 해 봅시다.SiteMapNode에는 어디에 있습니까?
모든 아이디어?
해결책
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