locked
Ordering PDF's RRS feed

  • Question

  • Hi

    I have uploaded multiple PFD's that are named by date, eg. July 2000, April 2000, May 2000. I want these to be displayed according to a calendar year, ie. from Jan to Dec.

    How can this be achieved?

    • Moved by Mike Walsh FIN Thursday, August 25, 2011 12:14 PM admin q (From:SharePoint - General Question and Answers and Discussion (pre-SharePoint 2010))
    Thursday, August 25, 2011 12:06 PM

Answers

  • Hi,

    This can be done very easily. Follow these steps:

    1. Go to the settings of the document library.

    2. Create a column type of dateTime.

    3. Execute a console application that will copy the title mentioned into this column by converting it to the form.

    4. Now create a view or you can modify the existing view and you can use .

    5. Now go to view settings and under sort select this created column.

    I hope this will help you out.


    Thanks, Rahul Rashu
    Thursday, August 25, 2011 12:50 PM
  • Hi,

    I have developed the code for console application as per your need and I have tested it in my dev box also. It is running fine there as well.

    These are some points before we go to the code:

    1. The document library I created with name SortDateDocs

    2. The column of type datetime is created as SortDateUse SHIFT+ENTER to open the menu (new window)..

    Now here is the code

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using Microsoft.SharePoint;

    using System.Collections.Specialized;

    using System.Collections;

     

    namespace RahulDateSort

    {

        class RahulData

        {

            static void Main(string[] args)

            {

                using (SPSite site = new SPSite("YourSiteURL"))

                {

                    SPWeb web = site.OpenWeb();

                    SPDocumentLibrary documentLibrary =(SPDocumentLibrary) web.Lists["SortDateDocs"];

                    String title = string.Empty;

                    String month = string.Empty;

                    String year = string.Empty;

                    string[] comb = null;

                    Hashtable months = new Hashtable();

                    months.Add("January", "1");

                    months.Add("February", "2");

                    months.Add("March", "3");

                    months.Add("April", "4");

                    months.Add("May", "5");

                    months.Add("June", "6");

                    months.Add("July", "7");

                    months.Add("August", "8");

                    months.Add("September", "9");

                    months.Add("October", "10");

                    months.Add("November", "11");

                    months.Add("December", "12");

                    String monthNumber = string.Empty;

                    String fullDate = string.Empty;

                    foreach (SPListItem item in documentLibrary.Items)

                    {

                        title = (String) item["Title"];

                        comb = title.Split(' ');

                        month = comb[0];

                        year = comb[1];

                        monthNumber = (String)months[month];

                        fullDate = "01/" + monthNumber + "/" + year;

                        DateTime date = Convert.ToDateTime(fullDate);

                        item["SortDate"] = date;

                        item.Update();

     

                    }

                }

            }

        }

    }

     

    I hope this will help you out.

    If anything is not clear for you in this code do let me know.


    Thanks, Rahul Rashu
    Thursday, August 25, 2011 5:21 PM

All replies

  • You'll need to create a calculated column in the library that extracts the year from the title.  You can then create a view that sorts and groups by that column.  A second column that contains just the Month (converted to a number) would allow a secondary sort by month.
    Paul Stork SharePoint Server MVP Chief SharePoint Architect: Sharesquared Blog: http://dontpapanic.com/blog Twitter: @pstork
    Thursday, August 25, 2011 12:15 PM
  • Is there a 'How to' on the above?
    Thursday, August 25, 2011 12:31 PM
  • Hi,

    This can be done very easily. Follow these steps:

    1. Go to the settings of the document library.

    2. Create a column type of dateTime.

    3. Execute a console application that will copy the title mentioned into this column by converting it to the form.

    4. Now create a view or you can modify the existing view and you can use .

    5. Now go to view settings and under sort select this created column.

    I hope this will help you out.


    Thanks, Rahul Rashu
    Thursday, August 25, 2011 12:50 PM
  • How do I do step 3.

    Execute a console application that will copy the title mentioned into this column by converting it to the form.

     

    Thanks

    Thursday, August 25, 2011 1:04 PM
  • Hey Vasu,

     

    Assumption:

    Title column value is in format of Jan XXXX , April XXXX ... etc

     

    1. Create a Custom Calculated custom in List, you can name is like.... Ordering or whatever you like

    2. Add Formula by selecting the column as below

       =MONTH([Title])

     

    3. Click ok.

    4. Modify the required view, and set the sorting / grouping for above custom calculated column u created.

     

    Let us know if you need some more help on this.


    Thanks
    Akhilesh Nirapure
    Thursday, August 25, 2011 1:59 PM
  • Hi,

    I have developed the code for console application as per your need and I have tested it in my dev box also. It is running fine there as well.

    These are some points before we go to the code:

    1. The document library I created with name SortDateDocs

    2. The column of type datetime is created as SortDateUse SHIFT+ENTER to open the menu (new window)..

    Now here is the code

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using Microsoft.SharePoint;

    using System.Collections.Specialized;

    using System.Collections;

     

    namespace RahulDateSort

    {

        class RahulData

        {

            static void Main(string[] args)

            {

                using (SPSite site = new SPSite("YourSiteURL"))

                {

                    SPWeb web = site.OpenWeb();

                    SPDocumentLibrary documentLibrary =(SPDocumentLibrary) web.Lists["SortDateDocs"];

                    String title = string.Empty;

                    String month = string.Empty;

                    String year = string.Empty;

                    string[] comb = null;

                    Hashtable months = new Hashtable();

                    months.Add("January", "1");

                    months.Add("February", "2");

                    months.Add("March", "3");

                    months.Add("April", "4");

                    months.Add("May", "5");

                    months.Add("June", "6");

                    months.Add("July", "7");

                    months.Add("August", "8");

                    months.Add("September", "9");

                    months.Add("October", "10");

                    months.Add("November", "11");

                    months.Add("December", "12");

                    String monthNumber = string.Empty;

                    String fullDate = string.Empty;

                    foreach (SPListItem item in documentLibrary.Items)

                    {

                        title = (String) item["Title"];

                        comb = title.Split(' ');

                        month = comb[0];

                        year = comb[1];

                        monthNumber = (String)months[month];

                        fullDate = "01/" + monthNumber + "/" + year;

                        DateTime date = Convert.ToDateTime(fullDate);

                        item["SortDate"] = date;

                        item.Update();

     

                    }

                }

            }

        }

    }

     

    I hope this will help you out.

    If anything is not clear for you in this code do let me know.


    Thanks, Rahul Rashu
    Thursday, August 25, 2011 5:21 PM
  • Our solution to this problem was to add a date field and force the users to fill it up. If you can't programm, my proposal is to use excel!

    You add the date field (date only i.e. MYDATE) and then export to xls. In there you can:

    a) either put the values yourself at the feld MYDATE, much faster

    b) make an xls formula to calculate the field MYDATE, accoarding to filename.

    Now, the tricky part: You go to Sharepoint and show the list in spreadsheet mode! Assuming that the xls and the list in spreadsheet mode are in the same order, you copy-paste the column MYDATE !!!

     


    Christos
    Thursday, August 25, 2011 7:36 PM
  • Thanks to all for your assistance. I have solved the problem.

     

     

    Wednesday, September 14, 2011 9:17 AM