views:

302

answers:

4

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.

A: 

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

Danielvg
We have used Data form webpart for meeting the design requirement. The default sorting is based on created date. Changing the sorting field we need to edit this page in sharepoint designer, so we look for an alternate method.
Hojo
+2  A: 

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:

&amp;lt;OrderBy&amp;gt;&amp;lt;FieldRef Name=&amp;quot;Created&amp;quot; Ascending=&amp;quot;TRUE&quot;/&amp;gt;&amp;lt;/OrderBy&amp;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
zincorp
There are two problems with sharepoint designer1. The page will unghost, when it edited with sharepoint designer2. We have more the 20 blogs in this site and we don't have access in production site (to edit in SPD). So that SPD is not a good choice for us.
Hojo
Fair enough. The solution I presented will work without SPD though
zincorp
Thanks Zincorp, with your solution I could sort post by published date. And I need to do it all the blogs in this intranet. But this webpart is not working in other site? do you have any idea about it? Since I dont have access in production so I studied how to write code for opening all the blog site and delete the existing data form webpart and add the new webpart.
Hojo
A: 

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

Hinek
can you explain littile more?
Hojo
I'm not sure about the webpart you are talking about, but you can export most webparts, clicking on button on the top-right of the webpart and choosing "Export". You save the .webpart File and open it in a text editor, it's XML. Set or change the property you need. Then you click "Add a Web Part" on the SharePoint page, choose "Advanced web part gallery and options" click on "Browse" and change it to "Import", browse the edited file and click "Upload".
Hinek
Thanks Hinek, with your solution I could sort post by published date. And I need to do it all the blogs in this intranet. But this webpart is not working in other site? do you have any idea about it? Since I dont have access in production so I studied how to write code for opening all the blog site and delete the existing data form webpart and add the new webpart.
Hojo
Now you lost me ... you don't have access to the production portal but you can run code on it to delete and add webparts?
Hinek
A: 

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);      
   }
Hojo