Contains operator missing in Advance Search Web Part

This is an old topic, and i know it has been covered by some other people, but it is one i keep having to rectify in various client environments, so thought i would give myself an easy reference point for it rather than keep trawling the web each time.

So you have added the advance search Web Part to a page and the only two options which exist in the operator drop down (see below) are “Equals” and “Does not equal”.  So where has the “contains” and “does not contain” operator gone.  

clip_image002

The explanation of why it has disappeared could be due to an MS infrastructure update to increase performance for search.

Well, to restore this follow the instructions below.

Read the rest of this entry »

Happy New Year

Just thought i’d send a quick post to wish everyone who reads my Blog a very Happy New Year.  I am looking forward to an exciting 2010 with plenty of new technologies to dive into with SharePoint 2010 and Visual Studio 2010 at the top of my list.

Over the Christmas period i managed to get a SharePoint 2010 beta server up and running so i will be putting up some posts on my findings whilst playing around.

I Will also be looking into Visual Studio 2010 and how well it integrates and caters for SharePoint development.

Watch this space………..

Setting ModerationInformation.Status back to pending removes author/creator permissions

Here’s the scenario – I have a visual studio sequential workflow on a list (not document library) which has a 2 stage approval process.  The request was to use the standard OOB approve/reject mechanism rather than tasks, so for the first stage of approval, the approver would select Approve/Reject from a list item.  Once the first stage approver approves the item, the item should NOT be approved and live, but still pending and an email sent to the 2nd level approver to make the ultimate decision of making the item live.  Once the 2nd stage approver approves the item the item then becomes Approved and Published for all to see.

I created a Visual Studio Sequential Workflow and created separate routes through workflow based on who updated the List Item.

image

In code, if the item was approved by the 1st stage approver  i would reset the ModerationInformation.Status back to pending, my code was simple and as follows;

  1: this.workflowProperties.Item.ModerationInformation.Status = SPModerationStatusType.Pending;
  2: this.workflowProperties.Item.Update();
  3:
  4: 

Read the rest of this entry »

SPDisposeCheck Error workaround

I use the very useful SPDisposeCheck tool to check my assemblies using the SharePoint API to make sure i have not left any SharePoint objects open which could cause potential memory leaks.

I encounter issues using the output to xml file “–xml” switch on the tool where it simply crashes at the point of “Processing Method Traces”.  I am not sure if there is an updated version out there to fix this but should you want to get the output to a file rather than the command window, i use a workaround to which outputs (pipes) the command window to a file by using the > command, so your command should look something like this.

SPDisposeCheck “<mydllFileOrDirectory>” –debug  >”<outputdirectory>outputtfile.txt”

Hope that helps if people want to save the output.

Finally got round to taking the 70-541 MCTS WSS 3.0 Developer Exam

I finally got round to taking the 70-541 MCTS Microsoft Windows SharePoint Services 3.0 – Application Developer exam today and passed with a score of 895.

The exam content was pretty much what everyone out there is blogging about with some added questions which apparently do not contribute to your score in order for Microsoft to test out some new questions.  Completed it in just over an hour.

Having worked with SharePoint since its Beta days back in October 2006, i didn’t think it really tested or was a reflection on my real world experience of development within the WSS space. 

I used the Inside Microsoft SharePoint Services 3.0 book (Ted Pattison), which i did find useful and then a number of Visual Cert Exams from various places out on the web.  All pretty useful for passing the exam.

Fun with SPFieldUserValueCollection

I have been searching around to see the various ways in which people are retrieving Users and Groups objects or the string value from relevant SPField  object when retrieving ListItems from a SharePoint List,  and I have found that there are quite a few blog posts on this subject, all with differing code and views. 

Having now tested nearly all of them, i have used 2 approaches that have helped me and the are

  1. Retreiving an SPUser or SPGroup object – perhaps for validation purposes or to gain other information about the user of group
  2. Retrieving a User friendly string representation of the User or Group – perhaps for simple display purposes.

The code below show the retrieval of the SPUser/SPGroup objects

  1: SPList oList = currentWeb.Lists["ListName"];
  2: SPListItemCollection oListItems = oList.Items;
  3: foreach(SPListItem oListItem in oListItems)
  4: {
  5:   //Gets a collection of all the User and Group objects from 
  6:   //the UserGroup Field
  7:   SPFieldUserValueCollection oFieldUserValueCollection =
  8:     new SPFieldUserValueCollection(currentWeb, oListItem["FieldName"].ToString());
  9:
 10:   //Next, loop through the Values in the Collection
 11:   foreach(SPFieldUserValue oFieldUserValue  in oFieldUserValueCollection)
 12:   {
 13:     //now we need to test if the SPFieldUserValue is a
 14:     //User or a  Group, because if we simply assign a user
 15:     //we will get a Null Reference Exception if it is a Group
 16:
 17:     //It is a Group
 18:     if(oFieldUserValue.User == null)
 19:     {
 20:       //Create and assign a new SPGroup object by using the
 21:       //Lookup value to return a Group from the current Site(SPWeb)
 22:       SPGroup oGroup = currentWeb.Groups.GetByID(oFieldUserValue.LookupId);
 23:     }
 24:     //It is a User
 25:     else
 26:     {
 27:       //Create and assign a new SPUSer object by using the User
 28:       //property of the SPFieldUserValue object
 29:       SPUser oUser = oFieldValueUser.User;
 30:     }
 31:   }
 32: }

and the code below here shows the retrieval if the simple string representation.

  1: SPList oList = currentWeb.Lists["ListName"];
  2: SPListItemCollection oListItems = oList.Items;
  3: foreach(SPListItem oListItem in oListItems)
  4: {
  5:   SPFieldUserValueCollection oFieldUserValueCollection
  6:     = SPFieldUserValueCollection(currentWeb, oListItem["FieldName"].ToString());
 7:
  8:   foreach(SPFieldUserValue oFieldUserValue in oFieldUserValueCollection)
  9:   {
 10:      //simply retrieve the string value from the SPFieldUserValue object
 11:      string sFieldValue = oFieldUserValue.LookupValue;
 12:   }
 13: }

If anyone else has any more thoughts on this please let us know.

Content Type Hidden Columns disappear completely after using Move/Copy in Manage Content and Structure

I found a potentially huge problem the other day with the use of content types in a list, hidden columns and using the Move/Copy in Manage Content and Structure and thought i would share this with everyone as this has cost me a week of banging my head trying to solve the problem (and re-creating the lists).

These issues are additional to a previous post i submitted about the use of Child Content Types.

Here is what I did and the problems i discovered.

Firstly I created a Base Content Type, added a couple of columns to it,

image

image

Read the rest of this entry »

Adding ListView WebPart with SharePoint Designer ignores permissions on folders in the Menu Bar.

Came across an interesting problem the other day for anyone adding a ListView WebPart to a Page using SharePoint designer which i believe to be a SharePoint Designer bug.

The scenario

I created a custom List which contained 2 folders, Country A and Country B.  I had a user who I gave read access to the entire List but Edit access to Country A folder only.

I created a new SharePoint ListView using the SharePoint UI, which in turn created an aspx page.  I opened this page up in SharePoint designer and removed the ListView WebPart as i was going to create DataView web part instead.   I found that the DataView WebPart was not going to meet my needs so added back in a ListView WebPart by using the Add WebPart from the right hand toolbar (see below).

image

This put my ListView WebPart back on the page as per the original page.  Or did it…….

Read the rest of this entry »

SPList.GetItems(SPQuery query) does not search recursively through sub folders in a List

I developed a custom WebPart which allowed a user to select a list from a site and then execute an advanced search within the selected list.   The advanced search functionality provided various options to select which fields to filter on, sort and display, using the SPField properties.

The search execution code was created using the SPList.GetItems(SPQuery query) search function. 

Testing was going great until i came across a problem when searching on items in subfolders within a list, the test failed as No items in subfolders were returned.

I came across this in the SDK which wasn’t obvious to me, so thought I’d ease other people’s pains quickly if it isn’t obvious to you either.

There is a property called ViewAttributes on the SPQuery object which accepts a string value. The following code shows how to use the property to search recursively through subfolders

  1: using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["Site_Name"])
  2: {
  3:     SPList oList = oWebsite.Lists["DocLib_Name"];
  4:     SPView oView = oList.Views["View_Name"];
  5:
  6:     SPQuery oQuery = new SPQuery(oView);
  7:     oQuery.ViewAttributes = "Scope="Recursive"";
  8:     SPListItemCollection collListItemsAvailable =
  9:       oList.GetItems(oQuery);
 10: }
 11: 

Searching across all fields using SPList object

Was given an interesting requirement the other day to create a Web Part which used WSS API, not MOSS,  to search within a single  list across all fields(like a google search) to see if any fields contained a specific search term displaying the results in a DataGrid.

I set about looking into using CAML to do this with the SPLIst.GetItems(SPQuery) function but found the CAML too time consuming to write for such a generic seach.

So that lead me to returning a DataTable from the ListItemCollection so i could filter records in memory using the SPListItemCollection.GetDataTable() function.

I then had a look at the DataTable.Select() function to see if i could use a SQL query to filter my items but again, would have had to write a fair bit of code to generate the dynamic SQL string for all fields.

So that finally lead me to using the returned items from the DataTable, iterating through each DataRow and testing the contents of each DataColumn in each row to see if it contained my search term using a string.Contains() function.

Read the rest of this entry »