Pages

Wednesday, January 1, 2014

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

Introduction

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. http://melcher.it/2012/07/sharepoint-2013-create-a-search-service-application-and-topology-with-powershell/

Conclusion

There are plenty of suggestions on msdn. Please check for this solution as well. If this works say thanks to Maximilian Melcher (http://melcher.it/about-me/)

Monday, December 23, 2013

Migrate SharePoint 2010 code (custom solutions) to SharePoint 2013

Introduction

Recently I was assigned to Migrate code which used to develop SharePoint 2010 web parts to SharePoint 2013 web parts. Here I will illustrate how I did it.

Solution

Step 01: Open the Visual Studio 2010 (SharePoint 2010) solution in Visual Studio 2012. 




Step 02: Change the Target framework to .Net Framework 4.5

Step 03: Remove all the SharePoint 2010 assemblies and add SharePoint 2013 assemblies. This is because SharePoint 2010 assemblies are located in 14 hive and in SharePoint 2013 the assemblies are located on 15 hive. The SharePoint dlls can be


  • Microsoft.Office.Server.dll
  • Microsoft.SharePoint.dll 
  • Microsoft.SharePoint.Security.dll 

There are others as well. Please refer MSDN for other common used SharePoint assemblies.

Step 04: Change Control templates/ web part location as below.

From
~/_CONTROLTEMPLATES/{Folder Name}
To
~/_CONTROLTEMPLATES/15/{Folder Name}

Step 05: Change the _layouts location files to /_layouts/15/ location. Usually images, CSS and JavaScript files are added to _layouts folder.

Images
From
/_layouts/images/
To
/_layouts/15/images/

CSS
From
/_layouts/{Folder Name}/css
To
/_layouts/15/{Folder Name}/css

JavaScript
From
/_layouts/{Folder Name}/scripts
To
/_layouts/15/{Folder Name}/scripts

Step 06: In all aspx pages you have to change the reference from SharePoint 2010 asssembly to SharePoint 2013 assemblies. To do this change the assembly version from Version=14.0.0.0 to Version=15.0.0.0

Example.

           


<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>



To

           

<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


Conclusion
Hope this will work for you and please note that sometimes you will need to change the deployment path according to SharePoint 2013. As the above add 15 hive after the mapped folder. If you have set the master page as v4.master you should change to seattle.master

Sunday, December 1, 2013

Adding Left Navigation for SharePoint Publishing site programmatically

Problem Background

I was working on creating a webtemplate based in SharePoint 2013 based on publishing site. There I had an requirement to create Left Navigation programmatic.

Solution Background

Here I have used "Structural Navigation" as the navigation type.

Solution

Below is the method to achieve it.

           
using (SPSite spSite = new SPSite("http://cd-sjamaldeen:23855/sites/002/"))
{
    using (SPWeb spWeb = spSite.OpenWeb())
    {

        //to remove pages from quick launch navigation
        PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(spWeb);
        // Current navigation 
        publishingWeb.Navigation.CurrentIncludePages = false;
        publishingWeb.Navigation.CurrentIncludeSubSites = false;
        publishingWeb.Navigation.GlobalIncludePages = false;
        publishingWeb.Navigation.GlobalIncludeSubSites = false;


        var webNavSettings = new WebNavigationSettings(spWeb);

        // Set the current navigation to Structural Navigation type
        webNavSettings.CurrentNavigation.Source = StandardNavigationSource.PortalProvider;

        // Set the global navigation to Structural Navigation type
        webNavSettings.GlobalNavigation.Source = StandardNavigationSource.PortalProvider;

        webNavSettings.Update();
      

        //add the settings page to the quick launch
        SPNavigationNodeCollection nodeColl = spWeb.Navigation.QuickLaunch;

        //Delete all the navigation nodes from QuickLaunch 
        for (int i = spWeb.Navigation.QuickLaunch.Count - 1; i > -1; i--)
        {
                        
            spWeb.Navigation.QuickLaunch[i].Delete();
        }


        publishingWeb.Update();

        SPNavigationNode googleNode = new SPNavigationNode("Google", "http://google.com");
        nodeColl.AddAsFirst(googleNode);


        SPNavigationNode yahooNode = new SPNavigationNode("Yahoo", "http://yahoo.com");
        nodeColl.AddAsLast(yahooNode);

        spSite.AllowUnsafeUpdates = true;
        spWeb.AllowUnsafeUpdates = true;
        spWeb.Update();
        spWeb.AllowUnsafeUpdates = false;
        spSite.AllowUnsafeUpdates = false;

    }
}
 
 

Conclusion

Hope your publishing site now will have the Navigation.
If you face any problems go to site setting ->  Navigation (Under Look and Feel section) see weather all your navigation setting exists.


Thursday, October 31, 2013

The Web application at "" could not be found in WCF with SharePoint server object model

Problem Background

I was creating a WCF in Visual Studio 2012 using C# as the programming language and when I call SharePoint server object model in the WCF there was an exception saying The Web application at "" could not be found.


Solution Background

Its because IIS hosted WCF sites use ApplicationPoolIdentity as its user. This is not authorized to SharePoint farm. So we have to give farm administrators credential in order to access SharePoint server.

Solution

  • Open IIS 
  • Go to "Application Pools" 
  • Click on your WCF Service site 
  • Click on "Advanced Setting"




  • Click the corner "Identity" under Process Model in order to change the identity

  • Select "Custom account" and click "Set"



  • There give your farm administrator user name and password.

Tuesday, October 1, 2013

Disable the option for creating a new folder in sharepoint 2010

Problem Background

Some of clients want the users nolt to create New Folder in a document library.

Solution

  • Open the specified document library. 
  • Go to "Library Setting"
  • Click "Advanced Setting"

  • Go to "Folders" section and "No" option for "Make New Folder command available"


    Conclusion

    Now the "New Folder" option is disabled.




    But still users can create folders through Explorer Mode. ;)

    Thursday, August 22, 2013

    Create "Shared with Everyone" folder in Sky Drive Pro / Documents library - SharePoint 2013

    Introduction

    As I mentioned in my previous post our team faced issues in document migration from SharePoint 2010 to SharePoint 2013. The actions were not as expected.

    Problem Background

    In some profile we couldn't find "Shared with Everyone" which folder is having "Read" permission to "All Authenticated Users". So we created a console application which will create "Shared with Everyone" folder and set the permission as we needed.

    Solution

    Please pass your personal site (spWeb) to the method.

       
     public static void CreateSharedFolder(SPWeb web)
     {
    
        SPList list = (SPDocumentLibrary)web.Lists["Documents"];
        //Get the folders inside Documents library
        SPFolderCollection folders = web.GetFolder(list.RootFolder.Url).SubFolders;
        List<string> folderList = new List<string>();
        //Add the SPFolderCollection to a generic list
        foreach (SPFolder folder in folders)
        {
            folderList.Add(folder.Name);
        }
        //Check whether folder list has shared with everyone folder
        if (!folderList.Contains("Shared with Everyone"))
        {
    
           //Create folder inside Documents library 
           folders.Add("Shared with Everyone");
    
           //Greate users
           SPUser allUser = web.EnsureUser("NT AUTHORITY\\authenticated users");
           //Get folder
           SPListItem item = list.Folders[0];
           if (!item.HasUniqueRoleAssignments)
               item.BreakRoleInheritance(true);
    
           SPRoleAssignment roleAssignment = new SPRoleAssignment(allUser);
           SPRoleDefinition roleDefination = web.RoleDefinitions["Read"];
                    //Add role assignment
           roleAssignment.RoleDefinitionBindings.Add(roleDefination);
           item.RoleAssignments.Add(roleAssignment);
           web.AllowUnsafeUpdates = true;
           item.Update();
           web.AllowUnsafeUpdates = false;
    
        }
    
    }
     
     


    Conclution
    Now you can see "Shared with Everyone" folder inside SkyDrive pro.

    Thursday, August 15, 2013

    Move (Personal) Documents into SkyDrive Pro after migrating from SharePoint 2010 to SharePoint 2013

    Introduction

    If you have working on migrating SharePoint 2010 personal sites to SharePoint 2013 personal sites;  documents migration may become a headache. The expectation of the action is
    "The Personal and Shared document libraries in SharePoint Server 2010 are combined into the SkyDrive Pro document library on the user's My Site in SharePoint Server 2013. Items from the Shared folder are stored in the Shared with Everyone folder in SharePoint Server 2013. Items from the Personal folder are stored at the root of the SkyDrive Pro document library and only shared with the owner of the My Site." - MicroSoft

    Problem Background

    But in our case, the documents didn't shift under SkyDrive but they were seen under site contents as another document library.

    So I wrote a console application to move all the documents to SkyDrive. Here I'm presenting a simple code snippet which you have to modify to use other document library and sub folders under document library. 

    Solution 

    private static void MovePersonalDocuments(SPWeb web)
    {
     SPFolder folder = web.GetFolder("Personal Documents");
     SPFileCollection collFile = folder.Files;
     ///*Copy the files to a generic List of type SPFile*/
     List listFiles = new List(collFile.Count);
     foreach (SPFile oFile in collFile)
     {
      listFiles.Add(oFile);
     }
     SPList list = (SPDocumentLibrary)web.Lists["Documents"];
     for (int i = 0; i &lt; listFiles.Count; i++)
     {
        SPFile movefile = collFile[0];
        Console.WriteLine("Moving File: " + movefile.Name);
               web.AllowUnsafeUpdates = true;
        byte[] fileBytes = movefile.OpenBinary();
        string destUrl = list.RootFolder.Url + "/" + movefile.Name;
        movefile.MoveTo(destUrl, true);
               web.AllowUnsafeUpdates = false;
       Console.WriteLine("Success");
     }
    }

    Conclusion 

    • Please note that I have only considered moving Personal Documents.
    • The code will help to move Shared Documents and Sub folders as well.