Wednesday, 31 May 2017

Gacutil.exe successfully adds assembly, but assembly not viewable in explorer. Why?

 C:\_Dev Projects\VS Projects\bmccormack\CatalogPromotion\CatalogPromotionDll\bin
    \Debug>gacutil /i CatalogPromotionDll.dll
    Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.1
    Copyright (c) Microsoft Corporation.  All rights reserved.

    Assembly successfully added to the cache


That's because you use the .NET 4.0 version of gacutil.exe. 
It stores the assembly in a different GAC, the one in 
c:\windows\microsoft.net\assembly. Where all .NET 4.0 assemblies 
are stored. There is no shell extension handler for that one,
 the folders are visible as-is. You can have a look-see with 
 Windows Explorer, .you'll see the internal structure of the GAC
 folders. You shouldn't have any trouble finding your assembly back,
 the GAC isn't particularly complicated.If the assembly is intended
 to be used by an app that targets an earlier version of .NET then 
 you should use the .NET 2.0 version of gacutil.exe, stored 
 in C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin

Tuesday, 30 May 2017

How to Create Custom SharePoint 2013 List using PowerShell?

Ref : https://www.codeproject.com/articles/808246/how-to-create-custom-sharepoint-list-using-powersh

SharePoint provides an interface called AddFieldAsXml. This basically creates a field based on the specified schema. Nothing fancy. Right?
However, this can be very handy when you want to create your own custom lists in SharePoint programmatically. I will be using PowerShell as an example to demonstrate how you can simply create SharePoint Lists based on plain, simple xml definitions.
To start with, I created an XML template based on which I want to create my custom list using PowerShell.
xml version="1.0" encoding="utf-8"?>
<Template>
 <Field Type="Text" DisplayName="Name" Required="False" 

 MaxLength="255" StaticName="Name" Name="Name" />
 <Field Type="Number" DisplayName="Phone Number" 

 Required="False" MaxLength="255" 

 StaticName="PhoneNumber" Name="PhoneNumber" />
 <Field Type="DateTime" DisplayName="Date of Birth" 

 Required="False" MaxLength="255" 

 StaticName="DateOfBirth" Name="DateOfBirth" />  
 <Field Type="Choice" DisplayName="Annual Salary" 

 Required="False" Format="Dropdown" FillInChoice="FALSE" 

 StaticName="AnnualSalary" Name="AnnualSalary">
            <Default>0 - 10000</Default>
            <CHOICES>
                <CHOICE>0 - 10000</CHOICE>
                <CHOICE>10000 - 50000</CHOICE>
                <CHOICE>50000 - 100000</CHOICE>
                <CHOICE>100000 or more</CHOICE>
            </CHOICES>
       </Field> 
</Template>
In this example, I have used TextNumberDate and Choice as the Field Types. But this could be anything which is supported by SharePoint or even your own content types. Check the documentation on MSDN for Field Element.
The next step is to read this XML file, parse it and use the AddFieldAsXml method to create fields in this list. The PowerShell snippet below does the trick. Straight and simple. Isn’t it?
Add-PSSnapin Microsoft.SharePoint.PowerShell 

function CreateList($siteCollectionUrl, $listName, $templateFile){
 
 $spWeb = Get-SPWeb -Identity $siteCollectionUrl 
 $spTemplate = $spWeb.ListTemplates["Custom List"] 
 $spListCollection = $spWeb.Lists 
 $spListCollection.Add($listName, $listName, $spTemplate) 
 $path = $spWeb.url.trim() 
 $spList = $spWeb.GetList("$path/Lists/$listName")
 $templateXml = [xml](get-content $templateFile)
 foreach ($node in $templateXml.Template.Field) {
 
  $spList.Fields.AddFieldAsXml($node.OuterXml, 
  $true,[Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)
 }
 $spList.Update()
}

$siteCollectionUrl = "http://manas.com"
$listName = "New Custom List"
$templateFile = "template.xml"

CreateList $siteCollectionUrl $listName $templateFile
And here is the result, just by configuration in XML file, you can create lists using PowerShell.

Monday, 8 May 2017

Sharepoint Client-side HTML Table Pagination using JavaScript

Client-side pagination to large Html table that you can specify the number of rows to show per page.

Html Code : 

script src="/**************/New/jquery-1.10.1.min.js">/script>
script src="/*************/Untitled.js">/script>
style>
#table_id{
border:solid 1px #0072C6;
border-collapse: separate;
}
#table_id #tab-head{
background-color:#005C89;
color:#fff;
}
#table_id #tab-head th {
    padding: 5px;
    font-size: 14px;
    font-weight: bold;
}
#table_id #content .loop-quick-links:hover{
background-color:#f5f5f5
}
#table_id #content .loop-quick-links{
/*background:#E1EEF4;*/
font-size:small;
}
#table_id #content .loop-quick-links td {
/*background:#E1EEF4;*/
padding: 5px;    
}
#table_id #content .loop-quick-links #cntrlink{
text-align:center;
}
#table_id #content .loop-quick-links td a {
    background: #8CA2B0;
    padding: 3px;
    color: #fff;
}
#table_id #content .loop-quick-links td a span{
margin:10px;
font-size:14px;
}
.pg-normal {
color: #000000; 
font-size: 15px; 
cursor: pointer; 
background: #D0B389; 
padding: 2px 4px 2px 4px;            
}
.pg-selected {
color: #fff; 
font-size: 15px; 
background: #000000; 
padding: 2px 4px 2px 4px;            
}

/style>
div>
    table id="table_id" class="display" cellspacing="0" width="80%" align="center">  
        thead id="tab-head">  
            tr>  
                th style="display:none">Employee Name/th>  
                th style="width:120px;">Project Name/th>  
                th style="width:120px;">Task Name/th>  
                th style="width:100px;">Created Date/th>  
                th style="width:100px;">Planned Hours/th>  
                th style="width:100px;">Actual Hours/th>
                th style="width:100px;">Notes/th>
th style="display:none;">Billing Status/th>

/tr>             
        /thead> 
        tbody id="content">/tbody> 
        tfoot>        
        /tfoot>  
    /table>   
    div id="pageNavPosition" style="padding-top: 20px" align="center">/div> 
   script>
        var pager = new Pager('table_id', 11);    
  pager.init();
pager.showPageNav('pager', 'pageNavPosition');
pager.showPage(1);
/script>    


JS File Code:

ExecuteOrDelayUntilScriptLoaded(Getdata, "sp.js"); function Getdata() { var Userid = _spPageContextInfo.userId; var siteUrl = _spPageContextInfo.siteAbsoluteUrl+'/***************/TimeSheet/'; //Subsite URL var context = new SP.ClientContext(siteUrl); var web = context.get_web(); var list = web.get_lists().getByTitle('TimeSheetTranscation'); //List Name var myquery = new SP.CamlQuery(); myquery.set_viewXml('View>Query>Where>Eq>FieldRef Name=\'EmpID\'/>Value Type=\'Number\'> '+ Userid +'/Value>/Eq>/Where> OrderBy>FieldRef Name=\'ID\' Ascending=\'False\'/>/OrderBy>/Query>RowLimit>1000000/RowLimit>/View>'); myItems = list.getItems(myquery); context.load(myItems); context.executeQueryAsync(Function.createDelegate(this, this.success_Getdata), Function.createDelegate(this, this.failed_Getdata)); } function success_Getdata() { try{ var ListEnumerator = this.myItems.getEnumerator(); var text = 'tr>th style="display:none">input type="text" id="txtEmployeeId">input type="text" id="txtEmployee">/th>th>select id="ProjectName" onchange="ProjectChange()">/select>/th>' + 'th>select id="TaskName" onchange="TaskChange()">/select>/th>' + 'th>input type="text" id="txtdate" style="width:70px;">/td>' + 'th align="center">select id="PlnHours" style="width:30px;">/select>/th>' + 'th align="center">input type="number" id="txtah" min="0" max="24" style="width:30px;">/th>' + 'th>input type="text" id="txtNotes" style="width:70px; height:30px;">/th>' + 'th style="display:none">select id="BillingStatus">option>Non Billable/option>option>Billable/option>/select>/th>/tr>'; while (ListEnumerator.moveNext()) { var currentItem = ListEnumerator.get_current(); var EmployeeName = currentItem.get_item('EmployeeName'); var ProjectName= currentItem.get_item('ProjectName'); var TaskName= currentItem.get_item('TaskName'); var DateCreated= new Date(currentItem.get_item('DateCreated')); var date=DateCreated.getDate(); var month = DateCreated.getMonth() + 1; var year=DateCreated.getFullYear(); var DateCreated=month+'/'+date+'/'+year; //var PlannedHours= currentItem.get_item('PlannedHours'); var ActualHours= currentItem.get_item('ActualHours'); var BillingStatus= currentItem.get_item('BillingStatus'); var Notes = currentItem.get_item('Notes'); var id=currentItem.get_item('ID'); text += 'tr class="loop-quick-links" id='+ id +'>'; text += ('td style="display:none">' + EmployeeName + '/td>' + 'td id ="PN">' + ProjectName + '/td>' + 'td id="TN">' + TaskName+ '/td>' + 'td id="DC">' + DateCreated+ '/td>' + 'td align="center">' + ActualHours+ '/td>' + 'td>'+ Notes +'/td>' + 'td style="display:none">' + BillingStatus+ '/td>' + 'td>input type="button" id="btn_update" value="Update" onclick="divshow('+ id +');">input type="button" id="btn_delete" value="Delete" onclick="getConfirmation('+ id +');">/td>/tr>'); } fieldNameElement = document.getElementById('content'); fieldNameElement.innerHTML = text; pager.init(); pager.showPageNav('pager', 'pageNavPosition'); pager.showPage(1); } catch(err) { alert(err.message); } } function failed_Getdata(sender, args) { alert("failed. Message:" + args.get_message()); } function Pager(tableName, itemsPerPage) { this.tableName = tableName; this.itemsPerPage = itemsPerPage; this.currentPage = 1; this.pages = 0; this.inited = false; this.showRecords = function(from, to) { var rows = document.getElementById(tableName).rows; for (var i = 1; i rows.length; i++) { if (i from || i > to) rows[i].style.display = 'none'; else rows[i].style.display = ''; } } this.showPage = function(pageNumber) { if (! this.inited) { alert("not inited"); return; } var oldPageAnchor = document.getElementById('pg'+this.currentPage); oldPageAnchor.className = "pg-normal"; this.currentPage = pageNumber; var newPageAnchor = document.getElementById('pg'+this.currentPage); newPageAnchor.className = "pg-selected"; var from = (pageNumber - 1) * itemsPerPage + 1; var to = from + itemsPerPage - 1; this.showRecords(from, to); } this.prev = function() { if (this.currentPage > 1) this.showPage(this.currentPage - 1); else{ alert('There is no Previous Item'); } } this.next = function() { if (this.currentPage this.pages) { this.showPage(this.currentPage + 1); } else{ alert('There is no next Item'); } } this.init = function() { var rows = document.getElementById(tableName).rows; var records = (rows.length - 1); this.pages = Math.ceil(records / itemsPerPage); this.inited = true; } this.showPageNav = function(pagerName, positionId) { if (! this.inited) { alert("not inited"); return; } var element = document.getElementById(positionId); var pagerHtml = 'span onclick="' + pagerName + '.prev();" class="pg-normal"> Prev /span> '; for (var page = 1; page = this.pages; page++) pagerHtml += 'span id="pg' + page + '" class="pg-normal" onclick="' + pagerName + '.showPage(' + page + ');">' + page + '/span> '; pagerHtml += 'span onclick="'+pagerName+'.next();" class="pg-normal"> Next /span>'; element.innerHTML = pagerHtml; } }

Tuesday, 2 May 2017

Get mobile no using Client object model

// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
var userProfileProperties;
SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function() {
   // Make sure PeopleManager is available
   SP.SOD.executeFunc('userprofile', 'SP.UserProfiles.PeopleManager', function() {
debugger;
       // get the target users domain name and account name.
    var targetUser = "i:0#.f|membership|inspiredata@gbtmarketingreview.onmicrosoft.com";

    // Get the current client context.
    var clientContext = new SP.ClientContext.get_current();
    //Get PeopleManager Instance
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

    // Get the properties to retrieve
    var profilePropertyNames = ["AccountName", "FirstName","LastName","Assistant", "Office","Personal site","WorkPhone", "Mobilephone","CellPhone","Fax","Department" ];
    var userProfilePropertiesForUser = new SP.UserProfiles.UserProfilePropertiesForUser(
    clientContext,
    targetUser,
    profilePropertyNames);

    // Get user profile properties for the target user
    userProfileProperties =peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser);
    // Load the UserProfilePropertiesForUser object.
    clientContext.load(userProfilePropertiesForUser)
    //Execute the Query
    clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
   });

});




// This function runs if the executeQueryAsync call succeeds.

function onRequestSuccess() {
debugger;
    var messageText = "\" AccountName \" property is "
    + userProfileProperties[0];
    messageText += "
\" FirstName \" property is "
    + userProfileProperties[1];
    messageText += "
\" LastName \" property is "
    + userProfileProperties[2];
    messageText += "
\" Assistant \" property is "
    + userProfileProperties[3];
    messageText += "
\" Office \" property is "
    + userProfileProperties[4];
    messageText += "
\" Personal site \" property is "
    + userProfileProperties[5];
    messageText += "
\" HomePhone \" property is "
    + userProfileProperties[6];
    messageText += "
\" Mobilephone \" property is "
    + userProfileProperties[7];
    messageText += "
\" CellPhone \" property is "
    + userProfileProperties[8];
    messageText += "
\" Fax \" property is "
    + userProfileProperties[9];
    messageText += "
\" Department \" property is "
    + userProfileProperties[10];
 alert("WorkPhone"+userProfileProperties[6])
    $get("Display").innerHTML = messageText;
}

// This function runs if the executeQueryAsync call fails.

function onRequestFail(sender, args) {
debugger;
    $get("Display").innerHTML = "Error: " + args.get_message();
}

Tag A href Events to Click and Double Click

You might want a link to have a special action when double-clicked which prevents the default action of the link (go to another page). So:
Double-click: does something special, does not do normal click event at all
Click: works as normal
You'll need to have a very slight delay on firing off the normal click action, which you cancel when the double click event happens.


script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"

$(document).ready(function(){
function doClickAction() {
  alert("Single Click");
}
function doDoubleClickAction() {
  alert("Double Click");
}

var timer = 0;
var delay = 200;
var prevent = false;

$("#target")
  .on("click", function() {
    timer = setTimeout(function() {
      if (!prevent) {
        doClickAction();
      }
      prevent = false;
    }, delay);
  })
  .on("dblclick", function() {
    clearTimeout(timer);
    prevent = true;
    doDoubleClickAction();
  });
});