Monday, October 26, 2009

Adding a SlideShow to a SharePoint Site Redux

One of my most popular posts on this blog was a tutorial on adding a slide show to a SharePoint site using HTML, JavaScript and the Content Editor Web Part. If you haven't had a chance to view that tutorial, you can view it at this link: Add a SlideShow to the SharePoint Site using HTML, JavaScript, and the CEWP.

Just as it was one of my most popular tutorials, it was the one that seemed to cause trouble for some of the readers. Two of the most popular questions that I received were:

  • Why am I only getting the first image?

  • Why am I getting red X's?



I created this separate post to address troubleshooting the application.

Check Your Browser Version
Common Symptom: The first picture displays but the slide show doesn't play

To give you more information on the tutorial, I tested the tutorial on the following browsers:

  • Internet Explorer 6

  • Internet Explorer 7

  • Firefox 3.1x

  • Firefox 3.5x

  • Opera 0.9x


I've noticed that in some of the browsers, the comments in the JavaScript caused it to only show the first picture only. Try removing the comments from the JavaScript.


If you're not using the browsers that I've used to test the code, test the code in a stand-alone "test" web page to see if the browser supports the JavaScript. If you do that, make sure that you comment out the _spBodyOnLoadFunctionNames.push("runSlideShow"); line. If the code is not working, it's possible that your browser will not support the JavaScript code.


Also check the user's browser settings. The browser settings may be configured to not run JavaScript. If that's the case, then the script won't run.


Check Your Code

Common Symptom: The first picture displays but the slide show doesn't play; red X's appear instead of images

When I was assisting people with the slide show, I found two common problems:


  • Coders forgot to add the _spBodyOnLoadFunctionNames.push("runSlideShow"); statement before the ending </script> tag

  • Coders were not referencing the correct location for the images


Make sure that the _spBodyOnLoadFunctionNames.push("runSlideShow"); line appears before the closing </script> tag.

If the _spBodyOnLoadFunctionNames.push("runSlideShow"); statement is there, check to make sure that your path to reference the pictures is exactly right (the src property in the <img> tag). If you are having trouble with using the relative path, try referencing the absolute path (ex: http://www.bogus.com/images/image.jpg). If you are still getting the red X, it's possible that the image does not exist where you are referencing.


Check to Make Sure That Other Scripts on the Page Aren't Failing

Common Symptom: The first picture displays but the slide show doesn't play

If the page on the SharePoint site is running other JavaScripts (especially JavaScript that gets added through a feature) and one of those JavaScripts fail before the page gets a chance to load the slide show script, the slide show script won't run. For example, in my environment, we have a feature that adds JavaScript to change the logo. If that JavaScript fails, the slide show stops working. If your slide show is not working, view the errors on your browser to see if there is any JavaScript that's failing.


If You Are Referencing a Document Image Library for the Images, Check to Make Sure That You Have Read Permission on the Library

Common Symptom: The script "hangs", then red Xs appear when the user stops the script from running.

One of the things that readers reported was that their script would "hang", and when the stop the "hanging", it would show a red X. If you are referencing a document library for the images, you will possibly get "hanging" if the viewer does not have read permission to the document library. Either grant the viewers of the site at least read permission to the document image library, or move the pictures to a document image library where the users have read permission.


Hopefully these techniques are helpful. If you have other ideas to help fellow readers who are having trouble with the script, please post your suggestions.

Wednesday, October 21, 2009

Spotlight on Great Tutorial Site for Learning Telecommunications and Network Technologies:RAD University

RAD University - http://www.rad.com/12/RAD_University_Tutorials/5266/

Follow Dr. Debby Koren, Founder of RAD University, on Twitter (@RAD_U_dean)- http://twitter.com/RAD_U_dean

I usually teach network and telecommunications technologies in school, and I'm always trying to find ways to help the students learn the concepts without being completely bored or overwhelmed. Typically, I'll make interactive games in Flash. Unfortunately, I'm not a full-time professor, so my time to create supplemental materials is limited. While I was looking for an interactive example of IP Routing, I stumbled upon RAD University.

Created by Dr. Debby Koren of RAD Data Communications, Ltd., she and her students at Tel Aviv University and other institutions of higher education created interactive tutorials to help students understand concepts in telecommunications, data networking, and computer networking. While these subjects would generally appeal to students studying network engineering, software and computer engineers may also want to view some of these tutorials to help them develop applications for telecommunications or networking.

A complaint that I hear from some of my network technology students is the concepts about telecommunications and networking can be dry, which made it a little difficult for them to really understand it. RAD University's tutorials really make learning about telecommunications and networking interesting by providing fun, interactive exercises to help learn about the topics.

If you are interested in learning about telecommunications and networking in a fun way, or if you are an instructor looking for more exercises to help reinforce learning, check out RAD University. As an instructor, I'm looking forward to directing my students to this site.

Note: The author is not being remunerated by the owners of the RAD University website for the site review, nor does the author have any association or affiliation with the RAD University site.

Thursday, October 15, 2009

WPF Tutorial: Great Site for Learning WPF

WPF Tutorial, by Christian Moser - http://www.wpftutorial.net

I try to keep my finger on the pulse of what technical skills employers are looking for in a particular IT discipline so I can help guide my students with their learning plan to prepare for the work force. One of the technical skills that seems to be in demand with employers looking for .NET developers is WPF. As a student or a professional who's looking to build a skill set, it may be difficult to find a course teaching WPF that's affordable. It may also be time consuming and expensive to find any self-study materials to learn WPF. Christian Moser, a software developer from Switzerland, has solved that problem.

WPF (Windows Presentation Foundation) - a graphical subsystem for rendering user interfaces in Windows-based applications.

Mr. Moser has developed a web site for students (and established IT professionals) who want to learn WPF. His site, WPF Tutorial, is a well-organized, beautifully designed, "one-stop shop" site that provides students with information that they need to learn WPF. Some of the features of the site include:

  • Tutorials to get started with WPF.

  • Informative articles about tools and books that help students learn WPF.

  • My personal favorite - "Learn WPF in two Weeks". Note: this tutorial appears to be incomplete, but there are enough exercises to get started



If you are interested in learning WPF, visit Christian's site by clicking on the link at the top of this post.

Note: The author is not being remunerated by the owners of the WPF Tutorial website for the site review, nor does the author have any association or affiliation with the WPF Tutorial site.

Wednesday, October 7, 2009

Blog of Interest for IT Students - http://careertips.blogliterature.com/

There was a blog that was brought to my attention that I found to be very interesting to job seekers. The blog is called Career Tips.

Although a number of tips are targeted for people just entering the workforce, a few of the tips posted are also very useful to people in mid-career or people who are changing careers. It's worth a read regardless of what stage you are in a career.

Granted, some of the posts are of little interest to an aspiring IT professional. For example, most IT professionals aren't interested in learning how to write a resume to get a job as a chef. However, many of the posts are relevant and informative. For example, two posts on the blog - tips for searching for a job and choosing a career - are relevant to aspiring IT professionals.

If you're looking for some advice on getting your first job in the industry or changing careers, visit http://careertips.blogliterature.com.

Note: The author is not being remunerated by the owners of the Career Tips blog for the site review, nor does the author have any association or affiliation with the Career Tips blog.

Thursday, September 10, 2009

Writing Your Own Twitter Client



These are screen shots of a Twitter client that I wrote for my own use. This application allows me to log in to Twitter and post tweets without having to log in from my browser.

This application was written in C#. I put all the calls to the Twitter API in a reusable class (this application is referencing that class), and I put all the URLs to Twitter in the configuration file in case.

I also have logic for the program to reference the configuration file to determine what image should appear in the application.


Overview


A great way to get more practical experience with computer programming and software design is to design and write your own substantial application. By substantial, I mean something beyond the standard "hello world" or "add two numbers" program. One fun idea is writing your own Twitter client. Thanks to the Twitter API, you can make your own custom Twitter client.

The Twitter API


Twitter has APIs that aspiring programmers can use to create their own custom Twitter applications. In a nutshell, the APIs are accessed using HTTP, and the methods/functions return an XML response. The documentation to the Twitter APIs can be accessed here.


If you are learning a programming language, you should acquaint yourself with using the Twitter APIs. However, the libraries and wrapper classes are very handy if you are already experienced with a particular programming language and you are on a tight deadline to create an application.

Please note that if you are creating an application using one of the libraries, you will need to be aware of the usage license for those libraries. For example, if you are making a commercial application, you may not be allowed to use a particular library.

Libraries/Wrapper Classes using the Twitter API


If you want to save a little time with writing your application, numerous developers have written custom libraries or wrapper classes (based on a variety of languages) to make calling the Twitter API a little simpler. These libraries can be found here.

A C# Lab: Making a Simple Twitter Client That Sends Tweets



Custom Twitter API Libraries (based on language) - http://apiwiki.twitter.com/Libraries

Twitter API Documentation - http://apiwiki.twitter.com/Twitter-API-Documentation

I created a C# lab that will allow the C# student create a very basic, simple Twitter client using the Twitter APIs that will give the student practice with how to use the Twitter APIs. If you want a copy of that lab, you can access it here.

Thursday, August 20, 2009

Links to FREE SharePoint 2007 Training and Reference Resources


Before I begin my article, I wanted to address a comment that was left on one of my posts regarding moderating comments. I didn't publish the comment because a) it contained language that was not safe for work or school, and b) it was not in a tone that would promote a healthy learning environment. I still want to answer the question anyway.

There are a few reasons why I moderate my comments:

  • Since a good bit of my audience are students, some of them try to be funny. If it's something clean, I'll post it. However, there are some who like to post inappropriate links or messages that are not safe for work or school. I don't want my blog to get flagged by web site traffic blockers because somebody finds it amusing to do a rickroll to pornographic material in my comments.

  • A pet hate of mine is when someone likes to use the comments to post spam. By moderating the comments, I can keep the spam off my site.

  • Although my blog is read by IT professionals of all levels, my blog is targeted to IT students and professionals who are starting out in a technology. As an adjunct professor, I believe in promoting a healthy learning environment where people can freely ask questions without being told that they're "stupid" or that they should just "Google it before asking it", and people can receive constructive criticism instead of negative attacks. By moderating the comments, I can block the people who are attacking others that have left comments or questions.





When I talk about job roles throughout the article, I mean the following in relation to SharePoint:

  • Administrator

  • Programmer/Developer

  • End User

  • (Web) Designer




I'm always looking for resources to help me with my day-to-day activities and my project work in relation to SharePoint 2007. Because of the economy, I need to use resources that are as inexpensive as possible. There's nothing less expensive than free.

Below are some free resources that I personally use and endorse.

The MSDN Windows SharePoint Services Developer Center is a fantastic source for all job roles with SharePoint 2007. After all, SharePoint 2007 is a Microsoft product. This site contains whitepapers, tips, and videos on all things SharePoint.

If you are looking for general tips and techniques, the SharePoint News Section of SearchWinIT.com contains great tips and techniques to help you with the various job roles in SharePoint. Note: you may have to register on the site to gain access to some of the information. Registration is free.

You can also access the free SharePoint E-Zine to get monthly information about the management, implementation, and governance of SharePoint. For example, the March 2009 issue contains traps to avoid to save yourself aggravation while supporting SharePoint, and the February 2009 issue talks about migrating from WSS 3.0 to MOSS 2007.

If you are a designer, look no further than Heather Solomon's Site. If you already work with branding and designing SharePoint sites, you probably already know that Ms. Solomon is considered the expert in SharePoint branding. Her site is the most comprehensive site on SharePoint branding.

If you are a developer, there are two helpful sites for you. Kirk Evans Links to Free SharePoint Developer Resources contains reference links that SharePoint developers need to have handy when working on development projects for SharePoint, and Point8020 free developer training is a 12-part course on writing code for SharePoint. It includes a module on Silverlight, which is what I'm learning now. ;)

When it comes to free SharePoint resources, a "new kid on the block" is Shelby Consulting. Bob Shelby is an IT professional working toward Microsoft Partner status in SharePoint, and he was kind enough to publish materials that he acquired and developed during the process. Most of the tutorials are targeted at administrators, but he does have a section for designers.

If you have any links to great free resources (in SharePoint) that you would like to share, please leave a comment and I will publish them.

Monday, June 15, 2009

Congratulations Pittsburgh Penguins!!



Congratulations to the Pittsburgh Penguins for beating the odds and winning the Stanley Cup!

Wednesday, June 3, 2009

A Look at CAML for SharePoint Development

Overview


For a quick summary of how CAML improved performance on a list items query, read this article from author and SharePoint development expert Sahil Malik.
The Collaborative Application Markup Language (CAML) is an XML-based language that is primarily used to perform data manipulation. In a number of cases, using CAML helps improve your program's performance.

CAML Tutorial


If you are unfamiliar with CAML syntax, Karine Bosch wrote a fantastic tutorial on writing CAML queries for SharePoint Magazine. She covers all the basics and the "gotchas" of CAML syntax in an easy-to-follow manner.

Helpful Tools


When I am writing code where I need to use CAML, I am partial to two FREE tools.
Screenshot of Stramit CAML viewer. Click on the image for a larger view.


The Stramit CAML Viewer is an "all-in-one" tool that not only lets you view and test CAML queries, but it also displays the GUIDs for lists and views. You can download this tool from CodePlex.

Screenshot of U2U Caml Query Builder. Click on the image for a larger view.


The U2U CAML Query Builder is a slick, time-saving tool that will automatically build the CAML query for you based on the information entered by you. It also has a feature where you can copy the built CAML query to the clipboard. You can download this tool from the U2U site.

CAML in Action: A Simple Query



Note: This code will only work on a server where SharePoint is installed. For example, if you are going to add a view to a list that exists on http://bogus/bogussite, you need to have this code on the server that houses http://bogus.


In this example, I have a list on my site called Doctor Who Episodes. I would like to get the list of episodes that starred Jon Pertwee as the Doctor, and I would like to order that list by the year. My application, written for demonstration purposes only (no "fancy" formatting, application usability design, or full performance evaluation was considered), will display the episode list in a text box the moment the application runs (Form_Load).
Click on the image for a larger view.


After creating a new C# Windows application called SimpleCAMLQuery, I added reference to the Microsoft.SharePoint library in my project and referenced the library in my code.

using Microsoft.SharePoint;


I added the following in the Form_Load event:
I defined three variables to hold the URL for the site, the list name, and the view name.

String siteName = "http://bogus/bogussite";
String listName = "Doctor Who Episodes";
String viewName = "All Items";


I then used SPSite, SPWeb, and SPList to open my list on my site. I also used SPQuery to open my view, since this class has the method/function to use for the CAML query.

SPSite site = new SPSite(siteName);
SPWeb web = site.OpenWeb();
SPList list = web.Lists[listName];
SPQuery query = new SPQuery(list.Views[viewName]);


I then build my CAML query using the StringBuilder class. You can also put the CAML query directly into a string object if you prefer. If the field has spaces or special characters in the name (as it does in my example - the field in my list is called "The Doctor"), you need to reference the hexadecimal values in the name.


System.Text.StringBuilder oSb = new System.Text.StringBuilder();
oSb.Append(" <Where>");
oSb.Append(" <Eq>");
oSb.Append(" <FieldRef Name=\"The_x0020_Doctor\" />");
oSb.Append(" <Value Type=\"Text\>Jon Pertwee</Value>");
oSb.Append(" </Eq>");
oSb.Append(" </Where>");
oSb.Append(" <OrderBy>");
oSb.Append(" <FieldRef Name=\"Year\" Ascending=\"True\" />");
oSb.Append(" </OrderBy>");

Note: The order in which the Where and the OrderBy tag blocks appear in the CAML doesn't matter. Some people place the OrderBy tag blocks before the Where tag blocks. I usually place the OrderBy tag blocks after the Where tag blocks because I'm used to writing SQL, and in SQL syntax, the Order clause comes after the Where clause.

I then called the Query method/function of the SPQuery object to set up the CAML query

query.Query = oSb.ToString();


Finally, I put the results in a SPListItemCollection object and looped through the object.

SPListItemCollection results = list.GetItems(query);
foreach (SPListItem i in results)
{
  txtResults.Text += i["LinkTitle"].ToString();
  txtResults.Text += Environment.NewLine;
  txtResults.Text += i["Synopsis"].ToString();
  txtResults.Text += Environment.NewLine;
  txtResults.Text += i["Year"].ToString();
  txtResults.Text += "----------------------------------------";
  txtResults.Text += Environment.NewLine;
  txtResults.Text += Environment.NewLine;
}



Here is the full code:
Click on the image for a larger view.


Additional examples of CAML in Action


If you would like to see additional examples of using CAML, view these previous posts on my blog:


If you have any questions, comments, or additional examples, please feel free to post a comment.

Wednesday, May 27, 2009

The Scribd Store: Another way to expand your portfolio...AND your wallet

As you may have read on my blog, I am a fan of Scribd, and I am a regular user. Scribd has released an exciting feature. Scribd now has its own storefront that will allow you to sell your written works.

Not only is the store a way to earn money on technical and research documents that you have written, but it is a way to build your professional portfolio.

  • Published works are always great projects to have on a professional portfolio.

  • The analytics tools that come with the store displays sales and viewing figures that you can use to demonstrate your product's marketability to potential employers.

  • Having your own store demonstrates business skills - a secondary skill - because you have to manage the sales and marketing of your documents.



For more information, visit http://www.scribd.com/store/about.

Monday, May 18, 2009

SharePoint 2007: System.OutOfMemoryException in SiteData During Search Crawl

Lately at work we've been getting these errors on our SharePoint site. From what I was able to Google, it looks like others have this problem as well.

After doing some research, I found a post from Ranjan Banerji, who also experienced this problem in his environment. This post goes into deep detail as to how they worked around this problem. You may want to read through the post. I've found it to be very helpful.

In addition to the information mentioned in the post, we found that we had users who had abnormally long names for folders and files. As a result, it would make a path that was entirely too long for SharePoint to handle. From what we were able to tell in our logs, we noticed that the crawler would "choke" on these entries, which would then trigger the OutOfMemoryException.

If you have encountered this problem due to a reason not mentioned by me or Ranjan, please feel free to post a comment.

Friday, May 8, 2009

SharePoint Development Tutorial: Programmatically Create View on a List

While it is easy to create a view for a list in SharePoint, you may find a scenario where you need an easier way to create a view on a list. For example, I had a situation where I had to create over 30 views for one list. Creating the views using SharePoint can be time-consuming, and it could increase the possibility of user error because of the manual process. Using C#, the Microsoft.SharePoint library, and CAML, one can create a view for a list on SharePoint.

This illustration will demonstrate the simplest example of using C# code to add a view to a list (as a console application). You may want to make modifications for your needs, or use it as a foundation for a larger-scale application.


Note: This code will only work on a server where SharePoint is installed. For example, if you are going to add a view to a list that exists on http://bogus/bogussite, you need to have this code on the server that houses http://bogus.



The Scenario


In this illustration, there is a list on a SharePoint site called "Doctor Who Episodes". This list needs a new view called "JNT Era", which will display Doctor Who episodes made during the JNT era (1980-1989). This list has four fields:

  • Title

  • The Doctor

  • Synopsis

  • Year



See the example list

After starting a new project, you will need to add a reference to the Microsoft.SharePoint library in your code, and you will need to indicate that you will be using the library in your code.
See the example snippet

The next step is to define the SharePoint classes that you will need to perform the action. The four classes that you will need are:

  • SPSite - Collection of sites

  • SPWeb - The SharePoint web site

  • SPList - A List on a SharePoint web site

  • SPViewCollection - Collections of views on a list



In the code, you will need to access the website. You will define an instance of the SPSite class to get the site, then you will need to define an instance of the SPWeb class to have a reference to the actual site.

SPSite oSite = new SPSite("http://bogus/bogussite");
SPWeb oWeb = oSite.OpenWeb();


Alternative to SPList oList = oWeb.Lists["List Name"]

You can also access the list by the GUID. Use the following logic if you want to access the list by the GUID rather than the name:

Guid gui = new Guid("The List GUID");
SPList oList = oWeb.Lists[gui];


Then, you will need to access the list that will get the new view, and you will need to access the list's collection of views.

SPList oList = oWeb.Lists["Doctor Who Episodes"];
SPViewCollection oViewCollection = oList.Views;


Finally, you will need to define the new view name.

string strViewName = "JNT Era";

See the example snippet

We are ready to define the fields that will be displayed in this new view. In this example, the view will display all the fields. You will need to define an instance of the System.Collections.Specialized.StringCollection class to hold the names of the fields that will be displayed in the view.

System.Collections.Specialized.StringCollection viewFields =
new System.Collections.Specialized.StringCollection();

To add the fields, use the Add() function of the class. You do not have to use the special hexadecimal characters to represent spaces and special characters for the field names. You can use the literal field name.
See the example snippet


Helpful Links:

CAML Syntax

Stramit Caml Viewer

We have to define the criteria for the view using CAML. In our illustration, we want to display the Doctor Who episodes from 1980 until 1989, and we want to display them in ascending order. Your scenario may be different, so your CAML will be different. If you are unsure of CAML syntax, a link to a site that has documentation on the CAML syntax has been provided for you on this post. If you want to make sure that your query will work before you begin coding, you can use the Stramit Caml Viewer to test your CAML query. A link to the tool has also been provided for you on this post. In this illustration, I am using the StringBuilder class to hold the CAML query. Then, I am converting it to a String.
See the example snippet

Finally, we are ready to add the view. The Add() function of the SPViewCollection class adds a view to the list. The Add function
takes six parameters:

  • View Name - a string

  • Collection of View Fields - string collection

  • CAML query - a string

  • Row Count - an integer

  • Is this paged? - a boolean

  • Is this going to be the default view? - a boolean


You also have to call the Update() function of the SPWeb class to make sure the changes "take".

oViewCollection.Add(strViewName, viewFields, query, 5000, true, false);
oWeb.Update();

See the example snippet

After completing, compiling and running the program, the list now has a new view!
See the results

If you would like a copy of the skeleton code, you can download the RTF file of the skeleton code here.

Please post your questions or comments, and I will answer your questions to the best of my ability.

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/

Tuesday, March 31, 2009

For Multimedia Students and Professionals: An Affordable 2-D Animation Program

Most of graphic design and animation is done using computers. If you are a Multimedia student or professional, you may have noticed that many applications used in your line of work, including the academic editions of the software, are very expensive. For those of you who are studying or working in Multimedia Technologies, famed animator Eddie Fitzgerald wrote a review on affordable 2-D animation programs that may be useful in your line of work.

At Last: An Affordable 2-D Animation Program

Thursday, March 26, 2009

Spotlight on a Good Example of a Project for a Career Portfolio


Stephanie Jones's site, Best of Everything

http://www.joancrawfordbest.com


For people who are starting out in the IT industry, one of the things that I tout is creating a career portfolio. If you are a web designer or a web application developer, a comprehensive, professional web site is a great way to gain experience.

A fine example of a professional web site is The Best of Everything, run by Stephanie Jones. The Best of Everyting is a comprehensive, unbiased, well-researched site about classic film star Joan Crawford. What impresses me about this site is Ms. Jones is not a web developer by trade, but her site does not look "amateur".

Below are some points on what makes this a good site:

  • The site is thorough, well-researched, easy to navigate, and has a good layout.

    While creating a social networking profile is a nice way to "get your name out there", you need more that that to illustrate that you can do the work. Unfortunately, a simple, few-page web site about your pet, your favorite possession, your favorite sport, or your favorite celebrity will not win over the hiring managers. You need a strong, active site to prove that you can do the work. This site fits the bill. It is not just a site with a list of Joan Crawford films and a few pictures; it is an all-inclusive site about Joan Crawford.


    A University of Michigan study showed that people receiving instructions in a plain font like Arial were able to follow the instructions and complete the task more quickly and accurately than people receiving instructions in a "fancy" font. (Source: Hyunjin Song, Norbert Schwarz (2008). If It's Hard to Read, It's Hard to Do: Processing Fluency Affects Effort Prediction and Motivation Psychological Science, 19 (10), 986-988)

    If you are going to create a web site, the trick is to make it look like a skilled, talented professional created it. The site shouldn't look like it was created by someone who uses FrontPage and animated GIFs and considers that "web development". You want to take the color pallete, the layout and the fonts into consideration. If you look at Ms. Jones' site, you will see that she uses about 4 colors total on the site. The site is also easy to read - the content is "center" to the page, and the font is a "rounded" font (ex: Arial), which is easier to read. She is also utilizing well-established third-party tools (like Google Search and Yahoo!Groups) to properly enhance her site.


  • The site illustrates Ms. Jones's skills with writing and research.

    Ms. Jones is a copy editor by trade. The thorough research that has been done on this site illustrates her writing and research skills to potential employers and clients. She has had a job offer based on the work that she has done with her site, and she was able to expand her professional network because the site was a good conversation starter.

    What does that have to do with technology, you may ask? As I mentioned in numerous articles about getting a job in the economy, you need to be more than a "digithead" in order to get the job. You need secondary skills that will support your role in the company. Written communication and research are two secondary skills to have. For example: let's say that you want to develop a encyclopedic web site dedicated to vintage machines. If you develop a site featuring pictures and scant information about the machine, it may be nice - not thrilling, but nice. However, if you also contain thorough information about the machine ( who invented it, when was it used, what kind of "under the hood" technology was used, what was it's claim to fame, what replaced it), you'll demonstrate your ability to research and understand your topic as well as your web development abilities.

  • The site is professional.


    You'd be quite surprised about how many websites are out there that "borrow" content from someone's site without properly crediting the source. That's plagiarism. If you're working in the academic world, that's grounds for dismissal. In other arenas, that's grounds for a copyright-infringement lawsuit.


    Creating a site about a celebrity can easily drift into the "unprofessional" category. Ms. Jones does a wonderful job with keeping the content professional (although the message board can get a little "colorful"...you, as a student developing a site for a career portfolio, may need to monitor your forums). If she makes a personal opinion, she chooses her words carefully. Most importantly, if she receives information from outside sources, she properly credits those sources.



If you want to build a celebrity tribute web site for your career portfolio, look at The Best of Everything as an example of a site that would look wonderful in a portfolio. In my opinion, this site is so well done that it could easily pass for an "official" site.


See Also:
Getting a Job in a Tough Economy

Tuesday, March 24, 2009

Add a SlideShow to the SharePoint Site using HTML, JavaScript and the CEWP

While the SharePoint OOTB web parts for displaying images are nice, the functionality of the web parts are very limited. Particularly, the OOTB web parts do not have a true "slide show" capabiilties that many end users are looking for. You can write your own custom web part to display images like a slide
show. However, this solution will not only take time and effort to do, but if you are just a “power user” for your SharePoint site, you may not have the right tools and permissions to make your own web parts. If you are familiar with JavaScript and HTML, you can add your own slide show on your site.

For a step-by-step guide that you can download: Add a Slideshow on a SharePoint Site using Javascript, HTML, and the Content Editor Web Part

Here is a video demonstrating how to add the slideshow:


UPDATE: If you are having trouble with getting this to work, see the blog post from 10/26/2009 for troubleshooting tips.

Thursday, March 19, 2009

VB.NET Tutorial: Renaming a Directory using VB.NET Code

There may be a time where you need to programmatically rename a directory. For example, you may be creating a Setup and Deployment project where you have to have a project that "backs up" a directory before installing a directory. .NET has a class that allows you to programmatically rename a directory.

The following video demonstrates how to programmatically rename a directory with the Move function in the Directory class using VB.NET:


A more detailed document is available here: Rename a Directory Using VB.net

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

P.S. - I just noticed - this is my 100th post!!

Monday, March 16, 2009

SharePoint Tutorial: Playing a WMV File in a SharePoint Site

Sometimes you may need to play a WMV file on a page in a SharePoint site. For example, you may have to play a video of your CEO speaking, or you may have to play a training video. By using the Content Editor web part, you can easily play a WMV file on a page in a SharePoint site.

You can download the step-by-step documentation from the following location: Playing a WMV File in a SharePoint Site

Below is the step-by-step demonstration:


If you have any questions or comments, feel free to ask!

Friday, March 6, 2009

SharePoint Tutorial: Play a Flash Video on your SharePoint Site

Sometimes you may have to play a Flash video on your SharePoint site. For example, you may have to play a message from your CEO, or you may have to incorporate a quiz on the site. This tutorial demonstrates how to play a Flash video on your SharePoint site.

You can download the written tutorial here: Playing a Flash Video on a SharePoint Site

If you are a more visual person, here is a demonstration:


If you have any questions or comments, please post a comment and I will answer the question to the best of my ability.