Monday, July 2, 2018

SharePoint App model parameter from SharePoint Site to app page iframe


JS code has to add in Script Editor webpart


<script src="/SiteAssets/Script/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script>
var arrAppIFrames = document.getElementsByTagName("iframe");
for(i = 0; i< arrAppIFrames.length; i++)
{

    var currentiFrame=arrAppIFrames[i];
    var layoutValue="KeyIDValue";
    if(currentiFrame.src.indexOf(layoutValue) != -1)
    {         

        var queryStringValue = GetUrlKeyValue('KeyID', false, window.location.href);


             if(queryStringValue != null)
        {
                      currentiFrame.src=currentiFrame.src.replace(layoutValue,queryStringValue);
        }
    }
  
}


</script>
<style type="text/css">
   .ms-webpartPage-root {
                border-spacing: 0px !important;
    }
.ms-WPBody iframe {
width:100% !important;
height:3700px !important;
}
</style>

Element.xml:

<?xml version="1.0" encoding="utf-8"?>
  <ClientWebPart Name="ApproveKeyRequest" Title="ApproveKeyRequest Title" Description="Approve the Key Requests">

    <!-- Content element identifies the location of the page that will render inside the client web part
         Properties are referenced on the query string using the pattern _propertyName_
         Example: Src="~appWebUrl/Pages/ClientWebPart1.aspx?Property1=_property1_" -->
    <Content Type="html" Src="~remoteAppUrl/Pages/ApprovalForm.aspx?{StandardTokens}&amp;KeyID=_KeyID_" />
    <!-- Define properties in the Properties element.
         Remember to put Property Name on the Src attribute of the Content element above. -->
    <Properties>

      <Property Name="KeyID" Type="string"
                 DefaultValue="KeyIDValue"
                 RequiresDesignerPermission="true"
                 WebCategory="KeyID Parameter"
                 WebDisplayName="KeyID">
      </Property>


    </Properties>

  </ClientWebPart>
</Elements>
================== updated after practice=============
After R&D. replace the web part=>properties replace in url with partent url value

<script>
alert($('iframe')[3].src.replace('pkeyValue1','10'));
$('iframe')[3].src=$('iframe')[3].src.replace('pkeyValue1','10');

</script>
final JS
        //function to get a parameter value by a specific key
        function getQueryStringParameter(prKey) {
            var params = document.URL.split('?')[1].split('&');
            var strParams = '';
            for (var i = 0; i < params.length; i = i + 1) {
                var singleParam = params[i].split('=');
                if (singleParam[0] == prKey)
                    return singleParam[1];
            }
        }
        var iFrm = document.getElementsByTagName("iframe");
        for (i = 0; i < iFrm.length; i++) {
            $(iFrm)[i].src = $(iFrm)[i].src.replace('pkeyValue1', getQueryStringParameter('pkey'));
        }

Saturday, June 23, 2018

Angular JS call for webmethod in C# AsP.net with loading animation while call

Interacting With RESTful APIs Using $http in AngularJS


Angular JS call for webmethod in C# AsP.net $http

var app = angular.module('partHeadM', [])
app.controller('partHeadC', function ($scope, $http, $window) {
    $scope.searchclick = function (mid) {
        $scope.LAanimationshow();
        var post = $http({
            method: "POST",
            url: "PartViewr.aspx/GetPartHeader",
            dataType: 'json',
            data: JSON.stringify({ 'mid': mid }),
            headers: { "Content-Type": "application/json" }
        }).then(function (respons, status) {
            $scope.LAnimationhide();
            console.log(respons.data.d);
            var da1 = JSON.parse(respons.data.d);
            if (da1.length > 0)
                $scope.cmnt = da1[0];
            else
            { $scope.cmnt = ''; alert('Material not found.'); }
        }, function (respons, status) {
            $scope.LAnimationhide();
            $window.alert(respons.Message);
        });        
    }
    $scope.LAanimationshow = function () {
        document.getElementById('loadinganimation').style.display = 'block';
    }

    $scope.LAnimationhide = function () {
        document.getElementById('loadinganimation').style.display = 'none';
    }
});

<div class="col-xs-12 col-sm-9" ng-app="partHeadM" ng-controller="partHeadC">
                  <div class="row">
                      <div class="col-sm-12">
                          <div class="section_title">  Viewer</div>
                      </div>
                  </div>


                  <div class="row" style="padding-left: 5px; padding-right: 5px;">
                      <div class="col-sm-1 form-label">search Mat</div>
                      <div class="col-sm-3 form-input" style="line-height: 14px;">
                          <asp:TextBox ID="txtMaterial" runat="server" CssClass="form-control" MaxLength="20" ToolTip="Enter material number" ng-model="mat1"></asp:TextBox>
                      </div>
                      <div class="col-sm-1 form-button">
                          <asp:Button ID="btnSearch" runat="server" Text="Search" OnClientClick="return false;" ToolTip="Click to search" ng-click="searchclick(mat1)" />
                      </div>
                  </div>

Tuesday, May 29, 2018

SharePoint-tableau integration, IE11 compatible, SharePoint Master page to IE 11



  • SharePoint-tableau integration, IE11 compatible, SharePoint Master page to IE 11
  • Fix “AddEventListener” error in IE11 without access to Master Pages
  • IE11 ISSUE WITH SHAREPOINT MASTER PAGE
  • IE11 - Critical Error: Object doesn't support property or method

insert below green colored code in your master page.

<meta http-equiv="X-UA-Compatible" content="IE=10,IE=11" />

  <script type="text/javascript">//<![CDATA[
        var g_pageLoadAnimationParams = { elementSlideIn : "sideNavBox", elementSlideInPhase2 : "contentBox" };
     
     
     
     
        if (typeof browseris !== 'undefined') {
browseris.ie = false;
}
        
     
        //]]>
        </script>

Monday, May 7, 2018

GET THE MANAGER DETAILS AND CURRENT LOGIN USER DETAILS FROM ACTIVE DIRECTORY


GET THE MANAGER DETAILS AND CURRENT LOGIN USER DETAILS FROM ACTIVE DIRECTORY

outlook properties


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;

public partial class MgrFromAD : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ADAttributes ad = new ADAttributes();
            ad = GetEmployeeAttributes("Ashwini Sharma", AdPrpoertyParameters.displayName);
        }
    }

    public ADAttributes GetEmployeeAttributes(string Input, AdPrpoertyParameters PropertyParameter)
    {
        ADAttributes attributes = null;
        try
        {
            string strLDAPPath = "LDAP://DC=at,DC=com"; // configurable

            attributes = DirectoryEntryforAttributes(strLDAPPath, PropertyParameter.ToString(), Input, "AT");
            //if (attributes == null)
            //{
            //    attributes = DirectoryEntryforAttributes(strLDAPPath, PropertyParameter.ToString(), Input, CONST_TEL);
            //}


            ADAttributes mgrAttributes = null;
            mgrAttributes = DirectoryEntryforAttributes(strLDAPPath, AdPrpoertyParameters.sAMAccountName.ToString(), attributes.managerSamAcnt, "AT");
            //if (mgrAttributes == null)
            //{
            //    mgrAttributes = DirectoryEntryforAttributes(strLDAPPath, AdPrpoertyParameters.sAMAccountName.ToString(), attributes.managerSamAcnt, CONST_TEL);
            //}
            if (mgrAttributes != null)
            {
                attributes.ManagerEmail = mgrAttributes.mail;
                attributes.ManagerLoginName = mgrAttributes.sAMAccountName;
                attributes.ManagerDisplayName = mgrAttributes.displayName;
                attributes.ManagerDomain = mgrAttributes.domain;
                attributes.ManagerEmployeeID = mgrAttributes.employeeId;
                attributes.ManagerPhoneNumber = mgrAttributes.telephoneNumber;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return attributes;
    }

    public ADAttributes DirectoryEntryforAttributes(string PropertyKey, string Filtervalue, string Input, string DomainName)
    {
        SearchResult sresult;
        string query = string.Empty;
        string ldappath = "";
        DirectoryEntry entry_Amat = new DirectoryEntry(ldappath);
        DirectorySearcher userSearch_Amat = new DirectorySearcher(entry_Amat);
        query = string.Format("(&(objectClass=user)(" + Filtervalue + "={0}))", Input);
        userSearch_Amat.Filter = query;
        //Remove this code if not required
        sresult = userSearch_Amat.FindOne();
        if (sresult == null)
        {
            query = string.Format("(&(objectClass=contact)(" + Filtervalue + "={0}))", Input);
            userSearch_Amat.Filter = query;
            //samSearcher.PropertiesToLoad.Add(Filtervalue);
            sresult = userSearch_Amat.FindOne();

        }
        ADAttributes objAd = ADAttributes.GetDirectoryAttributes(sresult, Filtervalue, Input, DomainName);
        return objAd;
    }

}

public class ADAttributes
{

    public string employeeId { get; set; }
    public string employeeType { get; set; }
    public string mail { get; set; }
    public string sAMAccountName { get; set; }
    public string displayName { get; set; }
    public string givenName { get; set; }
    public string manager { get; set; }
    public string memberOf { get; set; }
    public string department { get; set; }
    public string departmentNumber { get; set; }
    public string division { get; set; }
    public string userAccountControl { get; set; }
    public string telephoneNumber { get; set; }
    public string postOfficeBox { get; set; }
    public string PhysicalDeliveryOfficeName { get; set; }
    public string objectClass { get; set; }
    public string uId { get; set; }
    public string domain { get; set; }
    public string Location { get; set; }
    public string Company { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    //    public string ManagerEmailAddress { get; set; }
    public string managerSamAcnt { get; set; }
    public string ManagerEmail { get; set; }
    public string ManagerLoginName { get; set; }
    public string ManagerDisplayName { get; set; }
    public string ManagerDomain { get; set; }
    public string co { get; set; }
    public string ManagerEmployeeID { get; set; }
    public string ManagerPhoneNumber { get; set; }
    public static ADAttributes GetDirectoryAttributes(SearchResult sresult, string Filtervalue, string Input, string DomainName)
    {


        if (sresult != null)
        {
            ADAttributes objAd = new ADAttributes
            {
                employeeId = sresult.Properties["employeeid"].Count > 0 ? sresult.Properties["employeeid"][0].ToString() : string.Empty,
                employeeType = sresult.Properties["employeeType"].Count > 0 ? sresult.Properties["employeeType"][0].ToString() : string.Empty,
                sAMAccountName = sresult.Properties["sAMAccountName"].Count > 0 ? sresult.Properties["sAMAccountName"][0].ToString() : string.Empty,
                department = sresult.Properties["department"].Count > 0 ? sresult.Properties["department"][0].ToString() : string.Empty,
                departmentNumber = sresult.Properties["departmentNumber"].Count > 0 ? sresult.Properties["departmentNumber"][0].ToString() : string.Empty,
                division = sresult.Properties["division"].Count > 0 ? sresult.Properties["division"][0].ToString() : string.Empty,
                manager = sresult.Properties["manager"].Count > 0 ? sresult.Properties["manager"][0].ToString() : string.Empty,
                managerSamAcnt = (sresult.Properties.Contains("manager") == true) ? Convert.ToString(sresult.Properties["manager"][0]).Split(',')[0].Split('=')[1] : string.Empty, // Splitting manger name
                //manager = (sresult.Properties.Contains("manager") == true) ? Convert.ToString(sresult.Properties["manager"][0]).Split(',')[0].Split('=')[1] : string.Empty, // Splitting manger name
                displayName = sresult.Properties["displayName"].Count > 0 ? sresult.Properties["displayName"][0].ToString() : string.Empty,
                PhysicalDeliveryOfficeName = sresult.Properties["physicalDeliveryOfficeName"].Count > 0 ? sresult.Properties["physicalDeliveryOfficeName"][0].ToString() : string.Empty,
                mail = sresult.Properties["mail"].Count > 0 ? sresult.Properties["mail"][0].ToString() : string.Empty,
                memberOf = sresult.Properties["memberOf"].Count > 0 ? sresult.Properties["memberOf"][0].ToString() : string.Empty,
                //memberOf = (sresult.Properties["memberOf"].Count > 0) ? Convert.ToString(sresult.Properties["memberOf"][0]).Split(',')[0].Split('=')[1] : string.Empty, //Splitting manger name
                userAccountControl = sresult.Properties["userAccountControl"].Count > 0 ? sresult.Properties["userAccountControl"][0].ToString() : string.Empty,
                givenName = sresult.Properties["givenName"].Count > 0 ? sresult.Properties["givenName"][0].ToString() : string.Empty,
                objectClass = sresult.Properties["objectClass"].Count > 0 ? sresult.Properties["objectClass"][0].ToString() : string.Empty,
                postOfficeBox = sresult.Properties["postOfficeBox"].Count > 0 ? sresult.Properties["postOfficeBox"][0].ToString() : string.Empty,
                telephoneNumber = sresult.Properties["telephoneNumber"].Count > 0 ? sresult.Properties["telephoneNumber"][0].ToString() : string.Empty,
                uId = sresult.Properties["uId"].Count > 0 ? sresult.Properties["uId"][0].ToString() : string.Empty,
                Location = sresult.Properties["L"].Count > 0 ? sresult.Properties["L"][0].ToString() : string.Empty,
                Company = sresult.Properties["Company"].Count > 0 ? sresult.Properties["Company"][0].ToString() : string.Empty,
                FirstName = sresult.Properties["givenName"].Count > 0 ? sresult.Properties["givenName"][0].ToString() : string.Empty,
                LastName = sresult.Properties["sn"].Count > 0 ? sresult.Properties["sn"][0].ToString() : string.Empty,
                //   ManagerEmailAddress = sresult.Properties["ManagerEmailAddress"].Count > 0 ? sresult.Properties["ManagerEmailAddress"][0].ToString() : string.Empty,
                co = sresult.Properties["co"].Count > 0 ? sresult.Properties["co"][0].ToString() : string.Empty,
                domain = DomainName
            };
            return objAd;
        }
        else
        {
            return null;
        }
    }
}
/// <summary>
    /// Enum AD properties
    /// </summary>
    public enum AdPrpoertyParameters
    {
        employeeid,
        sAMAccountName,
        displayName,
        mail,
CN // for current login user identity name from System.Web.HttpContext.Current.Request.LogonUserIdentity.Name.Replace("AMT\\", "")
    }