Archive

Archive for January, 2008

Another MS Exam Under the Belt

January 31st, 2008

Its official, I’ve passed another Microsoft Exam. Today I took Microsoft exam 70-282, Designing, Deploying, and Managing a Network Solution for a Small- and Medium-Sized Business. I needed a 700 to pass and scored a 770 on the test! Since I started this blog after my last passed Exam, I am also a Microsoft Certified Technology Specialist in Microsoft Office SharePoint Server 2007 Configuration by passing test 70-630 back in July of last year. Now I just need to figure out what the next test is that I should take. I may start moving on from here towards my MCSE, we’ll just have to see.

Ben Misc

SharePoint (sort of) Photo Album with Slideshow

January 25th, 2008

I was doing some work for another client this week and they wanted a Slideshow in SharePoint that would rotate through a set of pictures. SharePoint has a web part that will allow you to display a picture on a site and you can start it as a slideshow, however, it won’t automatically loop through a set of pictures. To solve their problem I used this application create in SilverLight. I know, it’s another browser pluggin to install. But it really is a cool Microsoft Project and can do some very cool stuff. I liked the application so much, I installed it on my blog, you can see my photo albums here. It isn’t a true SharePoint web part as it just using JavaScript and SilverLight. To use it in SharePoint, all you need to do is upload all the configuration files into a document library and then put a content view web part on the site you want your photo album on and point it to the html file in your document library. You can put the photos in another library and point your Data.XML file to the picture in the document library. It works for now. My next project when I get more time is going to work with a co-worker to add to the code so that a Picture Library in SharePoint can be used as the data source for the Photo Album so you can eliminate the Data.XML file when using the application with SharePoint.

Ben SharePoint

Getting Usernames in InfoPath

January 25th, 2008

I’m working on an InfoPath form for a client using Foms Services and needed a field in the Form that matched a Person/Group column in a SharePoint list. I first tried using the Username() function in InfoPath, however, this pulls the username in the form of domain\username and the column in SharePoint uses the Friendly name of the User, LastName, FirstName. The next step was to search and see what other people had done. I found one solution that doesn’t require any code here. Great, this will be easy. I went to attach to the Web Service, and low and behold, it wasn’t there. Then I check the MOSS install I had on my notebook and there it was. My client was running WSS with the Forms Services add on and didn’t have it. This was one of those Web Services that was included with MOSS but not with WSS, so it was back to searching. Then I ran across this site. I copied and pasted all the code made the few minor XPath revisions to fit it to my form and it worked beautifully!! It’s a great solution and now the client is happy. So, if you’re developing in InfoPath Forms Services, here are your two options, one for WSS and one for MOSS. Hope it helps all you fellow InfoPath Devs!

Ben SharePoint

Using the SharePoint web service to remove an item from a list

January 18th, 2008

For the last project I was working on, I needed to be able to delete an item from a SharePoint list using a Forms Service compatible InfoPath form. Due to the nature of the list, I needed to search for the item to delete based on the value of three different files and no column was unique. After several unsucessful attemps using various methods, I discovered that the only way you can use the List.asmx web service, is to delete an item based on the item ID (a hidden SharePoiint list column). The only way to do this in a forms services compatible form, is to write some code behind to perform the action. I used the following C# code in my InfoPath form and attached it to a button click event to remove the SharePoint list item based on the value in 3 fields in my InfoPath form. In the code below, any text in italics must be replaced with code specific to your particular setup of Infopath and SharePoint.

  1. [List.asmx web reference].Lists mylistService = new [List.asmx web reference].Lists();
  2. XPathNavigator nav = this.CreateNavigator();
  3.  
  4. // Get Column Values
  5. string strField1 = (string)nav.SelectSingleNode("[xPath to field1]", this.NamespaceManager).ValueAs(typeof(string));
  6. string strField2 = (string)nav.SelectSingleNode("[xPath to field2]", this.NamespaceManager).ValueAs(typeof(string));
  7. string strField3 = (string)nav.SelectSingleNode("[xPath to field3]", this.NamespaceManager).ValueAs(typeof(string));
  8.  
  9. XmlDocument xmlDoc = new System.Xml.XmlDocument();
  10. XmlElement elBatch = xmlDoc.CreateElement("Batch");
  11. XmlElement xnQuery = xmlDoc.CreateElement("Query");
  12.  
  13. string strID;
  14. mylistService.Credentials = System.Net.CredentialCache.DefaultCredentials;
  15.  
  16. //Build CAML Query
  17. xnQuery.InnerXml = "<where><and><and>" +
  18.   "<eq><fieldref name="Field1"><value type="Text">" +
  19.   strField1 + "</value></fieldref>" +
  20.   "<eq><fieldref name="Field2"><value type="Text">" +
  21.   strField2 + "</value></fieldref>" +
  22.   "</eq><eq><fieldref name="Field3"><value type="Text">" +
  23.   strField3 + "</value></fieldref></eq></eq>";</and></and></where>
  24.  
  25. //Query List
  26. XmlNode xmlList = mylistService.GetListItems("[SharePoinit List Name]", "", xnQuery, null, "20000", null, "");
  27.  
  28. //Get Item ID
  29. strID = xmlList.InnerXml;
  30. int intStart = strID.IndexOf("ows_ID");
  31. string tmpID = strID.Substring(intStart + 8);
  32. int intEnd = tmpID.IndexOf("ows");
  33. strID = tmpID.Substring(0, intEnd - 2);
  34.  
  35. //Build Batch Command
  36. string strBatch = "<method id="1" cmd="Delete">" +
  37.   "<field name="ID">" + strID + "</field></method>";
  38. elBatch.SetAttribute("OnError", "Continue");
  39. elBatch.InnerXml = strBatch;
  40. XmlNode ndReturn = mylistService.UpdateListItems("[SharePoint List Name]", elBatch);

This solved my problem and I was successfully able to delete items from my SharePoint list. If anyone has any questions about the code or suggestions to make the code better, leave me a comment and I will respond as soon as I can.

Ben SharePoint