CAML sorting by file name
If you are doing a CAML query and want the results sorted by the file name (and not by title, which may be different than the file name) use the following:
<OrderBy><FieldRef Name='LinkFilenameNoMenu' /></OrderBy>
Sharepoint Tips And Tricks is Ishai Sagi's sharepoint information blog. It specializes in Microsoft SharePoint technologies, including web parts, development, configuration, customization, and best practices for the use of Microsoft SharePoint Server and Windows SharePoint Services. It also provides some related Office Information, including VSTO and VSTA and other office application development tips.
If you are doing a CAML query and want the results sorted by the file name (and not by title, which may be different than the file name) use the following:
<OrderBy><FieldRef Name='LinkFilenameNoMenu' /></OrderBy>
Posted by
Ishai Sagi [SharePoint MVP]
at
10:05 PM
1 comments
Links to this post
Labels: CAML
U2U have released a new version of the U2U CAML Query Builder, and this time it can be installed as a feature, and has a web interface instead of the windows form application it was so far. GREAT!
Check out the post from Karine Bosch.
If you don't know what the CAML Query Builder is, I suggest you start by downloading it (either the new release or the old one) and see how easy it is to write CAML queries with it.
Posted by
Ishai Sagi [SharePoint MVP]
at
10:48 PM
0
comments
Links to this post
Labels: CAML, Features, SharePoint 2007
Another FAQ that I see a lot from developers - they get the error "One of more field types are not installed properly" in their applications.
No, don't blame your database in being corrupt, and don't go beat up the guy who create the list and the fields. The problem is simple:
You'r code is doing a CAML query, and uses a field name that does not exist.
I hear you say "but I checked my CAML query, and the field names are correct", and I have to remind you - field names in CAML queries should be internal names, not display names.
This is why, if you have a field called "Parent Task" (for example), in CAML you should refer to it as "Parent_x0020_Task", because the internal name is encoded to avoid special characters.
Also, the internal name may be totaly different from the display name - this will happen if you created a field and then renamed it. So the internal name remains the same as the old name, but the display name changed.
Another scenario for this is when you created your own list definition, and specified different internal and display names. (this happened to me recently)
So, how to know what is the internal name for your field? simple - just click on it!
Let me elaborate - create a view in the list that has that field, and click on the field to sort the list by it. In the web address (url) of the page you are directed to, the internal name of the field should be displayed, after the query string "SortField=".
If the field does not allow sorting, you can go to the list settings and click on the field, as if you want to change it's settings. Again, the internal name of the field will be in the URL address of the page.
Please note, that the field names in the URLs are encoded again, and you will have to compensate for that. for example, a field with a space like "Parent Task" will not be displayed like I said before in the address bar as "Parent_x0020_Task", but instead as "Parent%5fx0020%5fTask" (the underscore character was replaced by the unicode equivalent "%5f").
So you want an easier way to find the internal name (without coding)?
Just do yourself a huge favour and download U2U CAML Builder which is a terrific application to help you build CAML queries.
Since the tool knows it has to use internal names, it just does it for you!.
I cannot live without this tool
Posted by
Ishai Sagi [SharePoint MVP]
at
10:26 PM
4
comments
Links to this post
Labels: CAML, General SharePoint (All Versions)