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:



 
   
 

Friday, September 5, 2014

SharePoint 2013 - Get Add Remove - My Tags or SocialTag using javascript service call


SharePoint 2013 - Get Add Remove - My Tags - SocialTag - avaliable in socialdataframe.aspx ( Tags and Note Board ) - using service call  /_vti_bin/socialdatainternalservice.json 

GetTags:
$.ajax({
                                                           url: "/_api/contextinfo",
                                                           type: "POST",
                                                           contentType: "application/x-www-url-encoded",
                                                           dataType: "json",
                                                           headers: { "Accept": "application/json; odata=verbose", },
                                                           success: function (data) {
                                                               if (data.d) {
                                                                   var digest = data.d.GetContextWebInformation.FormDigestValue;
alert(digest);
                                                                   $.ajax({
                url: "/_vti_bin/socialdatainternalservice.json/GetSocialTagInternal",
                dataType: 'json',
                type: 'POST',
                data: '{"targetPage":"http://vddp23g-6c4153b:100/us/spc-do-01/eFileLibrary/PX230230","maximumItemsToReturn":"12"}',
                contentType: 'application/json; charset=utf-8',
                headers: {
                                                                           "accept": "application/json;odata=verbose",
                                                                           "X-RequestDigest": digest,
                                                                       },
                success: function (data) {
alert('success');
                     console.log(JSON.stringify(data));
                },
                error: function (err) {

                    alert(JSON.stringify(err));
                }
            });
                                                               }
                                                           },
                                                           error: function (err) {
                                                               alert(JSON.stringify(err));
                                                           }
                                                       });
                                                      
                                                       }


AddTag:
(Replace following in the above ajax call)
url: "/_vti_bin/socialdatainternalservice.json/ManageTagInternal",
                dataType: 'json',
                type: 'POST',
                data: '{"targetPage":"","title":"","changes":[{"ChangeType":0,"TermID":"d5f86d42-4f82-4574-9318-4559b4f5d3a9","Term":"spotlight","IsPrivate":false}],"maximumItemsToReturn":"12"}',


RemoveTag:
(Replace following in the above ajax call)
url: "/_vti_bin/socialdatainternalservice.json/ManageTagInternal",
                dataType: 'json',
                type: 'POST',
                data: '{"targetPage":"","title":"","changes":[{"ChangeType":2,"TermID":"350ba065-5119-4b9a-8d07-6e74d603d939","Term":"tamarind","IsPrivate":false}],"maximumItemsToReturn":"12"}',