Monday, July 22, 2019

SharePoint Online Send mail with attachment alternative with Graph api

Graph api send mail with attachment from SharePoint Online:


Alternative:

This Graph api has 4MB total size limitation over which you can go for ShareLink option using [/_api/web/Lists/getByTitle('Documents')/GetItemById('1')/ShareLink] rest api with minimum 'Members' permission level.



Preq: 



Need to Register App in Graph and give it 'Admin Consent'.



Graph api Encoded Code:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">  

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  





<body>  

<script type="text/javascript">  

    $(document).ready(function() {  

        requestToken();  

    });  

  

    var token;  

  

    function requestToken() {  

  

        $.ajax({  

            "async": true,  

            "crossDomain": true,  

            "url": "https://cors-anywhere.herokuapp.com/https://login.microsoftonline.com/XXX.onmicrosoft.com/oauth2/v2.0/token",

            "method": "POST",  

            "headers": {  

                "content-type": "application/x-www-form-urlencoded"  

            },  

            "data": {  

             "grant_type": "client_credentials",

            "client_id ": "XXX",

            "client_secret": "XXX", 

            "scope ": "https://graph.microsoft.com/.default"  

            },  

            success: function(response) {  

                

                token = response.access_token;  

              },  

            error: function(error) {  

            console.log(JSON.stringify(error));  

           }  

        })  

    } 



function sendEmail() {  

  //Variable to get values from input elements

    var to = $('#email').val();  

    var sub = $('#txtsubject').val();  

    var msg = $('#txtmessage').val();  

  

    $.ajax({  

        "async": true,  

        "crossDomain": true,  

        "url": "https://graph.microsoft.com/v1.0/users/XXX@XXX.onmicrosoft.com/sendMail",  

        "method": "POST",  

        "headers": {  

            "authorization":"Bearer " + token,     

            "content-type": "application/json"  

        },  

        "processData": false,  

        "data": JSON.stringify({                    

            "message": {  

                "subject": sub,  

                "body": {  

                    "contentType": "Text",    

                    "content": msg  

                },  

                "toRecipients": [{  

                    "emailAddress": {  

                        "address": to  

                    }  

                }]  

            }  

        }),  

        success: function(response) {  

            alert("email sent successfully to " + to + "");  

  

        },  

        error: function(error) { 

console.log(JSON.stringify(error));

            alert(JSON.stringify(error));  

        }  

    })  

}  

</script>  

<div class="container">  

<div class="form-group">  

    <label for="email">To:</label>  

    <input type="email" class="form-control" id="email" required>  

  </div>  

  <div class="form-group">  

    <label for="txtsubject">Subject:</label>  

    <input type="text" class="form-control" id="txtsubject" required>  

  </div>  

   <div class="form-group">  

    <label for="txtmessage">Message:</label>  

    <textarea class="form-control" id="txtmessage" rows="7" required></textarea>  

  </div>  

  <button type="submit" onclick="sendEmail();" class="btn btn-default">Send</button>  

  </div>     

</body>  





ShareLink Encoded Code:





<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

<script type="text/javascript">

$(document).ready(function(){

    getShareLink();

});

function getShareLink(){

    var formDigestURL ="https://XXX/_api/contextinfo";

        return $.ajax({

            url: formDigestURL,

            type: "POST",

            datatype:"json",

            headers: {

                "accept": "application/json;odata=verbose",

            },

            success:function(formDigestData){

                 var dataURL="https://XXX/_api/web/Lists/getByTitle('Documents')/GetItemById('1')/ShareLink";

                $.ajax({

                    url: dataURL,

                    type: "POST",

                    headers: {

                        "accept": "application/json;odata=verbose",

                        "X-RequestDigest": formDigestData.d.GetContextWebInformation.FormDigestValue,  

                    },

                    contentType: "application/json; charset=utf-8",

                    dataType: "json",

                    data:JSON.stringify({

                        "request":{

                            "createLink":true,

                            "settings":{

                                "allowAnonymousAccess":false,

                                "linkKind":2,

                                "expiration":null,

                                "restrictShareMembership":false,

                                "updatePassword":false,

                                "password":""

                            }

                        }

                    }),

                    success:function(data){

                        alert("Sucess");

                        console.log(data.d.ShareLink.sharingLinkInfo.Url);

                        $('Div#showLinks').html(data.d.ShareLink.sharingLinkInfo.Url);

                    },

                    error: function (error) {

                        alert("Error");

                        console.log(JSON.stringify(error));

                    }

                });

            },

            error: function (error) {

                $("#error").append(JSON.stringify(error));

            }

        });

}

</script>

<div id="showLinks"></div>

Sunday, October 21, 2018

SharePoint Designer - SharePoint workflow 2013 - Server-side activities have been updated -fix




Resolution Steps:
 
Perquisites:
SharePoint Designer 2013 is installed:
 
Step 1:
Service Pack 1 for Microsoft SharePoint Designer 2013 (KB2817441) 64-Bit Edition
 
Step 2:
2016 Update for Microsoft SharePoint Designer 2013 (KB3114721) 64-Bit Edition

Thursday, July 20, 2017

Remove 127.0.0.1 8080 proxy setting malware virus - Confirmed Fix

Got this virus and tried tons of approaches and softwares, finally the below fix worked for me.

Download  and run the ''malwarebytes'' software. As you will be fixing this issue in a single run the provided free trial version is enough. It took me around a hour to run the scan and quarantine.After which a reboot resolved by issue. 
https://www.malwarebytes.com/


The bug did not affect the Firefox browser, I went to the browser option Advanced-Network-Connection settings page of the firefox browser and set checked the ''No Proxy'' checkbox and saved after which the virus did not affect by firefox browser. Using this I downloaded the malwarebytes software.


I found this fix from courtesy of below youtube link:

Tuesday, November 8, 2016

Office 365 - SharePoint Online Developer References

Mini Calendar:
Override Style of existing calendar WP
http://www.bornsolutions.com/mini-calendar-webpart-in-sharepoint-online/

Multi Language in Custom components:
Javascript resource files
MMS-TermSet
http://www.vrdmn.com/2015/11/custom-multilingual-text-using.html

Image Slider:
JSSlide.js
http://en.share-gate.com/blog/image-slider-with-sharepoint-2013-search-results

PNP Samples:
https://github.com/OfficeDev/PnP/tree/master/Samples

ListView to Accordian
JSLink Concept
https://code.msdn.microsoft.com/office/Client-side-rendering-code-ccdb2a0e
https://blog.vgrem.com/2013/04/14/customize-the-rendering-of-a-list-view-in-sharepoint-2013-displaying-list-items-in-accordion/
JQuery Accordian,JSOM
http://aaclage.blogspot.co.uk/2013/08/example-how-to-use-accordion-jquery.html

Power BI External user Sharing:
https://powerbi.microsoft.com/en-us/blog/power-bi-february-service-update/#externalSharing

App Deployment:
https://support.office.com/en-gb/article/Use-the-App-Catalog-to-make-custom-business-apps-available-for-your-SharePoint-Online-environment-0b6ab336-8b83-423f-a06b-bcc52861cba0?ui=en-US&rs=en-GB&ad=GB

CRM online to SharePoint integration
http://dynamicscrmpros.com/benefits-integrating-sharepoint-microsoft-dynamics-crm/

Flow - CRM online to SharePoint integration
http://dynamicscrmcoe.com/dynamics-crm-online-and-sharepoint-online-codeless-integration/

SharePoint Online Bing Map:
https://alberthoitingh.wordpress.com/2014/04/04/connect-bing-maps-to-sharepoint-online/

SPO 2017 SkillSet:
https://dev.office.com/sharepoint/docs/spfx/tools-and-libraries
http://www.slideshare.net/kushanlahiru/sharepoint-framework-the-future-of-sharepoint-office-365-developer-ecosystem-64107055
https://beyond-sharepoint.github.io/

Angular VS React VS Ember:
https://smashingboxes.com/blog/choosing-a-front-end-framework-angular-ember-react/

SPO External User Signup Options:
http://sharepointmaven.com/setup-external-users-sharepoint/

SPO Folder metadata:
http://www.nothingbutsharepoint.com/2011/08/24/automatic-tagging-based-from-a-folder-how-to-get-your-users-to-eat-their-vegetables-without-them-knowing-it-aspx/
http://techtrainingnotes.blogspot.co.uk/2007/08/sharepoint-how-to-create-links-from.html

Azure Storage Costs:
http://www.aidanfinn.com/?p=19076
https://docs.microsoft.com/en-us/azure/storage/storage-introduction

JSLink:
http://www.martinhatch.com/2013/08/jslink-and-display-templates-part-1.html

Custom Search API Query in Display template
https://www.eliostruyf.com/creatingresult-block-shows-office-graph-suggestionspart-1/






Monday, October 10, 2016

Sharepoint Add an app - Storefront javascript listtemplate modification

Description:
To display only ListTemplate that contains 'CG_', which can be customised as per your need. This script was added into masterpage using ScriptLink customactions javascript embed. 

Note:
The $2b_3 and $M_3 collection variables tend to change based on MS updates. You have to find the right one using browser devtools in your 'add an app page' to check the OOTB Storefront collection's and get the right ones.

Code:
//Function to hide OOTB apps in 'AddAnApp' page
function CGRefreshUI() {
            var listedApps = SP.Storefront.StorefrontApp.get_currentView();  
             //remove  Noteworthy
            listedApps.$2b_3.length = 0;
              //remove all except List templates starting with 'CG_'
                  for (var i = listedApps.$M_3.length-1; i--;) {
               if (listedApps.$M_3[i].$2R_0.Title.indexOf("CG_") < 0 ) {
                  listedApps.$M_3.splice(i, 1);
               }
            }
            SP.Storefront.StorefrontApp.get_currentView().updateUI();
}

//Function check if SP.Storefront js is loaded and call core method
function CGAlterStorefront() {
        if (SP.Storefront != undefined) {                       
var listedApps = SP.Storefront.StorefrontApp.get_currentView();
if (listedApps == undefined || listedApps.$2b_3 == null || listedApps.$M_3 == null) { setTimeout(CGAlterStorefront, 300); return; }
listedApps.spProxy.add_getAppsCompleted(CGRefreshUI);
CGRefreshUI();
        }
    }


//Call Alter 'Add an Apps/StoreFront' function
   _spBodyOnLoadFunctionNames.push("CGAlterStorefront");


Reference:
https://spmatt.wordpress.com/2014/05/21/hiding-the-out-of-the-box-document-library-in-sharepoint-2013/

Monday, September 8, 2014

SharePoint 2013 - Powershell deployment simple log / logging function

Function:

$dp0 =  [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Definition)

Function write-log($date,$EventType,$EventMesage,$functionName,$Filename)
{  
    $dp0 = $(get-location)
    $date = get-date
    $index= "$dp0".LastIndexOf("\")
    $logloc="$dp0".Substring(0,$index)
   
    $EventMesages = $EventMesage -replace ",", "."

     $LogFilePath = "$dp0\ScriptExecLogs.csv"
   # Write-Host $LogFilePath
    $EventMesages = $EventMesage -replace ",", "."
   
    if($EventType -eq $null){
        $EventType="Event type not Specified"
    }
    if($EventMesage -eq $null){
        $EventMessage = "NA"
    }
    if($Filename -eq $null){
        $Filename = "No File Provided"
    }
    if($functionName -eq $null){
        $functionName = "Function name not provided"
    }
   
   
   
    Add-content -Path  $LogFilePath -value  "$date,$EventType,$EventMesages,$functionName,$Filename"
}

Function call:

1.write-log $date "message"  "PowerShell Snapin added successfully"   "GlobalCall" "SiteColumn"


2.catch
        {
             write-log $date "error" $_.Exception.Message ("on"+$_.Name+": field creation") "createContentType" "SiteContentType"
        }

SharePoint 2013 - Shared Column / fields and allowed contenttypes setup - powershell

Powershell:

#Get input XML

$xmlFile1  =  "$dp0\SharedColumns.xml"
                $col = [xml](Get-Content $xmlFile1)
                $sharedcol=$col.SiteColumns.Columns.Field.Name
                 $FieldName = $_.Name        
                    $myCT=$web.ContentTypes[$contentTypeName]

#Set Shared Columns
                    $sharedFileXMLPrefix=”"
                    $sharedFileXML=""
                    $sharedFileXMLSuffix="

                 
                       $sharedcol | ForEach {
                       Write-Host $_
                       $id=$myCT.Fields[$_].Id


                        $sharedFileXML=$sharedFileXML+""
                            Write-Host $sharedFileXML
                         
                        }

                $FinalValue=$sharedFileXMLPrefix+$sharedFileXML+ $sharedFileXMLSuffix
                Write-Host $FinalValue
                $oXMLDocument=New-Object System.XML.XMLDocument
                $ns = New-Object Xml.XmlNamespaceManager $oXMLDocument.NameTable
                $ns.AddNamespace( "NamespaceURI", "http://schemas.microsoft.com/office/documentsets/sharedfields" )
                $oXMLDocument.LoadXML($FinalValue);
                Write-Host $oXMLDocument.ToString();
                $myCT.XmlDocuments.Delete("http://schemas.microsoft.com/office/documentsets/sharedfields");
                $myCT.XmlDocuments.Add($oXMLDocument);


#Set Allowed ContentType

                $AllowedCTName=$col.SiteColumns.Columns.AllowedCT
                    Write-Host $AllowedCTName
                    $AllowedCT=$web.ContentTypes[$AllowedCTName]
                    $AllowedCTXMLPrefix=”"
                    $AllowedCTXML=""
                    $AllowedCTXMLSuffix="
”               
                       $AllowedCTid=$AllowedCT.Id
                        $AllowedCTXML=$AllowedCTXML+""
                            Write-Host $AllowedCTXML
                         



                $AllowedCTFinalValue=$AllowedCTXMLPrefix+$AllowedCTXML+ $AllowedCTXMLSuffix
                Write-Host $AllowedCTFinalValue
                $AllowedCTXML=New-Object System.XML.XMLDocument
                $ns1 = New-Object Xml.XmlNamespaceManager $AllowedCTXML.NameTable
                $ns1.AddNamespace( "NamespaceURI", "http://schemas.microsoft.com/office/documentsets/allowedcontenttypes" )
                $AllowedCTXML.LoadXML($AllowedCTFinalValue);
                Write-Host $AllowedCTFinalValue.ToString();
                $myCT.XmlDocuments.Delete("http://schemas.microsoft.com/office/documentsets/allowedcontenttypes");
                $myCT.XmlDocuments.Add($AllowedCTFinalValue);




                $myCT.Update();


XML: