Search This Blog

Thursday, November 15, 2018

How to reference css and script in SharePoint Master Page

CSS Reference

<!--SPM:<SharePoint:CssRegistration Name="https://Yugatechnolgy.sharepoint.com/sites/Teamsite/SiteAssets/customstyle.css" runat="server" after="corev15.css"/>-->


Javascript Reference

<!--SPM:<SharePoint:ScriptLink ID="ScriptLink10" language="text/javascript" name="sites/Teamsite/SiteAssets/jquery-2.2.4.min.js" runat="server" />-->


Thursday, August 2, 2018

How to add Custom Action Menu In SharePoint ListItem using Jquery

 The below code is used to add Custom Action Menu in SharePoint ListItem using JSOM.












Add a CEWP/Script Editor webpart in the "/sites/TeamSite/List/EmployeeDetails/AllItems.aspx" Page and paste the below code.

JSOM Code:

<script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', AddCustomUserActionToListItem);
    });

function AddCustomUserActionToListItem() {
    var clientContext = new SP.ClientContext();
    var oWeb = clientContext.get_web();
    var oList = oWeb.get_lists().getByTitle('EmployeeDetails');
    var userCustomActionColl = oList.get_userCustomActions();
    clientContext.load(oList, 'UserCustomActions', 'Title');
    clientContext.executeQueryAsync(function() {
        var customActionEnumerator = userCustomActionColl.getEnumerator();
        var foundAction = 0;
        while (customActionEnumerator.moveNext()) {
            var oUserCustomAction = customActionEnumerator.get_current();
            if (oUserCustomAction.get_title() == 'Custom Edit Page') {
                foundAction = 1;
                break;
            }
        }
        if (foundAction == 0) {
            var oUserCustomAction = userCustomActionColl.add();
            oUserCustomAction.set_location('EditControlBlock');
            oUserCustomAction.set_sequence(100);
            oUserCustomAction.set_title("Custom Edit Page");
            oUserCustomAction.set_url("/sites/TeamSite/Lists/Customer/dispform.aspx?ID={1}&Source=/sites/TeamSite/Lists/EmployeeDetails/AllItems.aspx");
            oUserCustomAction.update();
            clientContext.load(userCustomActionColl);
            clientContext.executeQueryAsync();
        }
    }, function(sender, args) {
        console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    });
}
</script> 

Wednesday, July 25, 2018

How To Migrate SharePoint Search Properties From One Tenant To Another Using CSOM

Create a Search Property:

First, we need to know how to create a search property before migrating it.

  • We should log into the SharePoint Admin Center.
  • Click Search from the left menu.
SharePoint

  • Select “Manage Search Schema”
           
SharePoint

  • Select “New Managed Property”.

     SharePoint

  • Then give the Property Name, Description, Type of the property and select the Searchable, Retrievable checkbox.
  • In the mapping to crawled property section, select “Add a Mapping” to choose the property or column 

  Migrating Search Crawl Property:

     After creating the property, create a windows application and add    “Microsoft.SharePointOnline.CSOM” Nuget package to the solution. We have to perform Export and Import operation to perform the migration. For exporting the search managed property use the below code snippet. 


private static string exportSearchSettings(ClientContext clientContext) {  
    SearchConfigurationPortability searchConfiguration = null;  
    SearchObjectOwner searchObjectOwner = null;  
    ClientResult < string > configResults = null;  
    string stringresult = string.Empty;  
    try {  
        searchConfiguration = new SearchConfigurationPortability(clientContext);  
        searchObjectOwner = new SearchObjectOwner(clientContext, SearchObjectLevel.SPSiteSubscription);  
        configResults = searchConfiguration.ExportSearchConfiguration(searchObjectOwner);  
        clientContext.ExecuteQuery();  
        if (configResults.Value != null) stringresult = configResults.Value;  
    } catch (Exception) {  
        throw;  
    }  
    return stringresult;  
}  

From the above code, we will be getting an xml string which can be imported to another site. After the above code execution, make sure that you’re storing the content somewhere to reuse it. I am saving the document as a file inside the application as “searchConfiguration.xml”
After storing it, use the below code to migrate the configurations to a new tenant.

private static void importSearchSettings(ClientContext clientContext) {  
    SearchConfigurationPortability searchConfiguration = null;  
    SearchObjectOwner searchObjectOwner = null;  
    string location = string.Empty, directory = string.Empty;  
    try {  
        location = Assembly.GetExecutingAssembly().Location;  
        directory = Path.GetDirectoryName(location);  
        searchConfigurationString = System.IO.File.ReadAllText(directory + "/searchConfiguration.xml");  
        searchConfiguration = new SearchConfigurationPortability(clientContext);  
        searchObjectOwner = new SearchObjectOwner(clientContext, SearchObjectLevel.SPSiteSubscription);  
        searchConfiguration.ImportSearchConfiguration(searchObjectOwner, searchConfigurationString);  
        clientContext.ExecuteQuery();  
    } catch (Exception) {  
        throw;  
    }  

Source:

Wednesday, May 9, 2018

How to retrieve items using SPSiteDataQuery in SharePoint 2013

In this post we will see how to retrieve the items from multiple lists using SPSiteDataQuery in SharePoint 2013.

SPSiteDataQuery:
                It is used to retrieve data from list or from all list in the site collection (i.e. used for cross-site and cross-list queries).

SPSiteDataQuery.Webs:
                This property will be used to specify from where the data will be retrieved.

SPWeb.GetSiteData:
                It is used to retrieve the data.

Sample Code to retreive the Items from the Tasks list

string siteUrl = SPContext.Current.Web.Url;
string username=string.Empty;

using (SPSite site = new SPSite(siteUrl ))
{
   using (SPWeb web = site.RootWeb)
   {
      SPUser user = web.CurrentUser;
      username = user.LoginName;
      SPSiteDataQuery dataQuery = new SPSiteDataQuery();
    //if it is set to SiteCollection, the query considers all Web sites that are in the       same site collection as the current Web site. 
     dataQuery.Webs = "<Webs Scope=\"SiteCollection\">";
//if it set to Recursive the query considers only the current Web site and all       subsites of the current Web site. 
   //dataQuery.Webs = "<Webs Scope=\"Recursive\">";
   //107 Maps to the tasks list
     dataQuery.Lists = "<Lists ServerTemplate=\"107\" />";
     dataQuery.ViewFields = "<FieldRef Name=\"Title\" />" + "<FieldRef           Name=\"AssignedTo\" />" + "<FieldRef Name=\"DueDate\" />";
     string spQuery = "<Where><Eq><FieldRef Name=\"AssignedTo\"/><Value   Type='User'>" + username + "</Value></Eq></Where>";
     dataQuery.Query = spQuery;
     DataTable dt = web.GetSiteData(dataQuery);
     DataView dv = new DataView(dt);
     gvResult.DataSource = dv;
     gvResult.DataBind();
              
    }

}

Tuesday, March 20, 2018

Some of the media queries for all devices

I have mentioned some of the media queries below

/* Smartphones (portrait and landscape) ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}

/* Smartphones (landscape) ----------- */
@media only screen and (min-width : 321px) {
/* Styles */
}

/* Smartphones (portrait) ----------- */
@media only screen and (max-width : 320px) {
/* Styles */
}

/* iPads (portrait and landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
/* Styles */
}

/* iPads (landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
/* Styles */
}

/* iPads (portrait) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
/* Styles */
}
/**********
iPad 3
**********/
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}

@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
/* Desktops and laptops ----------- */
@media only screen  and (min-width : 1224px) {
/* Styles */
}

/* Large screens ----------- */
@media only screen  and (min-width : 1824px) {
/* Styles */
}

/* iPhone 4 ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}

@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}

/* iPhone 5 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

@media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* iPhone 6 ----------- */
@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* iPhone 6+ ----------- */
@media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

@media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* Samsung Galaxy S3 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}

/* Samsung Galaxy S4 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}

@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}

/* Samsung Galaxy S5 ----------- */
@media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}

@media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}

How to merge more dll's into single dll (ILMerge tool)

We can merge multiple dll's into a single dll using the tool ILMerge.

Prerequisites:
                  Have to install this ILMerge before using the below  ILMerge-GUI tool.

ILMerge Link
https://www.microsoft.com/en-in/download/details.aspx?id=17630

You can download ILMerge-GUI tool in the below link

ILMerge-GUI Link
http://www.softpedia.com/get/Programming/Other-Programming-Files/ILMerge-GUI.shtml

How to use?
                   Add all the assemblies which we want to merge and select the primary assembly which we want to merge with other assemblies and select the Output path of the assembly in Output assembly and click merge after few minutes you will get a message box with message "Assemblies Merged"