Monday, August 15, 2011

SharePoint Search using Scope

In SP, you can easily slice and dice your content to search a specific document library or list. Last week, I posted an article that can be used when you want to search a given list on specific columns that are not exposed directly by METADATA.

In my experience, the below article would cover several business needs. These needs are specific to the clients I have worked with on Search. One of the needs is that we have so much of simillar data that when we search we get too much of results and not directly from the library that we are interested to get the data from. The other need is I need to get a list of all documents that have been modified/created/ by a user/date in this document library. You could have used a view here, but then that is specific and the user has to be educated. This cannot be dynamic.

Today, I am going to be documenting an Out of the BOX Scope feature that can be used perform a search specific to library/List/Sub Site. A user with site collection admin perms, can go to Site Settings->Search Scopes and then add a new Scope. Once you add a new item, then you can define the rules that are specific to the new Scope. After this, you have a choice of displaying this new Scope element in search box next on the top of the page and in the Basic Search Center's Advanced Search Page.

Assuming you have managed to get the above steps completed. Now, you need to go back to Central Admin- Services on Server-> Search-> Search and do a full crawl to have the new scope reflected in the Search Center. Once this has been completed, go back to Basic Search Center's Advanced Search Center page and you will be able use the new scope.
The same scope can also be developed using Visual Studio. This may be necessary when you have to repeat a process in multiple environments. In addition, some organizations don’t allow any direct updates so in that case you would need to write this scope via Feature and deploy it in your appropriate environment.
Next topic: Best Bets!

Friday, August 12, 2011

SharePoint Search on a Specific Document Library/List

How can you use OOTB search to perform search on a single specific list? When you perform a search, it will search those areas depending upon your content source, which is never specific to a single library containing documents. How can you perform a search where it only pulls the data from this given document library? You could use a common document property and then map it to perform your search. However, this is not a very consistent approach as some users may forget to do so. Therefore, it is better to use a column to create this feature. An alternative approach is to simply use scopes!

The key concept here is a metadata property that needs to be used. In this document, I will very briefly walk you through the process and show you how this can be extended to N number of document libraries. The same process can easily be applied to a list.

1: Create a document library for some finance group that you want to have a specific search upon. If that library exists, create a new column and call it MySearchColumn with a default value (Finance) and make sure the column is marked as not required field. Better, create a site column and then use it in this list. I will come back to why I suggested a site column.

2. Next, Go to the advanced setting of the Library and click on Manage content types. Once you do that, you will see the option to hidden the MySearchColumn from the form. This is a neat trick to hide the extra irrelevant column from the user and still maintain consistency. You could have let this column be there and the user could have asked you several questions. You could have educated the user on why you have this column in its place. You could have also written an event handler to ensure the value is consistent.
3. Now try adding a new document to the library and the MySearchColumn is not displayed on EditForm.aspx. Note, it will be visible from the “All Documents” view, but you can change this once you have completed the task.
4. Go to Central Administration -> Search Service Application->Search Administration and do a crawl. The reason you have to do this is so that the newly added column will be displayed in the MetaDataProperty.
5. Now create a new Meta Data Property by giving it a name “MyMetaDataProperty” that is mapped to ows_MySearchColumn. You should see this ows_MySearchColumn when you go to AddMapping. If you don’t see the column then there is a problem with your crawler or field name.
6. Next create a “Basic Search Template” that will be used to perform the search. When this is created a basic search page gets displayed. Click on the “Advanced Search”. On this page, edit the “advanced search webpart” to include this new property that you have created in Search Administration. When you click edit webpart, it displays you properties of the web part you can change. Click on properties section to open the box and then copy the XML into an XML editor where you need to add simillar following lines


Then, you need also include in the results section


7. Once this is completed, you should see 1 more managed property. Now, start a full crawl from
“Search Admin” and not an incremental crawl as the data from the new property will not show up.

8. Go to Advance search and choose the new property from the drop down below and choose equals “Finance” and perform you search. You should see results coming from that 1 single document library.

9. Similarly, if you have more document libraries you can reuse the same site column, but with a different value. The advantage of this approach is that you don’t have to set another meta data property and just put different value and you can now search exclusively in a different document library.









Wednesday, July 27, 2011

Power of Delegate Control- What/Why/How

I get a lot of questions from junior developer as to why use a delegate control and how do you implement a delegate control?

A delegate control is a control that will be rendered. The key thing here is that at the run time it finds all controls with the same id and then adds to tree the control with lowest seq number. The delegate control is mainly added to Master Page that is tied to your site. If you view the Master Page's code you will find several delegate controls as those are added by SP.

Why use a delegate control?
You will choose to use a delegate control if you want to add some code that is rendered on every single page in your site. The alternative way is you would add a user control containing your code to every single page on your site. If you create new page, then you have to remember to add this user control. This is not the best approach and for this reason you create a delegate control and add it to Master Page and then it is rendered on every page that uses this MasterPage. You can have more than 1 delegate control of the same ID, but the delegate control with the lowest seq will get added to the tree to render.

How do you create a delegate control?
There are 2 things involved in a delegate control.
- Master Page
- User Control created using Visual Studio.

Steps required to create DC
1. Create a new Empty SharePoint 2010 Project.
2. Map it to ControlTemplate Folder.
3. Right Click on ControlTemplate Folder and add a User Control.
4. Add your code in the User Control.
5. Right click on the project and add a module. This will create Elements.XML file
6. In the elements.xml add this code:





7. Delete the feature that got created and then add a new feature with a more meaningful name with information.
8. Open your MasterPage that is beeing used by your Site and add code like this

at top around the GlobalNavigation control.
9. Deploy your code and test it.

Where / How to store email address in SharePoint 2010 when using Claims

When you are using Claims based authentication method, the user is never added SharePoint SiteCollection unless the user has logged to the site for the 1st time. However, when a user logs into the site for the first time, its identifier is only stored in a UserList List.

If you have a need to send emails to user as per of workflow or alert or anything, you need to find a place to store them. You could easily use the UserList to store this information. As a user is entering your site, you could write code to query the claims to extract email address the user primarily has and then extract that value and store it to the User List.

The location of this list http://myserver/_catalogs/user/Simple.aspx

Specail Consideration with this list:
- User List is very notorious as to when it updates the data.
- Initially when you create a new Site Collection, this list shows less than 15 columns and then a timer job runs and it adds around 40 more columns to the list.
- This list can only be seen by Site Collection Admin and above.
- In order to update to this list, you should ue run with elevated privs.

I will post some sample code soon.

Monday, July 25, 2011

Auto Increment Columns in SharePoint 2010/MOSS

As more and more applications are using SharePoint to store data and they want it to work simillar to SQL. How do you create auto increment columns?

The process is pretty cool. It would require sing SPD workflow.

Here are the steps:
-Add another column to list (Note: You cannot use ID as that is the internal column)
-List Settings->Advanced Settings->Manage Content.
-From List Settings page, click Item Content Type, and then click new column name.
-Next, choose the option to hide the column in the form.
-Goto SPD and create a workflow with "Update Item" in the list action and then set the new column to a value with current item:ID .
-Check for errors->Publish - >Save
-Finally, don't forgot to check the workflow to be staretd automatically as this is not the default.

Demystify Title Column in SharePoint 2010 List/MOSS

When you create a new SP List, you see a default Title column. If you try to delete this column, you don't see the option to delete when you goto List Settings->Columns. Have you wondered why you cannot delete this column?

The answer is because when you create a custom list, it is created with "Item" content type. This "Item" content type has 1 field and it is required field.

How do you delete the Title column?

Goto List Settings->Advanced Setting -> Choose Manage Content Types.

Then, from List Settings-> Click Item Content Type and there you will get the optional to make changes to Title column!

Monday, July 18, 2011

Different Kinds of Pages in SharePoint 2010

Did you know there are 3 kinds of pages in SharePoint 2010

- WikiPages -> A new kind of page available in SharePoint 2010. Used primarily like a free for all wiki page for adding Tables etc. This may contain WebParts

- WebPart Pages -> Existed in SP2007 and SP2010 -> A more structured page with layouts/zones/webparts etc.

- Publishing Pages ->Specifically for publishing

In addition, there are Application pages that are physically stored on the server.