Thursday, July 6, 2017

SharePoint 2013 Global Navigation Menu Alignment and Display

Add below CSS to Content Editor WebPart and it will resolve problem.
<style>
.ms-core-listMenu-horizontalBox .menu-item.ms-core-listMenu-horizontalBox  
.menu-item .additional-background.ms-core-listMenu-horizontalBox  
.menu-item .additional-background .menu-item-text { display:block; }
ul.dynamic { min-width:175px; }
span.menu-item-text:hover { 
background-color:rgba(205,230,247,0.5);
padding:2px;
}
span.menu-item-textpadding:2px;
}
</style> 

SharePoint 2013 Search REST API

You can use the Search REST service to submit Keyword Query Language (KQL) or FAST Query Language (FQL) queries in your apps for SharePoint, remote client applications, mobile applications, and other applications.

The Search REST service supports both HTTP POST and HTTP GET requests.

GET requests

Construct the URI for query GET requests to the Search REST service as follows:

/_api/search/query

For GET requests, you specify the query parameters in the URL. You can construct the GET request URL in two ways:
  • http://server/_api/search/query?query_parameter=value&query_parameter=value
  • http://server/_api/search/query(query_parameter=value&query_parameter=)
POST requests

You construct the URI for query POST requests to the Search REST service as follows:

/_api/search/postquery

For POST requests, you pass the query parameters in the request in JavaScript Object Notation (JSON) format.

Disabling ParserEnabled affect: SharePoint 2013

Disabling ParserEnabled affect:
  1. We can't search in document library using Office document properties.
  2. When you upload image file. Thumbnail will not be generated.
  3. When you save a list template, You will not see it in list template gallery.
If you need to disable this property you need to take care of its effect. Disable it only in special sites. if you want it when you upload document using code disable it temporary using code like below:

using (var site = new SPSite("http://sharepoint-portal"))
{
    using (var web = site.OpenWeb())
    {
       SPFile file = web.GetFolder("Documents").Files["mydoc.docx"]; 
       using (var fs = new FileInfo(@"C:\Documents\mydoc.docx").OpenRead())
 
       {
        documentBytes = ..... // get the documents bytes
       }
       web.ParserEnabled = false;
       web.Update();
       file.SaveBinary(documentBytes);
       web.ParserEnabled = true;  
       web.Update();
    }
}

SharePoint SPWeb Property ParserEnabled

ParserEnabled :- property controls demotion and promotion.
Promotion :- The process of extracting values from properties of a document and writing those values to corresponding columns on the sharepoint list or document library where the document is stored.

Demotion :- The same process in reverse.Read sharepoint list or library columns values and written to document properties.

When ParserEnabled property false there will not be any property demotion and promotion, which means metadata and document file properties will not be in sync.

PowerShell way of Disabling and enabling this property:
Disable ParserEnabled property:
    [system.reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint")
    $site = new-object Microsoft.SharePoint.SPSite("http://mossweb/sites/test")
    $site.RootWeb.ParserEnabled = $false
    $site.RootWeb.Update()

Enable ParserEnabled property or document property promotion:
    $site.RootWeb.ParserEnabled = $true
    $site.RootWeb.Update()

Friday, June 30, 2017

Display Custom Metadata in the Advanced Search Web Part within SharePoint

                        string advancedUrl = newSearchWebSearch.Url + "/Pages/advanced.aspx";
                        SPFile advanceFile = newSearchWebSearch.GetFile(advancedUrl);
                        if (advanceFile.Exists)
                        {
                            advanceFile.CheckOut();
                            //Get Result search page
                            SPListItem wikiItem = advanceFile.Item;
                            string managePropertyname = strSubjectAreaName + getPropertyType(newSearchWeb, strSubjectAreaName), managePropertytype = getPropertySearchType(newSearchWeb, strSubjectAreaName), managePropertyDisplayName= strSubjectAreaName;


                            SPLimitedWebPartManager advsearchwebPartManager = newSearchWebSearch.GetLimitedWebPartManager(advancedUrl, PersonalizationScope.Shared);
                            foreach (var wsp in advsearchwebPartManager.WebParts)
                            {
                                if (wsp is AdvancedSearchBox)
                                {
                                    var wpAdavance = wsp as AdvancedSearchBox;
                                    string SearchQuery = wpAdavance.Properties.ToString();
                                    XmlDocument xmlDocs = new XmlDocument();
                                    xmlDocs.LoadXml(SearchQuery);
                                    XmlNodeList category1 = xmlDocs.SelectNodes("/root/r");
                                    XmlNodeList category = xmlDocs.SelectNodes("/root/PropertyDefs");
                                    XmlNodeList resulttype = xmlDocs.SelectNodes("/root/ResultTypes/ResultType");

                                    var newProperty = xmlDocs.CreateNode(XmlNodeType.Element, "PropertyDef", "");


                                    var property_attribute4 = xmlDocs.CreateAttribute("Name");
                                    property_attribute4.Value = managePropertyname;
                                    var property_attribute1 = xmlDocs.CreateAttribute("DataType");
                                    property_attribute1.Value = managePropertytype;
                                    var property_attribute2 = xmlDocs.CreateAttribute("DisplayName");
                                    property_attribute2.Value = managePropertyDisplayName;

                                    newProperty.Attributes.Append(property_attribute4);
                                    newProperty.Attributes.Append(property_attribute1);
                                    newProperty.Attributes.Append(property_attribute2);
                                    foreach (XmlNode node in category)
                                    {
                                        if (node.Name == "PropertyDefs")
                                        {
                                            category[0].AppendChild(newProperty);
                                        }
                                    }
                                    for (int j = 0; j < resulttype.Count; j++)
                                    {
                                        var Result_newInnerNode = xmlDocs.CreateNode(XmlNodeType.Element, "PropertyRef", "");
                                        var result_attribute = xmlDocs.CreateAttribute("Name");
                                        result_attribute.Value = managePropertyname;
                                        Result_newInnerNode.Attributes.Append(result_attribute);
                                        resulttype[j].AppendChild(Result_newInnerNode);
                                    }
                                    wpAdavance.Properties = xmlDocs.InnerXml;
                                    advsearchwebPartManager.SaveChanges(wpAdavance);
                                }
                            }
                            newSearchWebSearch.AllowUnsafeUpdates = true;
                            advanceFile.CheckIn("Publish", SPCheckinType.MajorCheckIn);
                            advanceFile.Publish("Publish");
                            _sitePage.Update();
                            newSearchWebSearch.Update();
                            newSearchWebSearch.AllowUnsafeUpdates = false;
                        }

                        //Based on Subject Seperate search Page