TechEd BPR377 Windows SharePoint Services: Programmatic Access to Lists and Document Libraries
Speaker: Bryan Jeffries gave a nice talk about accessing Sharepoint lists (IW400). You'll notice I'm only blogging the good sessions I attend. At a high level he started by mentioning there's 3 ways to access this data:
1. .NET Object Model in the Microsoft.Sharepoint namespace
2. Lists Web Service
3. Frontpage RPC
Bryan had some simple code samples in the slides that we can refer to later. And he says he will upload his other samples, they looked really useful - read on.
Cab files, DWP file, etc can make creating web parts difficult.
We're looking at the WhatsNew web part code that makes up the demo in C#.
There's a Visual Studio .NET web part library wizard available for download from MSDN that gives you a File -> New -> project. The default wizard generated code outputs a single text property. The next thing to do is try it by creating a cab file. You do this by adding a Cab Project (in the setup & deploy tab) to the project. Bryan made a joke about pulling one out of the oven ready and didn't start his build but he opened a precreated cab file. Next he used STSADM -o addwppack to deploy the web part to the sharepoint site. How to do all this is in the readme that's created as part of the wizard project. The web part should now appear in the Virtual Server Gallery and you can add it to a sharepoint web page.
Next we're talking about Lists.aspx the sharepoint list web service. You would use the web service because it gives you a remote way to access the data. office 2003 uses the web services.
Last night this guy created a program to copy a list from one sharepoint site to another. Apparently someone came and asked him at the Cabana's how to copy a list from one sharepoint site to the other. He showed us the UI which shows on the left hand side all the lists on his site in a tree view and lets you drill down to all the items. Then you can drag an item from that treeview and drop it on the destination site on the right hand side.
This app which is about 800 lines of code uses GetListCollection on the sharepoint web service. When you drag the items across he checks that the two lists are based on the same template. Once all the data is all ready he calls UpdateListItems() on the destination sharepoint site. There is no create item, create is a parameter to UpdateListItems().
There are 3 specialised lists in sharepoint. Document, Forms, and Picture which have special features. In addition to the features, document libraries are accessible via DAV.
You can create event handlers for document libraries. This can be used for implementing workflow, and triggering busines logic. They are created as .NET assemblies implementing IListEventSnk and must be installed in the GAC witha strong name. The administrator must enable these per virtual server.
Bryan has a demo of this showing how to get EXIF data from an image file. To create the EXIF picture library you just create a regular picture library list and set the customise list and then advanced settings where you can specify an assembly for events to be fired on. You type in the assembly name and it's found in the Gac. Once you've set all this up you can create a template from this list. We applauded when we saw a photo uploaded and all the EXIF information appeared. The EXIF information came in asynchronously so that the first time we saw the photo it didn't have the EXIF data but when he hit refresh it all appeared.
Update: Bryan kindly sent me the code from this session.