Wednesday, April 30, 2014

Map Icon URL for SharePoint webpart

Scenario :
I have come across to develop a webpart, which is to list certain assets from SharePoint library. The key is to display icons for each asset in the webpart, so that end user can easily identify the type of assets listed in the webpart. If you do not use the SPUtility method to map the icon URL, you have to go on a hard way to identify the file extension and map the relevant icon from style library.

Solution :
The SPUtility.MapToIcon(SPWeb, string, string, IconSize) allows you to retrieve the relevant icon file name, which resides inside hive folder.
Then you just need to concatenate the retrieved icon URL with hive relative folder to make the URL server relative. Check the following for the reference :

SPUtility.ConcatUrls("/_layouts/15/images/", SPUtility.MapToIcon(item.Web, SPUtility.ConcatUrls(item.Web.Url, item.Url), "", IconSize.Size16));

You may check the documentation from Microsoft for further reading here.

Further Notes :
MP3/MP2 icons are not available in the hive by default. You need to add those icons with 16*16 size to hive folder and update the  DOCICON.XML file.

In order to automate the above scenario, you may add a feature event receiver to update the DOCICON.CML file.


public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
            string[,] iconInformation = new string[,] { { "mp3", "ICMP3.png" }, { "mp2", "ICMP2.png" } }; 
            string docIconXml = SPUtility.GetVersionedGenericSetupPath(string.Format("Template\\XML\\{0}", "/DOCICON.XML"), 15);
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(docIconXml);
            XmlNode documentElement = xmlDocument.DocumentElement;

            for (int i = 0; i < iconInformation.Rank; i++)
            {
                XmlNode iconNode = documentElement.SelectSingleNode(string.Format("ByExtension/Mapping[@Key='{0}']", iconInformation[i, 0]));
                if (iconNode == null)
                {
                    iconNode = xmlDocument.CreateElement("Mapping");
                    iconNode.Attributes.Append(xmlDocument.CreateAttribute("Key")).Value = iconInformation[i, 0];
                    iconNode.Attributes.Append(xmlDocument.CreateAttribute("Value")).Value = iconInformation[i, 1];
                    bool wasAdded = false;
                    XmlNode byExtensionNode = documentElement.SelectSingleNode("ByExtension");
                    foreach (XmlNode node in byExtensionNode.ChildNodes)
                    {
                        if (node.Attributes["Key"].Value.CompareTo(iconInformation[i, 0]) > 0)
                        {
                            byExtensionNode.InsertBefore(iconNode, node);
                            wasAdded = true;
                            break;
                        }
                    }

                    if (!wasAdded)
                        byExtensionNode.AppendChild(iconNode);

                    xmlDocument.Save(docIconXml);
                }
            }
}



Happy coding!

Thursday, October 17, 2013

CRM 2013 Sandbox Plugin : System.TypeLoadException

Scenario​ :
Congratulations to the Microsoft CRM team, the new launch of CRM 2013 absolutely changed the way how it is presented to the customer but it has not changed in the way of developing components or plugin for it. Since this is a transition time from CRM 2013 RC to CRM 2013 RTM, I should put forward the following observation on the table. When it comes to the sandbox plugin development, if you have already started to develop on RC, the LINQ data context does not support for quering entities. It gives the following error -
"System.TypeLoadException: Inheritance security rules violated by type : XXXXX. Derived type must either match the security accessibility of the base type or be less accessible."



Solution​ :
The solution is, its time for you all to work on the RTM version and not on the RC version. In addition to this, make sure once you have installed the RTM version, you need to re-generate the data context class with the CrmSvcUtil.exe

Thursday, October 10, 2013

Uninstall Language pack from CRM 2013

Scenario​ :
Many of you might have experienced following problem while you try to uninstall the existing Language pack from CRM 2013 server. If that is same as following why you are investing much of the time to investigate the reason behind it and resolve, Well because I have the answer for you.

 This is because, the setup is trying to uninstall but the admin does not have the permission to uninstall. Then how come Admin cannot execute the administrative task. :)
Solution :
The uninstallation process have to be done in elevated privilege mode. In order to do that, we need to identify the installation unique id.
  • Go to Regedit (Run > RegEdit)
  • Navigate to HKLM > Software > Microsoft > Windows > CurrentVersion > Uninstall
  • Find the language pack installation by going over all the GUID and from details panel.


  • In the properties panel, copy the value for "UninstallString". In my case, it is MsiExec.exe /X{0C524DC1-1407-0060-8121-88490F4D5549}
  • Run the command prompt with administrative mode
  • Execute the copied command
Thats it, you are uninstalling the language pack without any problem.

Tuesday, August 28, 2012

Cannot Access File 'XXXX' because it is being used by another process - Error on Copying DLL to GAC

This post highlights one of the most common development environment issue you would encounter, when you try to show your tricky deployment steps.

Problem
Most of you all would not depend on the fresh deployment, where there is a possibility to ‘GAC’ the DLL. But in some cases, you would get an error message as follows, when you would try to pull the old DLL out and to put the new DLL in.


Solution
      1.      Get the list of all the processes attached to the interested DLL.
      Use the following command to list all the processes along with the ID.
      Tasklist /m <DLL Name.dll>
      E.g :







     Terminate processes/services shown in that list.
     In my case I had to release the DLL from the SharePoint timer job and the SharePoint worker process. This can be achieved by restarting the SharePoint service and recycling the IIS Pool/resetting the IIS  Server respectively.

     2.   In some cases, having done the above steps would repeatedly showing the same error message as shown      at the start. In such circumstances, you need to consider certain application running in the server. This can be Visual Studio/PowerShell.
Restarting those application would help you to get rid of the above problem.

Thursday, July 5, 2012

Search Settings Properties - PowerShell

This time, I’m going to shed some light on how to set the property values for the Search setting page.
I have a web-application and it is having many site collection with variation site to support for different languages. Each variation site is having its own content. When the user search from a particular variation site, the results should be shown inside the variation site itself. For that, If I set the Search results location at site collection level, that will be applied all across to the variation sites as well. In order to avoid that, we need to set the Site Collection Search Center value to Do not use custom scopes.

Search Settings Page


So my question is, how are you going to set that property for wsp deployment scenarios. When it comes to large level of projects with multiple site collection with variation sites, configuration are the pain points in the deployment process.
In order to automate and set the property values, I choose the PowerShell script.

The page is setting the values from the values stored in the Root web, property bag.

E.g:
In order to set the Site Collection Search Center value,

$web = Get-SPWeb –Identity http://server1/
$web.AllProperties[“SRCH_ENH_FTR_URL”] = “/en/SearchCenter/Pages”
$web.Update()


If you want to select the second radio button,

$web = Get-SPWeb –Identity http://server1/
$web.AllProperties[“SRCH_ENH_FTR_URL”] = $NULL
$web.Update()


If you want to select the second dropdown item, (Refer the table below for setting other values in that dropdown)

$web = Get-SPWeb –Identity http://server1/
$web.AllProperties[“SRCH_SITE_DROPDOWN_MODE”] = “HideScopeDD_DefaultContextual”
$web.Update()


If you want to set the search results page url,

$web = Get-SPWeb –Identity http://server1/
$web.AllProperties[“SRCH_TRAGET_RESULTS_PAGE”] = “/en/searchcenter/searchPages/”
$web.Update()



Key
Value
SRCH_ENH_FTR_URL
NULL or URL
SRCH_SITE_DROPDOWN_MODE
SRCH_TRAGET_RESULTS_PAGE
URL



Tuesday, June 19, 2012

Hide Selection Check Box in the Web Part Title Using a Content Editor

Recently I was engaged in a OOTB SharePoint project. I got a requirement to remove the Select Deselect check box which is shown to the anonymous users as well. Since the master page cannot be customized I used a simple trick using a content editor web part.





1) Add a content editor web part in the page which the check box has to be removed.
2) Simply add the following style to the content editor
  <style>
    .ms-WPHeaderTdSelection
    {
         display none;
     }
  </style>

Remember to set the Chrome type to None since this web part is a hidden one.Save and publish the page.

Sunday, February 19, 2012

Application Server Role: Web Server (IIS) Role: Configuration Error

Scenario
Last week was full of challenge on integrating SharePoint 2010 with JDEdwards ERP system. But the challenge turn around to a new dimension on migrating the SharePoint 2007 to SharePoint 2010 in Widows SBS 2008. Even though Microsoft has released a white paper here on how to migrate specifically on SBS 2008 server, there are few arguments going on with the validity and the comprehensiveness of the above white paper.

Problem
I ran into a trouble when I start to execute the Step 5, where the pre-requisites were not installed successfully, rather ended up with an error message saying  “Application Server Role: Web Server (IIS) Role: configuration error”. The error log repeated log the above line more than 25 times.

Solution
After few hours of googling,
  • Verify whether “World Wide Web Publishing Service” is started
  • Install  KB971831

After doing above steps, I could able to successfully re-install the pre-requisites and continue on with SharePoint migration.