开发者

Sorting files in sharepoint folder (2007)

I am looking for a way to sort files by date (id seems to do the same).

SPFol开发者_运维百科der imageFolder = web.GetFolder(...); ...

I know I have to do this with caml but how?

Thanks


Yes, this should be done with a CAML query. Use the SPQuery class to execute such a query. Use the OrderBy element in order to sort the result set:

<OrderBy>
  <FieldRef Name="yourdatefield" />
</OrderBy>

Example:

SPList list = ... // the list where you images are stored.

SPQuery query = new SPQuery();
query.Folder = imageFolder;
query.Query = "<OrderBy><FieldRef Name=\"Created\" /></OrderBy>";

SPListItemCollection items = list.GetItems(query);

The variable items now contains the contents of the imageFolder sorted by the field "Created".

In order to access the image files use the member File on SPListItem:

foreach (SPListItem item in items)
{
  Console.WriteLine("Filename: " + item.File.Name);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜