Showing posts with label SharePoint 2010. Show all posts
Showing posts with label SharePoint 2010. Show all posts

Monday, July 22, 2013

Get all seach scopes for current site collection

In this article we will be seeing about search scopes in SharePoint 2010.|

In this article:
  • Add namespaces
  • Get search context
  • Get all scopes
  • Skip default scopes
  • Add scopes in dropdown
Get all the search scopes:

Add following namespaces.

using Microsoft.Office.Server;
using  Microsoft.Office.Server.Search.Administration;

Use following method to populate all scopes of current site collection in dropdown.

private void GetScopes()
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
// Get the search context object.
SearchContext context = SearchContext.GetContext(site);
Scopes scopes = new scopes(context);
foreach(Scope scope in scopes.GetSharedScopes())
// Skip following default scopes
// Global Query Exclusion - Everything that should be omitted from all search by default
// Rank Demoted Sites - Sites whose rank will be demoted in click - distance calculation.

if(scope.Name != "Global Query Exclusion" && scope.Name !="Rank demoted Sites")
// Show scopes in dropdown

Sunday, July 7, 2013

CAML Query to get all documents from a Document Library

CAML query to retrieve all documents from all folders in a document library.

SPList lstDocs = SPContext.Current.Web.Lists.TryGetList("myDocLib");
SPQuery query = new SPQuery();
query.Query = @"<Where><BeginsWith><FieldRef Name = 'ContentTypeId' /><Value Type= 'ContentTypeId'>0x0101</Value></BeginsWith></Where>";
query.ViewAttributes = "Scope = 'RecursiveAll'";
SPListItemCollection itmsDocs = lstDocs.GetItems(query);

Wednesday, August 29, 2012

Lookup field dropdown position issue

I was trying to create a custom webpart that will display a form to submit data in a list. The list had few lookup fields.
Whenever, I click on that image it displays us with a drop-down containing all the values, but the funniest part is you can select a particular item either by double click or by selecting it once and clicking it else where on the page or by tabbing system of the keyboard. But I want it work like a normal drop-down selection in other words just with a single click and also the control should be closer to other controls from usability perspective.

To fix this issue. you need to set InDesign ="true";

 Ex.BaseFieldControl webControl = field.FieldRenderingControl;

webControl.ID =
string.Format("ctrl_{0}_{1}", field.InternalName, pplCount);

webControl.FieldName = field.Title;

webControl.ItemContext =
SPContext.GetContext(HttpContext.Current, lstReqData.DefaultView.ID, lstReqData.ID, lstReqData.ParentWeb);

webControl.RenderContext = SPContext.GetContext(HttpContext.Current, lstReqData.DefaultView.ID, lstReqData.ID, lstReqData.ParentWeb);

webControl.ControlMode = SPControlMode.New;

webControl.ListId = lstReqData.ID;

webControl.InDesign =

 If you are using form field you can set it by following changes in aspx page

<SharePoint:FormField runat="server" InDesign="true" ID="myFieldId" ControlMode="New" FieldName="myFieldName" />

Wednesday, June 6, 2012

Use Metadata Navigation in Wiki Pages (Sharepoint 2010)

If you want to use Metadata navigation tree in Wiki Page, you have to do the following:
  • Activate Metadata Navigation and Filtering feature on site level
  • Navigate to Library settings page of your “Pages” library and select Metadata navigation settings
  • From “Configure Navigation Hierarchies” select “Wiki Categories” and click “Add” and “OK”
  • Navigate to Pages library again
http://<Your Wiki Site Url>/Pages/Forms/AllItems.aspx

But when you click on any of the pages on the right panel, the navigation tree will disappear.


You have to change the master page or better to create and deploy a new one (via Sharepoint Designer or wsp)
You have to include a reference to MetadataNavTree control and put it in some placeholder (QuickLaunchNav) on the master page file.
  • Put this markup in the beginning of the page
<%@ Register TagPrefix="wssuc" TagName="MetadataNavTree" src="~/_controltemplates/MetadataNavTree.ascx" %>
  • Put this code in <asp:ContentPlaceHolder id="QuickLaunchNav" runat="server"> tag
<asp:ContentPlaceHolder id="QuickLaunchNav" runat="server">
<wssuc:MetadataNavTree id="mdnt" runat="server" />

The result is: