当前位置: 首页>>代码示例>>C#>>正文


C# Site.OpenWeb方法代码示例

本文整理汇总了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;
        }
开发者ID:maratbakirov,项目名称:spmeta2,代码行数:47,代码来源:LookupFieldModelHandler.cs

示例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;
        }
开发者ID:Whoopsss,项目名称:spmeta2,代码行数:36,代码来源:LookupFieldModelHandler.cs

示例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;
        }
开发者ID:Uolifry,项目名称:spmeta2,代码行数:52,代码来源:WebModelHandler.cs


注:本文中的Site.OpenWeb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。