Wednesday, April 28, 2010

Error: SharePoint folders that are created programatically are hidden.

I created few folders programatically from a SharePoint Workflow.

They have been created with no exceptions but I was unable to see them from the UI. Assuming that the folders are not created, I tried to created them through the UI. Then I got an error message "Folder already exists".

The above behaviour was with Custom Lists whereas these folders show up quite well in Document Libraries.

So I did a bit of research and learnt some thing about SharePoint folders.

There are few ways to create folders.

One of them is to use
SPWeb.Folders.Add(folderUrl);
The above problem was as a result of using this code.

Hers is another way to create folders in a list which works with both custom lists and document libraries (I have not tested the rest yet)
/// 
        /// Check whether the folder path exists. If it does not, build the folder structure
        /// 
        /// 
/// 
/// 
/// 
        private static String EnsureFolderStructure(SPWeb web, SPList list, String folderPath)
        {
            String folderUrl = String.Empty;
            try
            {
                if (!DoesFolderExist(web, folderPath))
                {
                    String partialFolderUrl = String.Empty;
                    String[] folderNames = folderPath.Split('/');
                    int ctr = 0;
                    SPListItem folder = null;
                    foreach (String folderName in folderNames)
                    {
                        partialFolderUrl += String.Format("/{0}", folderName);
                        folderUrl = String.Format("{0}/{1}{2}", list.ParentWeb.Url, list.RootFolder.Url, partialFolderUrl);
                        if (!DoesFolderExist(web, folderUrl))
                        {
                            //Folder does not exist. Create it
                            if (ctr == 0)
                                //Important: Leave the folderUrl blank if this folder is create in the root list.
                                folder = list.Items.Add("", SPFileSystemObjectType.Folder, folderName);
                            else
                                folder = list.Items.Add(folderUrl.Replace("/" + folderName, ""), SPFileSystemObjectType.Folder, folderName);
                            folder["Title"] = folderName;
                            folder.Update();

                            list.Update(true);
                            web.Update();
                        }
                        ctr++;
                    }
                }
                else
                {
                    folderUrl = String.Format("{0}/{1}/{2}", list.ParentWeb.Url, list.RootFolder.Url, folderPath);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return folderUrl;
        }
        /// 
        /// Check whether a folder exists
        /// 
        /// 
/// 
/// 
        public static Boolean DoesFolderExist(SPWeb web, String folderUrl)
        {
            try
            {
                return web.GetFolder(folderUrl).Exists;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Hide the SharePoint 2010 ribbon in a list form

If you have a to disable / hide the SharePoint 2010 ribbon in list forms (such as New / Edit / Display forms), one of the easiest ways is to do it through CSS.

As SharePoint 2010 provides great flexibility with list forms, we can easily modify whatever is required in a particular form for a particular list.

Click "Edit List" icon in the ribbon and it will fire up SharePoint Designer. Open the form where the ribbon needs to be hidden, right click it and choose "Edit File in Avdanced Mode".

The below is div in which the ribbon resides.
<div id=”s4-ribbonrow” class=”s4-pr s4-ribbonrowhidetitle”>
... 
</div>
Now to hide the ribbon, add this to the page.
<style type="text/css">
#s4-ribbonrow{ display:none; }
</style>
Ribbon gone..

Creating/Modifying list forms in SharePoint 2010

SharePoint 2010 provides the ability for users to create and edit list forms (New, Edit etc..) easily.
When you click on "Edit List" option in the list ribbon, SharePoint Designer opens up and provides  us with options to add/edit views, forms and workflows.

In order to create a new form, click on the "New" button next to forms and you will see a dialog that allows you to provide a name for the form, the type of the form (New/Edit/Display). Also you can set the newly created form as the default form for the selected type. You can also select content type to use.

Create a new form, choose the fields that you require to show in the form and hit ok.

All set. The newly created form should appear when you attempt to create a list item. (If the newly created form is for new items)

Tuesday, April 20, 2010

Error: "ERROR_NO_RESULTS_FOUND" when you use Search.asmx with FullText SQL query

I have encountered this bug that really irritated me today.
I was using Search.asmx with FullText SQL query to get some results and then display them to users using XSL through JavaScript using jQuery.

SELECT LastName,Company,AccountName,UserProfile_GUID, JobTitle,Size, Rank, Path, Title, Description, Write FROM SCOPE() WHERE ("DAV:contentclass"='urn:content-class:SPSPeople') AND (LastName LIKE 'C%')

worked

whereas

SELECT LastName,Company,AccountName,UserProfile_GUID, JobTitle,Size, Rank, Path, Title, Description, Write FROM SCOPE() WHERE ("DAV:contentclass"='urn:content-class:SPSPeople') AND (Company LIKE 'C%') 

did not work and it threw an error "ERROR_NO_RESULTS_FOUND"

After many trials and errors and a bit of research, it turned out to be a Microsoft bug.

"like statement will only work on a string shorter than 64 characters, above that it will fail gracefully leaving you with unexpected results..
"

The work around for my problem was to use CONTAINS as opposed to LIKE.
Please notice that the "company Name" is actually embedded within single quotes as '"Company Name"'.
Otherwise the Search service does not understand that it needs to look for the whole phrase.

SELECT LastName,Company,AccountName,UserProfile_GUID, JobTitle,Size, Rank, Path, Title, Description, Write FROM SCOPE() WHERE ("DAV:contentclass"='urn:content-class:SPSPeople') AND (CONTAINS(Company,'"Company Name"'))

Ref: http://social.microsoft.com/Forums/en-US/Offtopic/thread/12ea7757-7ca7-42b8-9ed2-59acd00d283d

Thursday, April 15, 2010

Display SharePoint 2010 ratings in search results XSL

I had a requirement to show the ratings(new feature in Sharepoint 2010) for all items that are returned in search results.

The crawled property that we have to use to get to the ratings is ows_AverageRating. You first need to create a metadata property like AverageRating that maps to the crawled property ows_AverageRating(decimal) to be able to display rating in search results. After adding the property, make sure that you run a full crawl so that the indexer picks up all the ratings.

After adding the property and performing a full crawl, we can use the below XSL to display rating for each item in search results.



 
   
  
    
  
  
    
  
  
    
  
   
   

 
   No Rating
   





 
 
 
   
   
  
  
   
 


Note: I have used 2 icons ratings_halfstar_blue.png and ratings_star_blue.png which are free to download. Make sure that you upload them some where and adjust the paths accordingly.

Ref: http://blogs.technet.com/speschka/archive/2009/10/28/using-the-new-sharepoint-2010-ratings-feature-in-search.aspx

Display SharePoint 2010 Social Tags in Search results XSL

I needed to display the SharePoint 2010 tags in custom search results XSLT.
After a bit of research, I understood that Managed Keywords == Tags
The property that we have to use to get to the tags is popularsocialtags.
But when users specify some terms in Managed Keywords and some in tags, sharePoint does not aggregate them by default. Therefore when we display them in search results, we need to merge them both and sort/filter them using XSLT.

You can expect to see the result from property "popularsocialtags" similar to "||1a8262b5-9c68-466c-9d17-bd446be783b1||24c38c92-b84b-49bd-9431-632222bc6c54|Stone Vendor;#||1a8262b5-9c68-466c-9d17-bd446be783b1"

Below XSL may help you display them delimited by ";" symbols

 
#

Tuesday, April 13, 2010

Problematic OnTaskCreated activity in Workflows

Error: After starting a workflow that uses OnTaskCreated you receive an error message: on a server that is running SharePoint Services 3.0, you receive an error message that states an error has occurred in the workflow

If you are working with Windows Workflow Foundation and SharePoint, it is advisable to not to use the  OnTaskCreated activity. Microsoft admitted the same here

The resolution has been provided by Microsoft in the same page above.

Wednesday, April 7, 2010

SharePoint 2010 - UserProfileApplication.SynchronizeMIIS: Unexpected exception: System.ServiceModel.EndpointNotFoundException

I have tried to do User Profile Synchronization. The status did not change from “Synchronizing” for more than 10 hrs.


I found the following errors in the logs:

UserProfileApplication.SynchronizeMIIS: Unexpected exception: System.ServiceModel.EndpointNotFoundException: Could not connect to http://sp2010index:5725/ResourceManagementService/MEX. TCP error code 10061: No connection could be made because the target machine actively refused it xxx.xx.x.xxx:xxxx. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it xxx.xx.x.xxx:xxxx at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 tim... 6d0e9ede-b3cf-45ac-9c4a-c5800216a178

After starting the “Forefront Identity Manager Service”, the exception disappeared. This can be started through services.msc

After starting the servide, the User Profile Sync worked and the Audiences compiled too..

My coloeague Dave suggested that it is a better practice to stop and start "User Profile Synchronization Service" from Central Admin as opposed to starting the “Forefront Identity Manager Service”,  manually.

Error - The RSS webpart does not support authenticated feeds

'The RSS webpart does not support authenticated feeds'

I encountered this error when I tried to use SharePoint 2010 RSS Viewer Web Part with internal feed (It does not happen with 3rd party feeds)

I had to change authentication provider settings from NTLM to Kerberos. To do this, go to SharePoint Central Administration and click on the Application Management tab. Within the list of options, click on Authentication Providers. Click on Default (should be the only one listed if you are an 'out of the box' set-up). Under IIS Authentication Settings, the checkbox for Integrated Windows authentication should be selected. Change the radio button selection from NTLM to Negotiate (Kerberos). Click Save. If you go and refresh the page containing the RSS Viewer web part, the feed should now be displayed, i.e. it worked for me.

Ref: http://www.joiningdots.net/blog/2007/08/sharepoint-rss-viewer-web-part.html