Tuesday, March 11, 2014

How to get the site collection URL in the masterpage of a SharePoint 2013 site or subsites using Javascript in masterpage

There might be times when you really want to get the URL of the site collection within the master page of sharepoint 2013 sites.

well you can achieve it by using the below javascript line .

Inorder to add script in masterpage , we have to follow the conventional and well known method of the script tag inside the body of HTML.

now within the script tag just copy paste the following function

function getSiteCollectionsURL()

{

var sitecollectionURL = window.location.protocol + "//" + window.location.host +_spPageContextInfo.siteServerRelativeUrl

return sitecollectionURL;

}

the function can be called from anywhere inside the masterpage according to your needs.. it will return the site collection url no matter where you are , ie , whether you are in the subsite or the site collection or the nested subsite.

Thursday, March 6, 2014

Read a list column value using SP services in SharePoint

How can i read  a column value value of a share point list using Jquery and SP services

This can be achieved by the following java script function .

Make sure in your JS page you have refered the jquery and spservices link
//read the tiltle field value of ABC list
function ReadColumnValue()
{

var myvalue=null;
var strViewfields = "<ViewFields><FieldRef Name='Title'/></ViewFields>";
$().SPServices({
webURL: strSiteURL,
            operation: "GetListItems",
            async: false,
            listName: "ABC",

            completefunc: function (xData, Status) {
                $(xData.responseXML).SPFilterNode("z:row").each(function () {
               
if($(this).attr("ows_title")!= undefined)
{

       myvalue=$(this).attr("ows_title");


}
                });
            }

        });



the variable myvalue will containt eh list column value of the tilte field of the AB list




How to make sure if a particular SharePoint Group Exists or Not?

Inorder to know if a particular group exists in sharepoint group collection , just use the following function..

 private bool GroupExists(SPGroupCollection objgroups, string strName)
        {
            const string NAME = "Name";
            bool isGroupExists = false;
            if (string.IsNullOrEmpty(strName) ||

                (strName.Length > 255) ||

                (objgroups == null) ||

                (objgroups.Count == 0))
            {

                isGroupExists = false;
            }

            else
            {
                XDocument doc = XDocument.Parse(objgroups.Xml);
                isGroupExists = doc.Descendants().Where(g => g.Attribute(NAME) != null).Where(g => g.Attribute(NAME).Value.Equals(strName, StringComparison.InvariantCultureIgnoreCase)).Count() > 0;
            }
            return isGroupExists;

        }


The function would return true if the group exists in group collection of sharepoint..


You just have to call the function as shown below :



                SPGroupCollection objSiteGroups = YOURWEBOBJECT.SiteGroups;
                if (GroupExists(objSiteGroups, "YOUR GROUP NAME"))
                {
                   // Do all that you want with the group coz the group does exists
                }
Happy sharepointing :)


Rename a Web Application in Sharepoint : A solution using powershell

Here is a small script that will enable you all to change a SharePoint Web Application name . We can use the following SharePoint Pow...