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


C# SPWeb.GetPagesLibrary方法代码示例

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


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

示例1: GetFolderByIdForWeb

        /// <summary>
        /// Method to get a folder by his Id
        /// </summary>
        /// <param name="web">Explicitly specify the SPWeb</param>
        /// <param name="folderId">the Id of the folder</param>
        /// <returns>The folder or throw an exception if not found</returns>
        public SPFolder GetFolderByIdForWeb(SPWeb web, int folderId)
        {
            SPListItem item = web.GetPagesLibrary().GetItemById(folderId);

            if (item == null || item.Folder == null)
            {
                throw new KeyNotFoundException(string.Format(CultureInfo.InvariantCulture, "Folder key <{0}> was not found.", folderId));
            }

            return item.Folder;
        }
开发者ID:GAlexandreBastien,项目名称:Dynamite-2010,代码行数:17,代码来源:FolderRepository.cs

示例2: Create

        /// <summary>
        /// Creates a page in the Pages library
        /// </summary>
        /// <param name="web">The current web</param>
        /// <param name="folderId">The folder in which to add the item</param>
        /// <param name="pageInfo">The pageInfo of the page</param>
        /// <returns>The newly created publishing page</returns>
        public PublishingPage Create(SPWeb web, int folderId, PageInfo pageInfo)
        {
            PublishingPage newPage = null;
            bool userHavePermissions = false;

            // get the root folder if no folder is specified
            var folder = folderId == int.MinValue ? web.GetPagesLibrary().RootFolder : this.folderRepository.GetFolderByIdForWeb(web, folderId);

            // if spfolder is root folder, check permissions at library level
            if (folder.Item == null)
            {
                userHavePermissions = folder.DocumentLibrary.DoesUserHavePermissions(SPBasePermissions.AddListItems);
            }
            else
            {
                userHavePermissions = folder.Item.DoesUserHavePermissions(SPBasePermissions.AddListItems);
            }

            if (userHavePermissions)
            {
                using (new Unsafe(web))
                {
                    var requestedContentType = web.AvailableContentTypes[pageInfo.ContentTypeId];

                    if (requestedContentType != null)
                    {
                        if (pageInfo.PageLayout != null)
                        {
                            var publishingWeb = PublishingWeb.GetPublishingWeb(web);

                            if (!pageInfo.Name.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase))
                            {
                                pageInfo.Name += ".aspx";
                            }

                            newPage = publishingWeb.GetPublishingPages().Add(folder.ServerRelativeUrl + "/" + pageInfo.Name, pageInfo.PageLayout);
                            newPage.ListItem[BuiltInFields.ContentType.InternalName] = requestedContentType.Name;
                            newPage.ListItem[BuiltInFields.ContentTypeId.InternalName] = requestedContentType.Id;

                            if (pageInfo.Values != null)
                            {
                                foreach (var field in pageInfo.Values)
                                {
                                    newPage.ListItem[field.FieldName] = field.Value;
                                }
                            }

                            if (pageInfo.IsWelcomePage)
                            {
                                folder.WelcomePage = newPage.ListItem.Name;
                                folder.Update();
                                EnsureFolderPublish(folder);

                                if (folder.UniqueId == newPage.ListItem.ParentList.RootFolder.UniqueId)
                                {
                                    // We are setting the Pages library's root folder's welcome page, so let's assume this means we also need to set it as the website's welcome page as well
                                    var webRootFolder = newPage.ListItem.ParentList.ParentWeb.RootFolder;
                                    webRootFolder.WelcomePage = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", publishingWeb.PagesListName, newPage.Name);
                                    webRootFolder.Update();

                                    EnsureFolderPublish(folder);
                                }
                            }

                            newPage.ListItem.Update();
                        }
                    }
                }
            }

            return newPage;
        }
开发者ID:GSoft-SharePoint,项目名称:Dynamite-2010,代码行数:79,代码来源:PageCreator.cs


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