private static SortBy[] GetSortOrder(UserContext userContext, Folder folder) { ColumnId columnId = ColumnId.DeliveryTime; SortOrder sortOrder = SortOrder.Descending; WebPartModuleViewState webPartModuleViewState = userContext.LastClientViewState as WebPartModuleViewState; if (webPartModuleViewState != null && folder.Id.ObjectId.Equals(webPartModuleViewState.FolderId)) { sortOrder = webPartModuleViewState.SortOrder; columnId = webPartModuleViewState.SortedColumn; } else if (!userContext.IsWebPartRequest) { using (UserConfiguration folderConfiguration = UserConfigurationUtilities.GetFolderConfiguration("Owa.BasicFolderOption", userContext, folder.Id)) { if (folderConfiguration != null) { IDictionary dictionary = folderConfiguration.GetDictionary(); object obj = dictionary["SortColumn"]; if (obj != null) { columnId = ColumnIdParser.Parse((string)obj); } obj = dictionary["SortOrder"]; if (obj != null) { sortOrder = (SortOrder)obj; } } } } if (!ListViewColumns.IsSupportedColumnId(columnId)) { columnId = ColumnId.DeliveryTime; } SortBy[] result; if (columnId == ColumnId.DeliveryTime) { result = new SortBy[] { new SortBy(ItemSchema.ReceivedTime, sortOrder) }; } else { Column column = ListViewColumns.GetColumn(columnId); result = new SortBy[] { new SortBy(column[0], sortOrder), new SortBy(ItemSchema.ReceivedTime, SortOrder.Descending) }; } return(result); }