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


C# Web.GetFileByServerRelativeUrl方法代码示例

本文整理汇总了C#中Web.GetFileByServerRelativeUrl方法的典型用法代码示例。如果您正苦于以下问题:C# Web.GetFileByServerRelativeUrl方法的具体用法?C# Web.GetFileByServerRelativeUrl怎么用?C# Web.GetFileByServerRelativeUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Web的用法示例。


在下文中一共展示了Web.GetFileByServerRelativeUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NeedToOverrideFile

 private bool NeedToOverrideFile(Web web, string pageUrl)
 {
     var file = web.GetFileByServerRelativeUrl(pageUrl);
     web.Context.Load(file, f => f.CustomizedPageStatus);
     web.Context.ExecuteQueryRetry();
     return file.CustomizedPageStatus == CustomizedPageStatus.Customized;
 }
开发者ID:skybow,项目名称:PnP-Sites-Core,代码行数:7,代码来源:FileModelProvider.cs

示例2: AddWebPartt

        //sourceWebPartId - Used to update the content of the wikipage with new web part id
        public static bool AddWebPartt(Web web, string serverRelativePageUrl, WebPartEntity webPartEntity, string sourceWebPartId = "")
        {
            bool isWebPartAdded = false;
            try
            {
                Microsoft.SharePoint.Client.File webPartPage = web.GetFileByServerRelativeUrl(serverRelativePageUrl);

                web.Context.Load(webPartPage);
                web.Context.ExecuteQueryRetry();

                LimitedWebPartManager webPartManager = webPartPage.GetLimitedWebPartManager(PersonalizationScope.Shared);

                WebPartDefinition importedWebPart = webPartManager.ImportWebPart(webPartEntity.WebPartXml);
                WebPartDefinition webPart = webPartManager.AddWebPart(importedWebPart.WebPart, webPartEntity.WebPartZone, webPartEntity.WebPartIndex);
                web.Context.Load(webPart);
                web.Context.ExecuteQuery();

                CheckForWikiFieldOrPublishingPageContentAndUpdate(webPart, web, webPartPage, sourceWebPartId);

                isWebPartAdded = true;

            }
            catch (Exception ex)
            {
                System.Console.ForegroundColor = System.ConsoleColor.Red;
                Logger.LogErrorMessage("[AddWebPartt] Exception Message: " + ex.Message);
                System.Console.ResetColor();
                ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, web.Url, "AddWebPart", ex.Message, ex.ToString(), "AddWebPartt()", ex.GetType().ToString());
            }

            return isWebPartAdded;
        }
开发者ID:OfficeDev,项目名称:PnP-Transformation,代码行数:33,代码来源:AddWebPart.cs

示例3: AddWikiPage

        public string AddWikiPage(ClientContext ctx, Web web, string folder, string wikiPageName)
        {
            string wikiPageUrl = "";
            var pageLibrary = web.Lists.GetByTitle(folder);

            ctx.Load(pageLibrary.RootFolder, f => f.ServerRelativeUrl);
            ctx.ExecuteQuery();

            var pageLibraryUrl = pageLibrary.RootFolder.ServerRelativeUrl;
            var newWikiPageUrl = pageLibraryUrl + "/" + wikiPageName;
            var currentPageFile = web.GetFileByServerRelativeUrl(newWikiPageUrl);
            ctx.Load(currentPageFile, f => f.Exists);
            ctx.ExecuteQuery();

            if (!currentPageFile.Exists)
            {
                var newpage = pageLibrary.RootFolder.Files.AddTemplateFile(newWikiPageUrl, TemplateFileType.WikiPage);
                ctx.Load(newpage);
                ctx.ExecuteQuery();
                wikiPageUrl = String.Format("sitepages/{0}", wikiPageName);
            }

            return wikiPageUrl;
        }
开发者ID:NicolajLarsen,项目名称:PnP,代码行数:24,代码来源:Default.aspx.cs

示例4: DeleteFiles

 protected void DeleteFiles(ClientContext clientContext, Web web, string filename, string serverRelatedURL)
 {
     File file = web.GetFileByServerRelativeUrl(serverRelatedURL + filename);
     clientContext.Load(file);
     file.DeleteObject();
     clientContext.ExecuteQuery();
 }
开发者ID:AaronSaikovski,项目名称:PnP,代码行数:7,代码来源:Default.aspx.cs

示例5: ProvisionObjects

        public override void ProvisionObjects(Web web, ProvisioningTemplate template)
        {
            Log.Info(Constants.LOGGING_SOURCE_FRAMEWORK_PROVISIONING, CoreResources.Provisioning_ObjectHandlers_Pages);

            var context = web.Context as ClientContext;

            if (!web.IsPropertyAvailable("ServerRelativeUrl"))
            {
                context.Load(web, w => w.ServerRelativeUrl);
                context.ExecuteQueryRetry();
            }

            foreach (var page in template.PublishingPages)
            {
                var url = String.Format("{0}/Pages/{1}.aspx", web.ServerRelativeUrl, page.PageName);


                if (!url.ToLower().StartsWith(web.ServerRelativeUrl.ToLower()))
                {
                    url = UrlUtility.Combine(web.ServerRelativeUrl, url);
                }


                var exists = true;
                Microsoft.SharePoint.Client.File file = null;
                try
                {
                    file = web.GetFileByServerRelativeUrl(url);
                    web.Context.Load(file);
                    web.Context.ExecuteQuery();
                }
                catch (ServerException ex)
                {
                    if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException")
                    {
                        exists = false;
                    }
                }

                if (exists)
                {
                    if (page.Overwrite)
                    {
                        file.DeleteObject();
                        web.Context.ExecuteQueryRetry();
                        web.AddPublishingPage(page.PageName, page.PageLayoutName, page.Title, page.Content, page.Properties, page.Publish);
                    }

                    //if (file.CheckOutType == CheckOutType.None)
                    //{
                    //    file.CheckOut();
                    //}
                }
                else
                {
                    web.AddPublishingPage(page.PageName, page.PageLayoutName, page.Title, page.Content, page.Properties, page.Publish);

                    
                }

                if (page.WelcomePage)
                {
                    if (!web.IsPropertyAvailable("RootFolder"))
                    {
                        web.Context.Load(web.RootFolder);
                        web.Context.ExecuteQueryRetry();
                    }

                    var rootFolderRelativeUrl = url.Substring(web.RootFolder.ServerRelativeUrl.Length);
                    web.SetHomePage(rootFolderRelativeUrl);
                }

                // Check out the file if needed
                
                
                

                if (page.WebParts != null & page.WebParts.Any())
                {
                    if (!exists)
                    {
                        file = web.GetFileByServerRelativeUrl(url);
                        web.Context.Load(file);
                        web.Context.ExecuteQuery();
                    }
                    file.CheckOut();    
                                    

                    var existingWebParts = web.GetWebParts(url);

                    foreach (var webpart in page.WebParts)
                    {
                        if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == webpart.Title) == null)
                        {
                            WebPartEntity wpEntity = new WebPartEntity();
                            wpEntity.WebPartTitle = webpart.Title;
                            wpEntity.WebPartIndex = (int)webpart.Order;
                            wpEntity.WebPartZone = webpart.Zone;

                            if (!string.IsNullOrWhiteSpace(webpart.ListUrl))
//.........这里部分代码省略.........
开发者ID:psrank,项目名称:PnP,代码行数:101,代码来源:ObjectPublishingPages.cs

示例6: ProvisionObjects

        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                var context = web.Context as ClientContext;

                web.EnsureProperties(w => w.ServerRelativeUrl, w => w.RootFolder.WelcomePage);

                foreach (var page in template.Pages)
                {
                    var url = parser.ParseString(page.Url);

                    if (!url.ToLower().StartsWith(web.ServerRelativeUrl.ToLower()))
                    {
                        url = UrlUtility.Combine(web.ServerRelativeUrl, url);
                    }

                    var exists = true;
                    Microsoft.SharePoint.Client.File file = null;
                    try
                    {
                        file = web.GetFileByServerRelativeUrl(url);
                        web.Context.Load(file);
                        web.Context.ExecuteQuery();
                    }
                    catch (ServerException ex)
                    {
                        if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException")
                        {
                            exists = false;
                        }
                    }
                    if (exists)
                    {
                        if (page.Overwrite)
                        {
                            try
                            {
                                scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0_, url);

                                if (page.WelcomePage && url.Contains(web.RootFolder.WelcomePage))
                                    web.SetHomePage(string.Empty);

                                file.DeleteObject();
                                web.Context.ExecuteQueryRetry();
                                web.AddWikiPageByUrl(url);
                                if (page.Layout == WikiPageLayout.Custom)
                                {
                                    web.AddLayoutToWikiPage(WikiPageLayout.OneColumn, url);
                                }
                                else {
                                    web.AddLayoutToWikiPage(page.Layout, url);
                                }
                            }
                            catch (Exception ex)
                            {
                                scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0_, url);

                            web.AddWikiPageByUrl(url);
                            web.AddLayoutToWikiPage(page.Layout, url);
                        }
                        catch (Exception ex)
                        {
                            scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
                        }
                    }

                    if (page.WelcomePage)
                    {
                        web.RootFolder.EnsureProperty(p => p.ServerRelativeUrl);
                        var rootFolderRelativeUrl = url.Substring(web.RootFolder.ServerRelativeUrl.Length);
                        web.SetHomePage(rootFolderRelativeUrl);
                    }

                    if (page.WebParts != null & page.WebParts.Any())
                    {
                        var existingWebParts = web.GetWebParts(url);

                        foreach (var webpart in page.WebParts)
                        {
                            if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == webpart.Title) == null)
                            {
                                WebPartEntity wpEntity = new WebPartEntity();
                                wpEntity.WebPartTitle = webpart.Title;
                                wpEntity.WebPartXml = parser.ParseString(webpart.Contents.Trim(new[] { '\n', ' ' }));
                                web.AddWebPartToWikiPage(url, wpEntity, (int)webpart.Row, (int)webpart.Column, false);
                            }
                        }
                        var allWebParts = web.GetWebParts(url);
                        foreach (var webpart in allWebParts)
                        {
                            parser.AddToken(new WebPartIdToken(web, webpart.WebPart.Title, webpart.Id));
//.........这里部分代码省略.........
开发者ID:LiyeXu,项目名称:PnP-Sites-Core,代码行数:101,代码来源:ObjectPages.cs

示例7: ProvisionObjects

        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                var context = web.Context as ClientContext;

                web.EnsureProperties(w => w.ServerRelativeUrl, w => w.RootFolder.WelcomePage);

                foreach (var page in template.Pages)
                {
                    var url = parser.ParseString(page.Url);

                    if (!url.ToLower().StartsWith(web.ServerRelativeUrl.ToLower()))
                    {
                        url = UrlUtility.Combine(web.ServerRelativeUrl, url);
                    }

                    var exists = true;
                    File file = null;
                    try
                    {
                        file = web.GetFileByServerRelativeUrl(url);
                        web.Context.Load(file);
                        web.Context.ExecuteQueryRetry();
                    }
                    catch (ServerException ex)
                    {
                        if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException")
                        {
                            exists = false;
                        }
                    }
                    if (exists)
                    {
                        if (page.Overwrite)
                        {
                            try
                            {
                                scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0_, url);

                                string welcomePageUrl = string.IsNullOrEmpty(web.RootFolder.WelcomePage) ? "" : UrlUtility.Combine(web.ServerRelativeUrl, web.RootFolder.WelcomePage);
                                if (!string.IsNullOrEmpty(welcomePageUrl) && url.Equals(welcomePageUrl, StringComparison.InvariantCultureIgnoreCase))
                                    web.SetHomePage(string.Empty);

                                file.DeleteObject();
                                web.Context.ExecuteQueryRetry();
                                this.AddPage(web, url, page, parser);
                                }
                            catch (Exception ex)
                            {
                                scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0_, url);
                            this.AddPage(web, url, page, parser);
                        }
                        catch (Exception ex)
                        {
                            scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
                        }
                    }

                    if (page.WelcomePage)
                    {
                        var rootFolderRelativeUrl = url.Substring(web.ServerRelativeUrl.Length + 1);
                        web.SetHomePage(rootFolderRelativeUrl);
                    }

                    if (page.WebParts != null & page.WebParts.Any())
                    {
                        this.AddWebParts(web, page, parser);
                    }
                    if (page.Security != null)
                    {
                        file = web.GetFileByServerRelativeUrl(url);
                        web.Context.Load(file.ListItemAllFields);
                        web.Context.ExecuteQueryRetry();
                        file.ListItemAllFields.SetSecurity(parser, page.Security);
                    }
                }
            }
            return parser;
        }
开发者ID:skybow,项目名称:PnP-Sites-Core,代码行数:88,代码来源:ObjectPages.cs

示例8: GetWikiPageFile

        protected File GetWikiPageFile(Web web, Folder folder, WikiPageDefinition wikiPageModel, out string newWikiPageUrl)
        {
            var context = folder.Context;

            //if (!string.IsNullOrEmpty(wikiPageModel.FolderUrl))
            //    throw new Exception("FolderUrl property is not supported yet!");

            var pageName = GetSafeWikiPageFileName(wikiPageModel);

            context.Load(folder, l => l.ServerRelativeUrl);
            context.ExecuteQueryWithTrace();

            newWikiPageUrl = folder.ServerRelativeUrl + "/" + pageName;

            TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving file with URL: [{0}]", newWikiPageUrl);
            var file = web.GetFileByServerRelativeUrl(newWikiPageUrl);

            context.Load(file, f => f.Exists);
            context.ExecuteQueryWithTrace();

            if (file.Exists)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Returning existing file");
                return file;
            }

            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "File does not exist. Returning NULL");

            return null;
        }
开发者ID:ReneHezser,项目名称:spmeta2,代码行数:30,代码来源:WikiPageModelHandler.cs

示例9: GetFileContents

        private ProvisioningTemplate GetFileContents(Web web, ProvisioningTemplate template, string welcomePageUrl, ProvisioningTemplateCreationInformation creationInfo, PnPMonitoredScope scope)
        {
            var fullUri = new Uri(UrlUtility.Combine(web.Url, web.RootFolder.WelcomePage));

            var folderPath = fullUri.Segments.Take(fullUri.Segments.Count() - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/');
            var fileName = fullUri.Segments[fullUri.Segments.Count() - 1];

            var webParts = web.GetWebParts(welcomePageUrl);

            var file = web.GetFileByServerRelativeUrl(welcomePageUrl);

            var homeFile = new Model.File()
            {
                Folder = Tokenize(folderPath, web.Url),
                Src = fileName,
                Overwrite = true,
            };

            // Add field values to file

            RetrieveFieldValues(web, file, homeFile);

            // Add WebParts to file
            foreach (var webPart in webParts)
            {
                var webPartxml = TokenizeWebPartXml(web, web.GetWebPartXml(webPart.Id, welcomePageUrl));

                Model.WebPart newWp = new Model.WebPart()
                {
                    Title = webPart.WebPart.Title,
                    Row = (uint)webPart.WebPart.ZoneIndex,
                    Contents = webPartxml
                };
            #if !CLIENTSDKV15
                // As long as we've no CSOM library that has the ZoneID we can't use the version check as things don't compile...
                if (web.Context.HasMinimalServerLibraryVersion(Constants.MINIMUMZONEIDREQUIREDSERVERVERSION))
                {
                    newWp.Zone = webPart.ZoneId;
                }
            #endif
                homeFile.WebParts.Add(newWp);
            }
            template.Files.Add(homeFile);

            // Persist file using connector
            if (creationInfo.PersistBrandingFiles)
            {
                PersistFile(web, creationInfo, scope, folderPath, fileName);
            }
            return template;
        }
开发者ID:rgueldenpfennig,项目名称:PnP-Sites-Core,代码行数:51,代码来源:ObjectPageContents.cs

示例10: GetFileContents

        private ProvisioningTemplate GetFileContents(Web web, ProvisioningTemplate template, TokenParser parser, string welcomePageUrl, ProvisioningTemplateCreationInformation creationInfo, PnPMonitoredScope scope)
        {
            var fullUri = new Uri(UrlUtility.Combine(web.Url, web.RootFolder.WelcomePage));

            var folderPath = fullUri.Segments.Take(fullUri.Segments.Count() - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/');
            var fileName = fullUri.Segments[fullUri.Segments.Count() - 1];

            var webParts = web.GetWebParts(welcomePageUrl);

            var file = web.GetFileByServerRelativeUrl(welcomePageUrl);

            var homeFile = new Model.File()
            {
                Folder = TokenizeUrl(folderPath, parser),
                Src = fileName,
                Overwrite = true,
            };
            // Add field values to file
            //RetrieveFieldValues(web, file, homeFile);

            WebPartsModelProvider webpartsProvider = new WebPartsModelProvider(web);
            var webparts = webpartsProvider.Retrieve(welcomePageUrl, parser);
            homeFile.WebParts.AddRange(webparts);

            template.Files.Add(homeFile);

            // Persist file using connector
            if (creationInfo.PersistBrandingFiles)
            {
                PersistFile(web, creationInfo, scope, folderPath, fileName);
            }
            return template;
        }
开发者ID:skybow,项目名称:PnP-Sites-Core,代码行数:33,代码来源:ObjectPageContents.cs

示例11: DeleteWebPartFile

        public static void DeleteWebPartFile(Web web, string wpFileName)
        {
            try
            {
                Logger.LogInfoMessage(String.Format("Deleting Web Part File: {0} ...", wpFileName), false);

                List wpGallery = web.GetCatalog((int)ListTemplateType.WebPartCatalog);
                Folder wpGalleryRoot = wpGallery.RootFolder;
                web.Context.Load(wpGalleryRoot);
                web.Context.ExecuteQuery();

                string wpFilePath = wpGalleryRoot.ServerRelativeUrl + "/" + wpFileName;
                File wpFile = web.GetFileByServerRelativeUrl(wpFilePath);

                Logger.LogInfoMessage(String.Format("Deleting Web Part File: {0} ...", wpFilePath), false);

                web.Context.Load(wpFile);
                web.Context.ExecuteQuery();

                if (wpFile.ServerObjectIsNull == false)
                {
                    wpFile.DeleteObject();
                    web.Context.ExecuteQuery();

                    Logger.LogSuccessMessage(String.Format("Deleted Web Part File: {0}", wpFilePath), false);
                }
                else
                {
                    Logger.LogErrorMessage(String.Format("DeleteWebPartFile() failed for {0}: Error=File {1} was not found", web.Url, wpFileName), false);
                }
            }
            catch (ServerException ex)
            {
                if (ex.ServerErrorTypeName.Equals("System.IO.FileNotFoundException", StringComparison.InvariantCultureIgnoreCase) == false)
                {
                    Logger.LogErrorMessage(String.Format("DeleteWebPartFile() failed for {0}: Error={1}", web.Url, ex.Message), false);
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage(String.Format("DeleteWebPartFile() failed for {0}: Error={1}", web.Url, ex.Message), false);
            }
        }
开发者ID:OfficeDev,项目名称:PnP-Transformation,代码行数:43,代码来源:Helper.cs

示例12: GetPageFile

        protected File GetPageFile(Web web, Folder folder, string pageName)
        {
            var context = folder.Context;

            context.Load(folder, l => l.ServerRelativeUrl);
            context.ExecuteQueryWithTrace();

            var newWikiPageUrl = folder.ServerRelativeUrl + "/" + pageName;

            var file = web.GetFileByServerRelativeUrl(newWikiPageUrl);

            context.Load(file, f => f.Exists);
            context.ExecuteQueryWithTrace();

            if (file.Exists)
            {
                return file;
            }

            return null;
        }
开发者ID:jashwanth2269,项目名称:spmeta2,代码行数:21,代码来源:ClientWebpartPresenceOnPageDefinitionValidator.cs

示例13: RegisterJStoWebPart

 void RegisterJStoWebPart(Web web, string url, string jsPath)
 {
     Microsoft.SharePoint.Client.File newFormPageFile = web.GetFileByServerRelativeUrl(url);
     LimitedWebPartManager limitedWebPartManager = newFormPageFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
     web.Context.Load(limitedWebPartManager.WebParts);
     web.Context.ExecuteQuery();
     if (limitedWebPartManager.WebParts.Count > 0)
     {
         WebPartDefinition webPartDef = limitedWebPartManager.WebParts.FirstOrDefault();
         webPartDef.WebPart.Properties["JSLink"] = jsPath;
         webPartDef.SaveWebPartChanges();
         web.Context.ExecuteQuery();
     }
 }
开发者ID:tandis,项目名称:PnP,代码行数:14,代码来源:Default.aspx.cs

示例14: ProvisionObjects

        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                var context = web.Context as ClientContext;

                web.EnsureProperties(w => w.ServerRelativeUrl, w => w.RootFolder.WelcomePage);

                // Check if this is not a noscript site as we're not allowed to update some properties
                bool isNoScriptSite = web.IsNoScriptSite();

                foreach (var page in template.Pages)
                {
                    var url = parser.ParseString(page.Url);

                    if (!url.ToLower().StartsWith(web.ServerRelativeUrl.ToLower()))
                    {
                        url = UrlUtility.Combine(web.ServerRelativeUrl, url);
                    }

                    var exists = true;
                    Microsoft.SharePoint.Client.File file = null;
                    try
                    {
                        file = web.GetFileByServerRelativeUrl(url);
                        web.Context.Load(file);
                        web.Context.ExecuteQueryRetry();
                    }
                    catch (ServerException ex)
                    {
                        if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException")
                        {
                            exists = false;
                        }
                    }
                    if (exists)
                    {
                        if (page.Overwrite)
                        {
                            try
                            {
                                scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0_, url);

                                if (page.WelcomePage && url.Contains(web.RootFolder.WelcomePage))
                                    web.SetHomePage(string.Empty);

                                file.DeleteObject();
                                web.Context.ExecuteQueryRetry();
                                web.AddWikiPageByUrl(url);
                                if (page.Layout == WikiPageLayout.Custom)
                                {
                                    web.AddLayoutToWikiPage(WikiPageLayout.OneColumn, url);
                                }
                                else
                                {
                                    web.AddLayoutToWikiPage(page.Layout, url);
                                }
                            }
                            catch (Exception ex)
                            {
                                scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0_, url);

                            web.AddWikiPageByUrl(url);
                            if (page.Layout == WikiPageLayout.Custom)
                            {
                                web.AddLayoutToWikiPage(WikiPageLayout.OneColumn, url);
                            }
                            else
                            {
                                web.AddLayoutToWikiPage(page.Layout, url);
                            }
                        }
                        catch (Exception ex)
                        {
                            scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
                        }
                    }

                    if (page.WelcomePage)
                    {
                        web.RootFolder.EnsureProperty(p => p.ServerRelativeUrl);
                        var rootFolderRelativeUrl = url.Substring(web.RootFolder.ServerRelativeUrl.Length);
                        web.SetHomePage(rootFolderRelativeUrl);
                    }

            #if !SP2013
                    bool webPartsNeedLocalization = false;
            #endif
                    if (page.WebParts != null & page.WebParts.Any())
                    {
                        if (!isNoScriptSite)
                        {
//.........这里部分代码省略.........
开发者ID:OfficeDev,项目名称:PnP-Sites-Core,代码行数:101,代码来源:ObjectPages.cs

示例15: DeleteWebPart

        private static bool DeleteWebPart(Web web, string serverRelativePageUrl, Guid storageKey)
        {
            bool isWebPartDeleted = false;
            LimitedWebPartManager limitedWebPartManager = null;
            try
            {
                var webPartPage = web.GetFileByServerRelativeUrl(serverRelativePageUrl);

                web.Context.Load(webPartPage);
                web.Context.ExecuteQueryRetry();

                limitedWebPartManager = webPartPage.GetLimitedWebPartManager(PersonalizationScope.Shared);
                web.Context.Load(limitedWebPartManager.WebParts, wps => wps.Include(wp => wp.Id));
                web.Context.ExecuteQueryRetry();

                if (limitedWebPartManager.WebParts.Count >= 0)
                {
                    foreach (WebPartDefinition webpartDef in limitedWebPartManager.WebParts)
                    {
                        Microsoft.SharePoint.Client.WebParts.WebPart oWebPart = null;
                        try
                        {
                            oWebPart = webpartDef.WebPart;
                            if (webpartDef.Id.Equals(storageKey))
                            {
                                webpartDef.DeleteWebPart();
                                web.Context.ExecuteQueryRetry();
                                isWebPartDeleted = true;
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.LogErrorMessage("[DeleteMissingWebparts: DeleteWebPart]. Exception Message: " + ex.Message
                                + ", Exception Comments: Exception occured while deleting the webpart", true);
                            ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, web.Url, "Webpart", ex.Message,
                                ex.ToString(), "DeleteWebPart", ex.GetType().ToString(), Constants.NotApplicable);
                        }
                        finally
                        {
                            oWebPart = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage("[DeleteMissingWebparts: DeleteWebPart]. Exception Message: "
                    + ex.Message + ", Exception Comments: Exception occure while fetching webparts using LimitedWebPartManager", true);
                ExceptionCsv.WriteException(Constants.NotApplicable, Constants.NotApplicable, web.Url, "Webpart", ex.Message,
                    ex.ToString(), "DeleteWebPart", ex.GetType().ToString(), Constants.NotApplicable);
            }
            finally
            {
                limitedWebPartManager = null;
            }
            return isWebPartDeleted;
        }
开发者ID:OfficeDev,项目名称:PnP-Transformation,代码行数:58,代码来源:DeleteMissingWebparts.cs


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