本文整理汇总了C#中Site.OpenWebById方法的典型用法代码示例。如果您正苦于以下问题:C# Site.OpenWebById方法的具体用法?C# Site.OpenWebById怎么用?C# Site.OpenWebById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Site
的用法示例。
在下文中一共展示了Site.OpenWebById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTargetWeb
public Web GetTargetWeb(Site site, string webUrl, Guid? webId)
{
var context = site.Context;
if (webId.HasGuidValue())
{
var targetWeb = site.OpenWebById(webId.Value);
context.Load(targetWeb);
context.ExecuteQueryWithTrace();
return targetWeb;
}
else if (!string.IsNullOrEmpty(webUrl))
{
var oldValue = CSOMTokenReplacementService.AllowClientContextAsTokenReplacementContext;
try
{
CSOMTokenReplacementService.AllowClientContextAsTokenReplacementContext = true;
var targetWebUrl = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
{
Value = webUrl,
Context = context
}).Value;
// server relative url, ensure / in the beginning
targetWebUrl = UrlUtility.RemoveStartingSlash(targetWebUrl);
targetWebUrl = "/" + targetWebUrl;
var targetWeb = site.OpenWeb(targetWebUrl);
context.Load(targetWeb);
context.ExecuteQueryWithTrace();
return targetWeb;
}
finally
{
CSOMTokenReplacementService.AllowClientContextAsTokenReplacementContext = oldValue;
}
}
// root web by default
return site.RootWeb;
}
示例2: GetTargetWeb
public Web GetTargetWeb(Site site, LookupFieldDefinition definition)
{
var context = site.Context;
if (definition.LookupWebId.HasGuidValue())
{
var targetWeb = site.OpenWebById(definition.LookupWebId.Value);
context.Load(targetWeb);
context.ExecuteQueryWithTrace();
return targetWeb;
}
else if (!string.IsNullOrEmpty(definition.LookupWebUrl))
{
var targetWebUrl = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
{
Value = definition.LookupWebUrl,
Context = context
}).Value;
// server relative url, ensure / in the beginning
targetWebUrl = UrlUtility.RemoveStartingSlash(targetWebUrl);
targetWebUrl = "/" + targetWebUrl;
var targetWeb = site.OpenWeb(targetWebUrl);
context.Load(targetWeb);
context.ExecuteQueryWithTrace();
return targetWeb;
}
// root web by default
return site.RootWeb;
}