Thursday, January 23, 2014

Enable auditing for a specific content type through "Content Type Policy Templates" in SharePoint Online | SharePoint 2013


Recently our client project had a requirement where a document type (or a content type) should be audited for its events such as editing items and checking in and checking out items, and also the policy should be reusable for other content type when we need. When I consult my architect he in instruct me how to do it. So I thought to share how I did this.

  • First of all you have to create a policy. 
    • To create Go to Site Setting -> Select Content Type Policy Templates (under Site Collection Administration category).
    • There select Create. The Url will end with “_layouts/15/policyconfig.aspx”.
    • Create a policy as you need. As per to my requirement I need an auditing policy. I created a policy enabling Auditing by selecting Enable Auditing option – Please refer the screenshot given below.

  • Then Select the content type which you should enable auditing. You can select the content type by going to Site Setting -> Click Site content types (under Web Designer Galleries) -> Select the content type you wish to add the policy.
    • In case you don’t have a content type; to create go to Site Setting -> Click Site content types (under Web Designer Galleries )
    • Select Create option on the top and create a content type as you need.
  • Select the “Information management policy settings” under setting.
  • You will see something like this.
  • There select “Use a site collection policy:” (the 3rd option) and select your policy name and click OK.
  • Now you have associated the auditing policy with the content type. 
  • Your logs reports can be seen under Go to Site settings -> Site Collection Administration -> Audit log reports.


You can also create a new policy at the Content Type -> Information management policy settings. But this will applicable only for the specific content type and you cannot be reusable for other content types; simply its a content type policy and not a site collection policy.

Friday, January 3, 2014

Show SharePoint Search Results in SPGrid View - programmatically


As I said in my earlier post I was working and trying some stuff related to SharePoint 2013 search server. Today I was trying to query and display search results in SPGrid view. I have uploaded my solution package in my drive; Please download and look for the code if you need. (Download)
I used certain blog posts as references.


Create a web part (I have created visual web part). On the .ascx page initiate a SPGridView. (For that you can use the below code)
On the ascx.cs page do the blow
On page load


        protected void Page_Load(object sender, EventArgs e)

           string query = string.Format("Project*"); //You can give what ever query you need


And also you need below both methods. So please paste them also on the ascx.cs page


        void ExecuteFederatedQuery(string queryText)
            long lastupdate;
            bool crawl;

            //Create Search service proxy
            SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy

            LocationConfiguration locationConfig = null;
            LocationConfiguration[] locationConfigurations = proxy.GetLocationConfigurations(out lastupdate, out crawl);//Get all federated search locations. 
            Location location;
            LocationList locationList = new LocationList();
            QueryManager queryManager = new QueryManager();
            foreach (LocationConfiguration locationConfiguration in locationConfigurations)
                //Specify any federated search location. Here default search location will be captured.  
                if (locationConfiguration.InternalName.Equals("LocalSearchIndex"))
                    locationConfig = locationConfiguration;
            location = new Location(locationConfig.InternalName, proxy);
            //Set the userQuery
            location.UserQuery = queryText;
            XmlDocument xDoc = queryManager.GetResults(locationList);//Return the query
            if (xDoc != null)
                DataSet resultSet = new DataSet();
                resultSet.ReadXml(new XmlNodeReader(xDoc));




        private void SortData(DataTable resultTable)

            //Sort the results by Title name
            DataView dataView = resultTable.DefaultView;
            dataView.Sort = "Title ASC";
            DataTable resuDataTable = dataView.ToTable();

            var fileTable = new DataTable();

            DataRow fileRow;

            foreach (DataRow resultRow in resuDataTable.Rows)

                fileRow = fileTable.NewRow();
                fileRow["Title"] = resultRow["title"];
                fileRow["DocURL"] = resultRow["url"];
                fileRow["Modified_Date"] = resultRow["lastmodifiedtime"];
                fileRow["Authors"] = resultRow["author"];


            //Assign the datasource
            spGridView.DataSource = fileTable;




The results will look something like this.

Wednesday, January 1, 2014

SharePoint 2013 Search is not working - "Search has encountered a problem that prevents results from being returned"


Happy New Year! I was working on SharePoint search where our client had a requirement on retrieving data through SharePoint search. Hopefully my upcoming posts will be related to SharePoint Search Server.

Problem Background

Suddenly my Search Service stopped working and it didn’t return results. My “Search Results” Web part show the error with the message “Search has encountered a problem that prevents results from being returned. If the issue persists, please contact your administrator.” See the screenshot below. Please note that I couldn’t capture the screenshots from my server and the screenshots are taken from the net.

Then when I try to open Search Service Application there also, I was able to see some error message.

Under “System Status (Name of Search application service => search administration => System Status)”; “Searchable items” showed “All Errors”.

And also Search Application Topology showed a error message as 
“Search Issue Unable to load the topology from the Search Administration component”. Ideally this should show something like this (See the below Screenshot).

When I try to see ULS log; I got the below error log

Content Plugin can not be initialized - list of CSS addresses is not set.

Solution Background

The issue is that SharePoint Search is unable to load the topology from the Search Administration component.

Solution 01

Recreate the Search Service Application using the Central Administration

Solution 02

The first Option didn't work for me. So I created the Search Service Application through the PowerShell which worked fine. Please go to the below Url and you can find the script to create service application from the scratch.


There are plenty of suggestions on msdn. Please check for this solution as well. If this works say thanks to Maximilian Melcher (