Sharepoint 博客文章:根据发布日期排序

发布于 2024-08-22 07:58:06 字数 202 浏览 9 评论 0原文

我有一个共享点内部网门户,其中有很多博客,并且它们有定制的设计。我们使用默认的数据表单 Web 部件来显示博客文章。默认情况下,帖子根据“创建日期”排序。

客户有一个新要求,要求我将排序标准更改为“发布日期”。在不使用 SharePoint Designer 的情况下实现此目标的最简单方法是什么?

笔记: 创建新视图不是解决方案,因为我无法应用自定义设计。

I have a sharepoint intranet portal which has many blogs and they have customized design. We use default Data form webpart for displaying blog posts. By default the posts are sorted based on "created date".

I have a new requirement from the client asking me to change the sorting criteria to "Published date". What is the easiest method to achieve this without using SharePoint Designer .

Note:
Creating a new view is not a solution as I will not be able to apply the customized design.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凉墨 2024-08-29 07:58:06

为什么不能使用 SharePoint Designer?会快得多。您可能会做的是:

  1. 导出有问题的 Web 部件并将其保存在某处。
  2. 在您最喜欢的文本/xml 编辑器中打开它(我偏爱 Notepad++)
  3. 向下滚动到 节点
  4. 您的订单可能是在此节点内的 CAML 查询中表达。您正在寻找类似这样的内容:

<OrderBy><FieldRef Name=&quot;Created&quot;升序="TRUE"/></OrderBy>

  1. 将“Created”替换为发布日期的内部字段名称,我认为是“PublishingStartDate”
  2. 将 Web 部件导入回其来源页面

Why can't you use SharePoint Designer? It would be much quicker. What you could probably do is:

  1. Export the webpart in question and save it somewhere.
  2. Open it up in your favorite text/xml editor (I'm partial to Notepad++)
  3. Scroll down to the <property name="DataSourcesString" type="string"> node
  4. Your order by is probably being expressed in the CAML query within this node. You're looking for something like this:

&lt;OrderBy&gt;&lt;FieldRef Name=&quot;Created&quot; Ascending=&quot;TRUE"/&gt;&lt;/OrderBy&gt;

  1. Replace "Created" with the internal field name for published date, which I believe is "PublishingStartDate"
  2. Import the webpart back onto the page it came from
很快妥协 2024-08-29 07:58:06

您不能编辑当前视图,以便它按发布日期排序吗? (我以为默认是发布日期..)

Cant you edit the current view, so it sorts by published date? (I thought the default was published date..)

梦醒时光 2024-08-29 07:58:06

您可以导出 webpart 并编辑下载的 .webpart XML 文件中的排序字段吗?

Can you export the webpart and edit the sorting field in the downloaded .webpart XML file?

没企图 2024-08-29 07:58:06

谢谢Zincorp,
我可以按发布日期对帖子进行排序。但我在内网中有20多个博客,而我在生产服务器中没有访问权限。基于Zincorp的解决方案,我需要为每个博客创建新的Web部件或者需要编辑参数值,而这在我的情况下是不可能的。

所以我用另一种方式实现了这一目标。

首先,我创建一个从当前站点读取博客的 Web 部件。

string url = Request.Url.ToString();
             SPSite  site = new SPSite(url.Substring(0, url.LastIndexOf('/')));

使用 CAML 查询我可以读取 &按发布日期对帖子进行排序。

下一个任务是将所有发布数据表单 Web 部件替换为新的 Web 部件。为此,我创建了一个功能,可以获取网站集中的所有博客并使用以下代码替换 Web 部件

using (SPWeb spWebTest = spSiteTest.OpenWeb())
   {
     SPWebPartCollection webparts = spWebTest.GetWebPartCollection("default.aspx", Storage.Shared);
     for (int k = 0; k < webparts.Count; k++)
     {
       //get reference to webpart
       Microsoft.SharePoint.WebPartPages.WebPart wp = webparts[k];

       //check webpart Title to find webpart which is to be removed
       if (wp.Title == "Posts")
       {
         //delete webpart
         webparts.Delete(wp.StorageKey);

         //update spWeb object
         spWebTest.Update();  
                                }                                                                                                                                       }

//create new webpart object            
     WebPartToBeAdded wpNew = new WebPartToBeAdded();      

     //set properties of new webpart object     
     wpNew.ZoneID = "1";     
     wpNew.Title = "LatestPost";     
     wpNew.ChromeState = System.Web.UI.WebControls.WebParts.PartChromeState.Normal;     
     wpNew.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;      

     //add new webpart object to webparts collection     
     webparts.Add(wpNew);      
   }

Thanks Zincorp,
I could sort post by published date. But I have more than 20 blogs in the intranet and I don’t have access in production server. And based on Zincorp’s solution I need to create new web parts for each blog or need to edit the parameter value, and it is not possible in my situation.

So I achieved this in another way.

First I crate a web part that reads the blog from current site.

string url = Request.Url.ToString();
             SPSite  site = new SPSite(url.Substring(0, url.LastIndexOf('/')));

And using the CAML query I could read & sort posts by published date.

The next task is to replace all the post data form web part with the new web part. For this I created a feature that fetch all the blogs in my site collection and replace the web part using below code

using (SPWeb spWebTest = spSiteTest.OpenWeb())
   {
     SPWebPartCollection webparts = spWebTest.GetWebPartCollection("default.aspx", Storage.Shared);
     for (int k = 0; k < webparts.Count; k++)
     {
       //get reference to webpart
       Microsoft.SharePoint.WebPartPages.WebPart wp = webparts[k];

       //check webpart Title to find webpart which is to be removed
       if (wp.Title == "Posts")
       {
         //delete webpart
         webparts.Delete(wp.StorageKey);

         //update spWeb object
         spWebTest.Update();  
                                }                                                                                                                                       }

//create new webpart object            
     WebPartToBeAdded wpNew = new WebPartToBeAdded();      

     //set properties of new webpart object     
     wpNew.ZoneID = "1";     
     wpNew.Title = "LatestPost";     
     wpNew.ChromeState = System.Web.UI.WebControls.WebParts.PartChromeState.Normal;     
     wpNew.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;      

     //add new webpart object to webparts collection     
     webparts.Add(wpNew);      
   }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文