Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Sorting documents in the document library

  Asked By: Damien    Date: Oct 26    Category: Sharepoint    Views: 1856

By default, the documents sort by title. I would like them to sort by
date. Does anyone know which file needs to be configured. Thanks.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Vinod Kumar     Answered On: Oct 26

After much head banging, I have come up with a solution. The 2 files
that need to be modified are TahoeUtils.asp and miscFunctions.js. In
TahoeUtils.asp look for this section of code:

Dim strOrderByClause
strOrderByClause = Request.Cookies(g_strSortByCookieId)
If strOrderByClause = "" Then
strOrderByClause =
"""urn:schemas-microsoft-com:office:office#Title"" ASC"
End If

Change it to:

Dim strOrderByClause
strOrderByClause = Request.Cookies(g_strSortByCookieId)
If strOrderByClause = "" Then
strOrderByClause = """DAV:getlastmodified"" DESC"
End If

Then look for this code:

Dim strPropertyUri, fAscending
GetOrderByPropertyAndDirectionFromCookie strPropertyUri,
fAscending
If Err.Number <> 0 Then SaveCurrentErrorContext
"GetCombinedCategoryInfoAndItemsQueryResults() - Error getting ORDER
BY propery name and direction." : Exit Sub
If IsEmpty(strPropertyUri) Then strPropertyUri =
"urn:schemas-microsoft-com:office:office#Title" ' If no
cookie is
set, it's order by title

Change it to:

Dim strPropertyUri, fAscending
GetOrderByPropertyAndDirectionFromCookie strPropertyUri,
fAscending
If Err.Number <> 0 Then SaveCurrentErrorContext
"GetCombinedCategoryInfoAndItemsQueryResults() - Error getting ORDER
BY propery name and direction." : Exit Sub
If IsEmpty(strPropertyUri) Then strPropertyUri =
"DAV:getlastmodified" ' If no cookie is set, it's order by
date

This code is in the file  twice. One for Categories, one for Document
Library. I changed both since I wanted both to sort  by date.

Once this change has been made, the "Date" link will be highlighted
when you either go to the document  Library or when you do a Category
search. The documents  will be listed in DESC order, but the up arrow
will be displayed. In order to fix this, as well as making sure that
the sorting  works properly, find the following code in TahoeUtils.asp:

Sub GetOrderByPropertyAndDirectionFromCookie(strPropertyUri,
fAscending)
On Error Resume Next

Dim strOrderByClause
strOrderByClause = Request.Cookies(g_strSortByCookieId)
If Len(strOrderByClause) <= 0 Then
strPropertyUri = Empty
fAscending = True
Exit Sub
End If

Change fAscending = True to fAscending = False

Then we need to alter the miscFunctions.js file. Find this code:

function setSortByAuthor( fUseForm )
{
var strOrderByPropList = GetCookie(
g_strSortByCookieId );
if ( g_strSearchSortByAuthor + g_strSearchSortDesc ==
strOrderByPropList )
{
strOrderByPropList = g_strSearchSortByAuthor
+ g_strSearchSortAsc;
}
else
{
strOrderByPropList = g_strSearchSortByAuthor
+ g_strSearchSortDesc;
}
document.cookie = g_strSortByCookieId + "=" +
strOrderByPropList;
reloadPage( fUseForm, true );
}

Just change all Desc to Asc and all Asc to Desc.

function setSortByAuthor( fUseForm )
{
var strOrderByPropList = GetCookie(
g_strSortByCookieId );
if ( g_strSearchSortByAuthor + g_strSearchSortAsc ==
strOrderByPropList )
{
strOrderByPropList = g_strSearchSortByAuthor
+ g_strSearchSortDesc;
}
else
{
strOrderByPropList = g_strSearchSortByAuthor
+ g_strSearchSortAsc;
}
document.cookie = g_strSortByCookieId + "=" +
strOrderByPropList;
reloadPage( fUseForm, true );
}

 
Answer #2    Answered By: Jeffery Hayes     Answered On: Oct 26

I made a mistake on the last section (miscFunctions.js). Here is the
corrected code:

Then we need to alter the miscFunctions.js file. Find this code:

function setSortByDate( fUseForm )
{
var strOrderByPropList = GetCookie(
g_strSortByCookieId );
if ( g_strSearchSortByDate + g_strSearchSortDesc ==
strOrderByPropList )
{
strOrderByPropList = g_strSearchSortByDate +
g_strSearchSortAsc;
}
else
{
strOrderByPropList = g_strSearchSortByDate +
g_strSearchSortDesc;
}
document.cookie = g_strSortByCookieId + "=" +
strOrderByPropList;
reloadPage( fUseForm, true );
}

Just change all Desc to Asc and all Asc to Desc.

function setSortByDate( fUseForm )
{
var strOrderByPropList = GetCookie(
g_strSortByCookieId );
if ( g_strSearchSortByDate + g_strSearchSortAsc ==
strOrderByPropList )
{
strOrderByPropList = g_strSearchSortByDate +
g_strSearchSortDesc;
}
else
{
strOrderByPropList = g_strSearchSortByDate +
g_strSearchSortAsc;
}
document.cookie = g_strSortByCookieId + "=" +
strOrderByPropList;
reloadPage( fUseForm, true );
}

 
Didn't find what you were looking for? Find more on Sorting documents in the document library Or get search suggestion and latest updates.




Tagged: