2017-05-12 9 views
0

C#을 사용하여 기본보기 쿼리를 변경하려고했지만 작동하지 않습니다. JSLink 속성을 변경할 수는 있지만 XmlDefinition은 변경할 수 없습니다. 해결 방법에 대한 아이디어 나 내가 잘못하고있는 것에 대한 생각?Sharepoint Online C#/CSOM을 사용하여 WebPart보기 쿼리 변경

var webPart = listWebPart.WebPart. 
clientContext.Load(webPart.Properties); 
clientContext.ExecuteQuery();  
webPart.Properties["XmlDefinition"] = newQuery; 
listWebPart.SaveWebPartChanges(); 
clientContext.Load(listWebPart); 
clientContext.ExecuteQuery(); 

일부 페이지에는 webpart가 있습니다.

+0

사내 구축 형 설치에서는 LimitedWebPartManager를 사용하여 뷰를 조사하고 반사 및 XML 노드 수정으로이를 변경합니다. 샘플 답변 https://sharepoint.stackexchange.com/questions/206309/how-to-modify-xsltlistviewwebpart-xmldefinition-property-using-powershell/212387. 희망이 조금 도움이됩니다. – tinamou

+0

예, 구내에서 변경하기가 더 쉽습니다. 온라인상의 문제가 있습니다. 이미 반사를 시도했는데 null이 반환되었습니다. – Rhonin

답변

0

GetLimitedWebPartManager 기능이 포함 된 페이지의 경우 LimitedWebPartManager도 얻을 수 있습니다 (MSDN). 그런 다음 아래와 같이 LimitedWebPartManager를 사용하여 WebParts를로드 할 수

var page = ctx.Web.GetFileByServerRelativeUrl(pageUrl); 
LimitedWebPartManager wpMgr = page.GetLimitedWebPartManager(Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared); 
ctx.Load(wpMgr.WebParts); 
ctx.ExecuteQuery(); 

이 페이지의 모든 webparts을로드합니다. 이것은 당신이 당신의는 WebPart를 업데이트 도움이 될 것입니다 희망

webPartDef.WebPart.Properties["XmlDefinition"] = newQuery; 
webPartDef.SaveWebPartChanges(); 
webPartDef.CloseWebPart(); 
ctx.ExecuteQuery(); 

:

WebPartDefinition webPartDef = wpMgr.WebParts[webpartIndex]; 
ctx.Load(webPartDef); 
ctx.ExecuteQuery(); 

가 이제 마지막으로 정의를 원하는 속성을 업데이트하고 저장할 수 있습니다 : 당신은 당신이 그것의 인덱스를 사용하여 필요는 WebPart의 WebPartDefinition를 얻을 수 있습니다 properties

관련 문제