本文整理汇总了C#中Site.OpenWeb方法的典型用法代码示例。如果您正苦于以下问题:C# Site.OpenWeb方法的具体用法?C# Site.OpenWeb怎么用?C# Site.OpenWeb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Site
的用法示例。
在下文中一共展示了Site.OpenWeb方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例3: GetExistingWeb
protected Web GetExistingWeb(Site site, Web parentWeb, string currentWebUrl)
{
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Entering GetExistingWeb()");
var result = false;
var srcUrl = currentWebUrl.ToLower().Trim('/').Trim('\\');
// for self-hosting and '/'
if (parentWeb.Url.ToLower().Trim('/').Trim('\\').EndsWith(srcUrl))
return parentWeb;
var context = parentWeb.Context;
Web web = null;
var scope = new ExceptionHandlingScope(context);
using (scope.StartScope())
{
using (scope.StartTry())
{
web = site.OpenWeb(currentWebUrl);
}
using (scope.StartCatch())
{
}
}
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "ExecuteQuery()");
context.ExecuteQueryWithTrace();
if (!scope.HasException && web != null && web.ServerObjectIsNull == false)
{
TraceService.InformationFormat((int)LogEventId.ModelProvisionCoreCall, "Found web with URL: [{0}]", currentWebUrl);
context.Load(web);
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "ExecuteQuery()");
context.ExecuteQueryWithTrace();
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Exciting GetExistingWeb()");
return web;
}
TraceService.InformationFormat((int)LogEventId.ModelProvisionCoreCall, "Can't find web with URL: [{0}]. Returning NULL.", currentWebUrl);
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Exciting GetExistingWeb()");
return null;
}