the singularity of being and nothingness
CFSharePoint…Yes!
The other day, I downloaded the beta for ColdFusion 9. While waiting for the download, I was looking through some of the marketing copy that Adobe had on their site about the new features for this release. I about fell off my chair when I saw that not only has ColdFusion 9 increased connectivity to Microsoft’s SharePoint, but they have even built a tag to wrap up the functionality into one nice little package: <cfsharepoint />.
This one little tag is incredibly powerful. It knocks out all of the painful and cumbersome web services wrappings required to deal with SharePoint’s WSDLs. Besides having over 50 built-in functions to deal with lists, document libraries, and the like, you can optionally point to other (or custom) WSDLs to access whatever <cfsharepoint> can’t get at by default.
So after reading about this, I just HAD to try it out. Not surprisingly, ColdFusion makes a routine task like retrieving a list extremely simple. Here’s my test:
<cfset viewFields = xmlParse(" <ViewFields> <FieldRef Name='Title'/> <FieldRef Name='ID'/></ViewFields> ")> <cfset query = xmlParse(" <Query> <OrderBy> <FieldRef Name='ID'/> </OrderBy> </Query> ")> <cfset queryOptions = xmlParse("<QueryOptions></QueryOptions>")> <cfsharepoint action="getlistitems" domain="domain.com" name="spVar" userName="myusername" password="mypassword" params="#{listName="546585D2-7AC4-493F-8DC5-F089B9EEB0AD", viewName="A8720E14-A847-4255-8527-055D2DD97868", query="#query#", rowLimit="20", viewFields="#viewFields#", queryOptions="#queryOptions#", webID="" }#" /> <cfset results="#spVar.listitems.data#"> <h1>Site Punch List</h1> <ul> <cfloop index="i" from="1" to="#arrayLen(results)#"> <li><cfoutput>#results[i].ows_Title#</cfoutput></li> </cfloop> </ul>
This is very straightforward. For supported web service methods, you simple specify the method in the “action” attribute of the <cfsharepoint> tag. In this example, I simply hard-coded my log in credentials, but the tag optionally supports the “login” attribute which can accept a pre-built domain/username/password object. After that, you just specify the required fields for the web service method (which can be found in Microsoft’s web services docs), and you’re good to go.
Simple. The only tricky bit, really, is building out the XML required by some of Microsoft’s methods. However, Microsoft’s documentation of the requirements for these is pretty good, so with a bit of reading you’ll have no trouble at all.
UPDATE: The other day, someone asked a very good question about how to retrive the list/view GUID to use in the cfsharepoint tag. I’m sure there are better ways of doing this, but here’s a quick and dirty way to do it. Hope this helps!
Print article | This entry was posted by existdissolve on July 21, 2009 at 5:19 pm, and is filed under ColdFusion, SharePoint. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about -1917 years ago
Hi Joel, this post was helpful, thanks! I have a question: Have you been able to get a recursive list of items? The docs state "To return all documents in a library, the ViewAttributes element is used as follows: <ViewAttributes Scope="Recursive" />". However, if I change the queryOptions value from "xmlParse(‘<QueryOptions></QueryOptions>’)" to "xmlParse(‘<QueryOptions><ViewAttributes Scope="Recursive" /></QueryOptions>’)", then I get ZERO results.
Just wondered if you’ve ran into this. What I’m really trying to do is get the contents of a subdirectory of Shared Documents. It looks like the only way is via getting a recursive list, starting w/ the parent of the list, and then poking thru the result? If so, that seems to be a strange requirement.
I’d be very thankful for any ideas/thoughts you may have on this.
Thanks!,
-Aaron Neff
about -1917 years ago
I should add that I’ve also tried this, for the value of queryOptions, but the result still only contains the items directly in ‘Shared Documents’:
xmlParse(‘<QueryOptions><ViewAttributes Folder="http://sharepoint.domain.com/Shared Documents/My Sub-Directory"/></QueryOptions>’)
just shaking my head on this one.. it seems that should work, to get the contents of "My Sub-Directory".
about -1917 years ago
Hi Aaron–
I’m glad you found the post to be helpful!
I’ve tried out the ViewAttributes and it seems to work. Here’s my setup:
Shared Documents
—–> Doc1.doc
—–> Doc2.doc
—–> Sub-Folder
——> Doc3.doc
——> Doc4.doc
When I run my query, it returns the listitems XML structure with a flattened view of the 4 files (of course, you can still get at their location in SharePoint through the ows_FileRef attribute…). When I remove the recursive directive, it returns the two documents plus an item for the subfolder.
If it helps, here’s the CF:
<cfset viewFields = xmlParse("<ViewFields><FieldRef Name=’Title’/><FieldRef Name=’ID’/></ViewFields>")>
<cfset query = xmlParse("<Query><OrderBy><FieldRef Name=’ID’/></OrderBy></Query>")>
<cfset queryOptions = xmlParse("<QueryOptions><ViewAttributes Scope=’Recursive’ /></QueryOptions>")>
<cfsharepoint
action="getlistitems"
domain="localhost/sites/xxxx"
userName="xxxx"
password="xxxx"
name="listsVar"
params="#{
listName="0E774169-A5FA-4446-80B3-900C9CAAC741",
viewName="07189E77-17FA-4251-8127-BA28D056CFFA",
query="#query#",
rowLimit="10",
viewFields="#viewFields#",
queryOptions="#queryOptions#",
webID=""
}#"
/>
For the listName argument, I put the parent list GUID (you can get this from the URL when you modify the list properties). For the viewName argument, I used the GUID for the "All Items" view for the root folder.
Hope this helps, and please let me know if this works out.
Thanks!
about -1917 years ago
Thanks very much Joel! I wish I would’ve read your reply earlier 🙂
However, since I was wanting an unflattened result including all files AND directories.. I kept playing and stumbled upon this:
<QueryOptions><Folder /></QueryOptions>
I’m just stumbling along! Your posts were very helpful, so hopefully that discovery is of help to you as well.
Thanks again very much!,
-Aaron