SharePoint 2010 “wildcard” search

Wildcard search was one thing which was very dearly missed in MOSS 2007 and WSS 3.0. SharePoint 2010 has introduced this functionality which is quite helpful. However, though with some caveats

So you perform a search and you do not get any results and you keep wondering what have you done wrong

You have to search for “Brian” and you enter the following to search and do not get any results

e.g. Bria (this will not return you results starting with “Bria”)

That is correct behaviour as Sharepoint supports wildcard search only if you append “ * ”at the end of your keyword

e.g. Bria* (this will return you all the results starting with “Bria”)

Wildcard searches can be used in property searches as well

e.g. Author:Bria* (this will return all results where Author starts with “Bria”)

Also, wildcards only work at the end of a search string,

A wildcard at the beginning of a string will not be recognized, so searching for

e.g. “*rian” (this will not return you any results)

Checking if a site is a publishing site programmatically

There are time when you need to check if a site is a “Publishing Site”. Use the following code snippet to check if a site is a publishing site or not

SPSite site = SPContext.Current.Site;

if (PublishingSite.IsPublishingSite(site))
{
    //it is a publishing site
}
else
{
    throw new System.ArgumentException("The SPSite is not a Publishing Site", "site");
}

Similarly, if you want to check for the Publishing Web the use the following snippet

SPWeb web = SPContext.Current.Web;

PublishingWeb publishingWeb = null;
if (PublishingWeb.IsPublishingWeb(web))
{
    publishingWeb = PublishingWeb.GetPublishingWeb(web);
}
else
{
    throw new System.ArgumentException("The SPWeb is not a PublishingWeb", "web");
}

Till then happy coding!!

Minimize a SharePoint web part programmatically

We have lot of times minimized a web part on a SharePoint page. That day there was a requirement to minimize the web part programmatically. It’s simple, see it how


this.ChromeState = PartChromeState.Minimized;

ChromeState options are Minimized or Normal, with Normal being the default. Normal will display your Web Part on the site in its entirety, whereas Minimized will display only the Web Part’s title bar

SharePoint Web Application virtual directory folders and files significance

Whenever we create a new “Web Application” in SharePoint few things are created in background. What I mean to say that creation/provisioning of a web application leads to creation of a few things in background

  1. An IIS Site
  2. A content database
  3. A virtual directory

Today, I am going to focus on the “virtual directory” and it’s significance.
“Virtual Directory” is just a container of files. It’s just a logical way to organize your web-site and physical directories . Typically the virtual directory for SharePoint web application is created at the following location
e.g. C:InetpubwwwrootwssVirtualDirectories80
If you have a look at this directory it typically has the following files and folders. Let’s have a look at each of them and their significance

virtual directory
virtual directory
_app_binThe _app_bin folder was designed to hold application assemblies which were previously installed in _layouts/bin. Web Part assemblies are *not* supposed to be installed in this folder. Put your assemblies in GAC or the bin, but not the _app_bin.
_vti_pvtThis folder is used by FrontPage Extensions/SharePoint Designer. It contains Legacy FrontPage Server Extensions files/folders. The reason for having these folders is that they provide the underlying infrastructure files for the many features SharePoint Designer provides.
BinContains compiled assemblies (.dll files) for controls, components, or other code that you want to reference in your application. Any classes represented by code in the Bin folder are automatically referenced in your application.
App_BrowsersContains browser definitions (.browser files) that ASP.NET uses to identify individual browsers and determine their capabilities.
App_GlobalResourcesContains resources (.resx and .resources files) that are compiled into assemblies with global scope. Resources in the App_GlobalResources folder are strongly typed and can be accessed programmatically.
wpresourcesContains configuration file for Web Parts
aspnet_clientThis directory contains JavaScript files that are used by the ASP.NET runtime for client-side validation functionality This directory is created automatically when ASP.NET is enabled on your site. This directory is not required for ASP.NET applications to run. It is only required if you are using client-side validation with ASP.NET server validation controls.
Global.asaxThe Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for responding to application-level events raised by ASP.NET or by HttpModules.
Web.configThe Web.config file is the primary configuration file having all the configuration details for the web application (IIS site)