Thursday, April 30, 2009

Why Twitter is a Helpful Tool if You Are or Are Going to Be in IT

If you don't know what Twitter is, here is a link to the Wikipedia article on the service.

If you haven't been living in a cave for the past six months, you've probably noticed that Twitter (http://www.twitter.com) has become the newest Internet application star. Twitter is a way for people to send updates via the web, a mobile phone, or an application on a PC or Mac. I use Twitter, and I find it to be a very useful tool in my line of work. By streamlining how one uses twitter, it can be a useful tool for all IT professionals and aspiring IT professionals. Here's how:


  • Twitter is a way to expand your technical knowledge.

    I follow a number of tweeple (people who use Twitter) who make informative posts about what's on in IT. Not only do I get instant technology news, but I also get posts containing: links to technology how-tos and tips; links to training and webinars; and career tips. It saves me a lot of time from sifting through websites and search engines to find information.

  • Twitter is a way to get assistance with your IT issue.

    Most forums are good tools to use to post questions. Twitter is another tool that you can use to post questions. Based on my experience, I've posted questions to the Twitter community, and more often than not, I got an answer to my question relatively quickly.

    If you've already asked a question in a forum, and your question is not getting a response, you can use Twitter to post a link to the question. If the regular readers of the forum can't answer your questions, perhaps someone in the Twitter community can.

  • Twitter is a way to get publicity for your professional work.

    If you're looking to expand your audience, Twitter is a good tool to use. I've recently started to use Twitter to publish links to my tutorial posts on this blog, and I've noticed a slight increase in my traffic. Other things that I've seen other tweeple post: links to custom applications and SharePoint web parts that they have written; links to web sites that they have designed; and podcasts and videos in which they were involved.

  • Twitter is a way to expand your professional social network, as well as assist with your job search.

    There are a number of IT professionals who use Twitter, and a large number of those tweeple post IT-related content 95% of the time. You can build your network by re-tweeting informative posts, as well as answer questions that other tweeple have posted.

    I've also noticed that a number of small business owners and IT job recruiters use Twitter to post job openings. You can use Twitter to keep abreast of new opportunities.



Do you use Twitter? Do you like Twitter? Can you see a use for Twitter for your profession? Please feel free to post any comments or questions that you have.

P.S. If you use Twitter, and if you are interested, you can follow me on Twitter

Wednesday, April 22, 2009

SharePoint Development Tutorial: Programmatically Deleting All Items from a List

Microsoft Reference Documentation: Microsoft.SharePoint namespace

Sometimes you need a quick way to delete all items from a SharePoint list. You can manually delete each item from the list without writing code, but this can be time-consuming, especially if you have a high quantity of items on the list.


Click the link to download the source code for this post

Licensing and Warranty

You may use the code as you wish - it may be used in commercial or other applications, and it may be redistributed and modified. The code is provided "as-is". No claim of suitability, guarantee, or any warranty whatsoever is provided. By downloading the code, you agree to defend, indemnify, and hold harmless the Author and the Publisher from and against any claims, suits, losses, damages, liabilities, costs, and expenses (including reasonable legal or attorneys' fees) resulting from or relating to any use of the code by you.




You can write code to programmatically remote items from a SharePoint list using the classes in the Microsoft.SharePoint library (namespace). There are two ways that you can delete all the items from the SharePoint list programmatically:

  • Using the DeleteItemById() function of the SPList class

  • Recommended for performance:Building CAML and using the ProcessBatchData() function of the SPSite class



I will demonstrate both approaches. The skill sets required for these approaches are:

  • C# knowledge

  • A general knowledge of the classes in the Microsoft.SharePoint library/namespace

  • A general knowledge of CAML (for approach #2)



Note: This code will only work on a machine on which SharePoint is installed.


Approach #1: Using the DeleteItemById() function of the SPList class


The function DeleteItemById() of the SPList class expects a numeric parameter ID, which is the ID of the item to delete. This code snippet, which is a slightly modified version of a function in Keith Richie's SPPurgeList (http://www.codeplex.com/sppurgelist), demonstrates how to delete all items by capturing the IDs in a hashtable, reading the hashtable, and calling the DeleteItemById() function. In this example, we will be running this on a site called http://mySharePoint/bogus on a list called BogusList. If you want to use this code, you would substitute the site and list names with your respective site and list names.

Sample: Using DeleteItemById() [Opens In Another Window]

The issue with Approach #1 is performance. While it is negligible on a list with a small amount of item, it becomes more noticeable on a list with hundreds of items. Each call to DeleteItemById() takes about 1 second. If you have hundreds of items, this could take a while to run.

Approach #2: Building CAML and using the ProcessBatchData() function of the SPSite class


Passing CAML to the ProcessBatchData() function of the SPWeb class runs faster than caling the DeleteItemById(). The following code snippet demonstrates how to build the CAML (using the StringBuilder) and pass the CAML to the ProcessBatchData() function to delete the items. In this example, we will be running this on a site called http://mySharePoint/bogus on a list called BogusList. If you want to use this code, you would substitute the site and list names with your respective site and list names.

Sample: Using CAML and ProcessBatchData() [Opens In Another Window]

A Note About Using CAML to Delete Items from a Document Library

The code snippet above will work for the lists except for document libraries. If you try to run the code snippet on a document library, you will get an error about file names. The document libraries require an additional parameter called owsfileref. The following link to the code snippet demonstrates how to build the CAML for document libraries.
Sample: CAML for document libraries [Opens In Another Window]

If you have any questions or comments, please feel free to post them, and I will answer the questions to the best of my ability.

Saturday, April 18, 2009

Attention Hackers! Uncle Sam Wants You (to help)!

I apologize for the lack of updates lately. I will be resuming tutorials on Monday.


MSNBC reports that The United States government is looking to hire hackers to help protect cyber networks.

To read the artice: http://www.msnbc.msn.com/id/30280436/