Home

This document is a cache from http://www.spidertg.com/cmsv5/images/stories/eBook_Libarary/Developer/Putting%20SharePoint%20to%20Work%20for%20You.pdf


Putting Share Point toWorkfor You

Document source : www.spidertg.com


Dts.TaskResult = Dts.Results.Success
Catch Ex As Exception
' Write out an error
Dts.Events.FireError(1, Ex.TargetSite.ToString(), Ex.Message, "", 0)
' Return gracefully, never return with an
' exception from a script task
Dts.TaskResult = Dts.Results.Failure
End Try
End Sub
Retrieving and Deleting Data with CAML
While the Main subroutine code shown in the preceding section is documented in-line, the following two lines are
worth noting because they add commands to the element to delete all existing records from the Suppliers list. They
also demonstrate how to retrieve list items from SharePoint.
Dim listService As Lists = ListHelper.GetListsService()
ListHelper.AddDeleteAllItemsBatch( _
listService, "Suppliers", xmlDoc, elementSuppliersBatch)
The first line retrieves a Lists object, which is the object you will interact with for all list-based requests. The Lists
class was generated by Visual Studio when you created the web reference. The helper method GetListsService sim-
ply instantiates an instance of the Lists class, then sets the login credentials and the URL:
public static Lists GetListsService() {
Lists listService = new Lists();
listService.Credentials = CredentialCache.DefaultCredentials;
listService.Url = "http://[server]/[site]/_vti_bin/Lists.asmx";
return listService;
}
The second command is a call to the ListHelper, which adds commands to delete all existing list items.
Unfortunately, there is no Truncate statement in CAML, so AddDeleteAllItemsBatch() retrieves all list items in the list
and adds a "Delete" command for each. The following line retrieves all records:
listService.GetListItems(
strListName, null, null, null, "1000000", null, null);
While the details of the GetListItems() function are beyond the scope of this article, if you use it in your own code
you'll most frequently interact with the third argument, which takes a Where CAML clause. However, to return all
records you can simply pass in null.
One trick worth mentioning is that this method retrieves about 20 items by default (or whatever is specified in your
default view). Consequently, you must pass in a large number for the fifth argument (which specifies the maximum
number of results to return) to prevent your results from being limited unexpectedly in production.
The GetListItems() function returns an XML node containing the query results. The AddDeleteAllItemsBatch()
method then loops through these results using the following two lines of code:
24
Putting SharePoint to Work for You, an Internet.com Developer eBook. Copyright 2008, Jupitermedia Corp.
Putting SharePoint to Work for You
[
]







Summary :

Dts.TaskResult = Dts.Results.Success Catch Ex As Exception ' Write out an error Dts.Events.FireError(1, Ex.TargetSite.ToString(), Ex.Message, "", 0) ' Return gracefully, never return with an ' exception from a script task Dts.TaskResult = Dts.Results.Failure End Try End Sub Retrieving and Deleting Data with CAML While the Main subroutine code shown in the preceding section is documented in-line, the following two lines are worth noting because they add commands to the element to delete all existing records from the Suppliers list.


Tags : lists,all,null,list,return,which,retriees,listserice,results,items,sharepoint,following,code





Terms    |    Link pdf-search-files.com    |    Site Map
   |    Content Removal Notice   
   |    Contact   

All books are the property of their respective owners.
Please respect the publisher and the author for their creations if their books copyrighted