Fringe SharePoint Continued
Site Sections
Home
Contact
Syndication
Login
Posts
48
Comments
32
Trackbacks
0
<< Unexpected WCF web Service Behaviour
|
Home
|
Mission Imposible Part 1 (introduction) >>
Extending SharePoint: Checking if a List exists (Web Services)
During my project that is heavily centered around web services, I often found that before I could execute one overall integration, I would need about 3 or 4 web Service calls to collect all the parameters I needed to actually call the web service call I was really trying to execute. I came across an interesting situation where I need to retrieve the List from SharePoint. A web service call will send back an XMLElement with all the information available for a list. The problem is that the list needs to exist for a web service call to succesfully execute. If the list does not exist then it will return an exception.
This is more along the lines of what I was implementing: (the object '_service' is the the instantiated ListSoapClient that is available through WCF to make my calls)
private XmlElement GetListWSCall(string listName)
{
XmlElement retval = null;
try
{
retval = _service.GetList(listName);
}
catch (Exception ex)
{
retval = null;
}
return retval;
}
The problem with this is that if the Library does not exist it will be handled by an exception. Bill Simser wrote a
good article
on this already, so please read his blog post about this issue. What I would like to point out is my solution for the web service call not the object model he worked with. Same concept though.
I wrote a method as well that would check if the List exited in SharePoint. I simply got all the lists for a given endpoint and then used Linq to get at the document library name. It looks like this:
public bool DocLibExists(string listName)
{
try
{
var allLists = _service.GetListCollection();
return allLists.ChildNodes.OfType<XmlElement>().ToList().Exists(x => x.Attributes["Title"].Value ==listName);
}
catch (Exception ex)
{
//handle whatever connection error you might get form the web service call.
}
return false;
}
I have really replaced all of my "foreach" statements and even the typical Linq statments by this somewhat daisy chain of linq query calls. It makes for tighter code as long as the daisy chain does not get huge. Your result set you get back is really an XmlElement with child nodes that are represent a list in SharePoint. All you are really after in this scenario is the "Attributes". When you debug and inspect the XmlElement you can take a look at all the Attributes and adjust your code accordingly to get what you are really after.
That's all for now, More to come!
Juan
Share This Post:
Short Url:
http://wblo.gs/Yub
posted on Wednesday, August 19, 2009 5:39 PM
Print
Comments
#
re: Extending SharePoint: Checking if a List exists (Web Services)
Duy Lam
8/20/2009 6:20 AM
That's another nice way to check. But I prefer not to use LINQ because it can help your code run on .NET 2.0 :-)
#
re: Extending SharePoint: Checking if a List exists (Web Services)
Brendan
8/24/2009 8:35 AM
It's a good idea to always use a finally{} for disposing your try/catch.
Post Comment
Title
*
Name
*
Email
Url
Comment
*
Remember Me?
Enter the code shown above
Archives
March, 2012 (3)
February, 2012 (3)
August, 2011 (2)
July, 2011 (1)
June, 2011 (1)
May, 2011 (2)
April, 2011 (2)
March, 2011 (2)
January, 2011 (1)
December, 2010 (1)
November, 2010 (3)
October, 2010 (4)
August, 2010 (1)
June, 2010 (1)
May, 2010 (1)
April, 2010 (1)
March, 2010 (2)
February, 2010 (2)
January, 2010 (2)
December, 2009 (1)
November, 2009 (3)
September, 2009 (2)
August, 2009 (3)
July, 2009 (4)
Post Categories
SharePoint
TFS
Development
Web Parts
Workflow
ALM
SharePointUserGroup
BUGS
Twitter
juan_larios
http://t.co/kJeXYd5S
This is extremely problematic for legal firms that need historical workflow data past 60 days. I built a custom...
about 17 hours ago
juan_larios
Headed to the first training session of my professional career! Although I will be working during the sessions
http://t.co/miYzvPHs
about 10 days ago
juan_larios
"is that Brandy? She's not dead?" -
@RuddyWine
about 11 days ago
juan_larios
Wasted half the day today catching up on all my favorite tv shows. Much needed down time!
about 12 days ago
juan_larios
Late night…working, wish the day had 35 hours.
about 15 days ago
juan_larios
Did you know, when developing
#SharePoint
Workflows in VS2010 the Event Receiver of feature receiver interferes with the workflow receiver?
about 15 days ago
juan_larios
http://t.co/9jDDpF4W
There are a couple of things you can do to optimize this. First, you have two Round trips in this call. Since you...
about 15 days ago
juan_larios
What a busy week! Glad it's the weekend and I can refresh.
about 27 days ago
juan_larios
I'm at Mulligans Restaraunt
http://t.co/c2HJQGuy
about 27 days ago
juan_larios
@robertregnier
I'm coming after you! I'm still getting used to the game! but getting closer and closer! I need re-string my raquet now!
about 35 days ago
Tag Cloud
cloud computing
SharePoint 2007
SP 2010
visual studio 2008
Copyright © 2005 juanlarios
This work is licensed under a
Creative Commons License