June 27, 2007

MOSS: SPListItem.Update() throws error Operation is not valid due to the current state of the object.

Problem:
When running SPListItem.Update commands inside SPSecurity.RunWithElevatedPrivileges block you get error: Operation is not valid due to the current state of the object.

Thoughts:
I will call this a workaround since I don't know why it works and is this really how it should be done.

Workaround:
You must not call the SPListItem.Update inside the RunWithElevatedPrivileges block. Instead you should only instantiate the SPSite or SPWeb there and call Update afterwards, like this:

    private static string CreateSiteLink(SPWeb newSite, int groupId, string text)
    {
        string retVal = "";
        SPWeb elevatedRootWeb = null;

try
{
         SPSecurity.RunWithElevatedPrivileges(delegate()
         {
             using (SPSite elevatedSite = new SPSite(newSite.Site.ID))
             {
                 elevatedRootWeb = elevatedSite.RootWeb;
             }
         });
 
         SPList userInformation = elevatedRootWeb.Lists["User Information List"];
  
         if (userInformation != null)
         {
             try
             {
                 elevatedRootWeb.AllowUnsafeUpdates = true;
  
                 SPListItem item = userInformation.GetItemById(groupId);
  
                 if (item["Notes"] != null)
                 {
                     item["Notes"] = string.Format(text, newSite.ServerRelativeUrl, newSite.Name);
                     item.Update();
                 }
  
                 elevatedRootWeb.AllowUnsafeUpdates = false;
             }
             catch (Exception e)
             {
                 retVal = " Site link for group " + groupId + " couldn't be created. (" + e.Message + ")";
             }
         }
         else
         {
             retVal = " Site link for group " + groupId + " couldn't be created. (User Information List not found)";
         }
finally
{
elevatedRootWeb.Dispose();
}
  
        return retVal;
    }


Solution:
Unknown

June 14, 2007

MOSS: SmallSearchInputBox is not visible on master page

Problem:
Having done something, the search box is no longer visible on the master page although

<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox">
</SharePoint:DelegateControl >
</asp:ContentPlaceHolder>

does exist on the page and search control is visible in SharePoint Designer.

Thoughts:
There is a search.js in 1033 folder.

Solution:
Make sure that the ContentPlaceHolder in the master page has not visible=false.

Also check that your layout pages do not have empty Content tags with ContentPlaceHolderId value
PlaceHolderSearchArea. If you do, they will override the respective Content on the master page.

Thanks to Ivan Inyushin for teaching me the wonders of ContentPlaceHolders.

MOSS: stsadm setproperty returns "Command line error"

Problem:
Trying to run commands such as:

stsadm -o setproperty -url http://url.to.site.com:80 -pn "peoplepicker-searchadforests" -pv "domain:my.domain.com"

return error message Command line error.

Solution:
Use stsadm.exe like this:

stsadm.exe -o setproperty -url http://url.to.site.com:80 -pn "peoplepicker-searchadforests" -pv "domain:my.domain.com"

Logical:
No, but not many things are in MOSS.