Coldfusion 9 Sharepoint Integration - getListItems

In my previous on the CFSharepoint tag and SharePoint Views we retrieved the meta-data columns for the specified view.

Now that we have the columns of the view we can build a CAML query to restrict what is returned when we get all the items of the list.

getListItems

the getListItems action of the SharePoint tag does pretty much what it says, it gets all the items of the specified list. As mentioned above we can restrict what columns of meta-data are returned by constructing a CAML query. So to get the list of files we can do the following.


<cfsharepoint action="getlistcollection"
username="#username#"
domain="sharepointserver/home/"
password="#password#"
name="ViewCollection"
params="#{listName='{A3EA94F4-9F1B-43A0-B197-085BA1E258C9}',viewName='{93BD49AF-E54D-4186-9062-36BF0751E4F6}'}#"/>


            <cfloop from="1" to="#arrayLen(ViewCollection.view)#" index="iView">
                <cfif structKeyExists(ViewCollection.view[iView],"viewFields")>
                    <cfset aViewFields = ViewCollection.view[iView].viewFields>
<cfsavecontent variable="viewfields">
                    <cfloop from=1 to="#arrayLen(aViewFields)#" index="iFieldName">
                        <cfoutput><FieldRef Name="#aViewFields[iFieldName].Name#"/></cfoutput>
                    </cfloop>
</cfsavecontent>
                    <cfbreak >
                </cfif>
            </cfloop>
<cfset nViewFields = xmlParse("<ViewFields>#viewfields#<FieldRef Name='BaseName'/></ViewFields>",true)>

<cfset nQuery=xmlparse("<Query><Where><Eq><FieldRef Name='FSObjType'/><Value Type='Number'>0</Value></Eq></Where></Query>",true)>
<cfset params ={listName='{A3EA94F4-9F1B-43A0-B197-085BA1E258C9}',viewName='{93BD49AF-E54D-4186-9062-36BF0751E4F6}',
query="#nQuery#",viewfields="#nViewFields#",
rowlimit="",queryoptions="#nQueryOptions#",webid=""}
>


<cfsharepoint action="getListItems"
username="#username#"
domain="sharepointserver/home/"
password="#password#"
name="sharepointFiles"
params="#params#"/>

The variable sharepointFiles should now contain a structure. To make sure that you actually have files you can check the sharepointFiles.listItems.itemCount structkey, it should be a non-zero value, if so then sharepointFiles.listItems will be an array of structures containing all the files in the list.

Getting the Meta-Data

Although you went through the trouble of getting only the columns of meta-data you want from the view there are naturally some extra columns containing important information such as the link to the document in sharepoint, file size and some other info.

To actually get the meta data for the columns you want you have to prefix the names returned from the getView with "ows_" for example "ows_BaseName".


<cfdump var="#sharepointFiles.listItems[1]["ows_BaseName"]#">

Should give you the BaseName of the first document.

Whats Next

Well you have the meta-data for the files, you have the link to the file, but you don't actually have the file yet. You can store all this information in a Database and grab the files later or you can get them right away and store both the original link in sharepoint and a local link for the document. To grab the physical files from SharePoint you can use the cfhttp tag making sure to use the ows_FileRef information, and sadly you have pass the username and password in clear text (at least until cfsharepoint supports ntlnm).

Happy Coding...

0 Comments to "Coldfusion 9 Sharepoint Integration - getListItems"- Add Yours

Powered By Railo

Subscribe

Subscribe via RSS
Follow garyrgilbert on Twitter Follow me on Twitter
Or, Receive daily updates via email.

Tags

adobe air ajax apple cf community cfml coldfusion examples ext flash flex google javascript max2007 max2008 misc open source programming railo software technology ui

Recent Entries

No recent entries.

Blogroll

An Architect's View
CFSilence
Rey Bango
TalkingTree

Wish List

My Amazon.com Wish List