Wednesday, November 18, 2015

How to use Iframe under SharePoint

I have a sharepoint site : ABC.com\index.aspx this needs to show the content of another SharePoint site DEF.com\Index.aspx Changes need to be done in the Master page of DEF.com site Add the below tag in the head part of the MP.
 <WebPartPages:AllowFraming ID="AllowFraming" runat="server" __WebPartId="{E5EA0CB9-8180-485C-985F-51B4DEB34CC4}" />

Friday, November 13, 2015

Find current login user in sharepoint users group using REST and render output as HTML


$(document).ready(function ()  
{ 
 getCurrentUser(); 
 
}); 
 
function getCurrentUser()   
{  
 $.ajax
 ({  
  url: url+"/_api/web/CurrentUser",  
  method: "GET",  
  headers: { "Accept": "application/json; odata=verbose" },  
  success: function (data)  
  {  
   getCurrentUserGroupColl(data.d.Id);  
  },  
  error: function (data)   
  {  
   failure(data);  
  }  
 });  
}
  
function getCurrentUserGroupColl(UserID)   
{  
 $.ajax  
  ({  
   url: url+"/_api/web/GetUserById(" + UserID + ")/Groups",  
   method: "GET",  
   headers: { "Accept": "application/json; odata=verbose" },  
   success: function (data) 
   {  
   /* get all group's title of current user. */  
   var results = data.d.results; 
   var InnrHtmlgrp = "<br />
<ul>";  
   
   for (var i = 0; i &lt; results.length; i++)   
   {  
    if(results[i].Title == 'owner')
    {
    // Do the changes 
    //InnrHtmlgrp += "
<li>" + results[i].Title + "</li>
";  
    $("#manager").append(managerstring);  
    
    }
   }  
  
    
   }  
  });  
}

Monday, August 3, 2015

Handling Concurrency for the List

http://blogs.technet.com/b/stefan_gossner/archive/2011/11/10/using-synchronous-quot-after-quot-events-e-g-itemupdated-in-sharepoint-2010.aspx http://sharepoint.stackexchange.com/questions/25542/what-happens-if-an-earlier-event-receiver-throws-an-error https://karinebosch.wordpress.com/walkthroughs/event-receivers-walkthrough2/ http://sppms.blogspot.in/2012/05/sharepoint-2010-event-receivers-and.html http://www.sharepoint-tips.com/2012/01/importance-of-synchronous-event.html

Sunday, August 2, 2015

change the colour of sharepoint list item

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js" type="text/javascript"></script>


    $(window).load(function () {
        $Text = $("td.ms-cellstyle.ms-vb2:contains('GREEN')"); 
        $Text.parent().css("fore-color", "#01DF3A");
        $Text.css("color", "#01DF3A");
        $Text = $("td.ms-cellstyle.ms-vb2:contains('RED')");
        $Text.css("color", "#F90101");
        $Text = $("td.ms-cellstyle.ms-vb2:contains('AMBER')");
        $Text.css("color", "#EAC117");
    });
});
http://mekalikot.blogspot.in/2014/07/highlight-row-change-font-color-and.html

Wednesday, July 29, 2015

https://msdn.microsoft.com/en-us/library/ff398052(v=vs.120).aspx

Saturday, July 18, 2015

Write CSOM/JSOM/REST call in ASPX page

Nice Blog : http://allthatjs.com/2012/04/03/using-sharepoint-csom-in-html5-apps/
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<%@ Page language="C#" %>
<%@ Register Tagprefix="SharePoint" 
     Namespace="Microsoft.SharePoint.WebControls" 
     Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<html>
<head>
      <title></title>
    <!-- the following 5 js files are required to use CSOM -->
     <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
    <script type="text/javascript"src="/_layouts/1033/init.js"></script>
    <script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
    <script type="text/javascript" src="/_layouts/15/sp.core.js"></script>
    <script type="text/javascript" src="/_layouts/15/SP.Runtime.js"></script>
    <script type="text/javascript" src="/_layouts/15/SP.js"></script>
 
    <!-- include your app code -->
       <script type="text/javascript">

           var context = SP.ClientContext.get_current();
           var user = context.get_web().get_currentUser();

           // This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
           $(document).ready(function () {
               getUserName();
           });

           // This function prepares, loads, and then executes a SharePoint query to get the current users information
           function getUserName() {
               context.load(user);
               context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
           }

           // This function is executed if the above call is successful
           // It replaces the contents of the 'message' element with the user name
           function onGetUserNameSuccess() {
               $('#message').text('Hello ' + user.get_title());
           }

           // This function is executed if the above call fails
           function onGetUserNameFail(sender, args) {
               alert('Failed to get user name. Error:' + args.get_message());
           }

    </script>

-->
  
</head>
<body>
    <SharePoint:FormDigest ID="FormDigest1" runat="server"></SharePoint:FormDigest>

     <div>
        <p id="message">
            <!-- The following content will be replaced with the user name when you run the app - see App.js -->
            initializing...
        </p>
    </div>
</body>
</html>

Wednesday, July 15, 2015

change the site to open the files as permissive

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Add-PSSnapin Microsoft.SharePoint.Powershell
$site = Get-SPSite("http://san001/sites/Harry")
$web = $site.OpenWeb()
$list = $web.GetList("http://san001/sites/Test/Shared Documents")
$list.browserfilehandling                      

$list.browserfilehandling = "Permissive"
$list.update()                                             
$list.browserfilehandling                     

One example is to loop through one web.


Add-PSSnapin Microsoft.SharePoint.Powershell
$site = Get-SPSite("http://san001/sites/Test")
$web = $site.OpenWeb()
foreach ($list in $web.Lists) 
{ 
     if($list.browserfilehandling -eq "Strict") 
     { 
          $list.browserfilehandling = "Permissive"; 
          $list.update(); $site.url, $list.title, $list.browserfilehandling
     } 
}

Tuesday, June 23, 2015

Wednesday, May 6, 2015

Batch file to run PowerShell

1
2
3
4
@echo starting
Powershell.exe -executionpolicy remotesigned -File AllResume_Details.ps1
@echo completed
pause

Script will download the document from the document library folder to the root folder of the machine where script has been executed

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
###############################################################
#Script Function : Script will download the resume from the Resume folder to the root folder where script has been executed.
# Otput of the execute is the Resume folder and a log file ,
# log file contains detail of script execution. The log file name prefix with "Output_RMSS_BulkDownload_Log" 
# Log file also gives the list of GUID which is not available in the resume folder. 
# Date :05/Feb/2015
# Created by : Sanjiv kumar 

################################################################


$snapinName = "Microsoft.SharePoint.PowerShell"
if ((Get-PSSnapin | Where-Object {$_.Name -eq $snapinName }) -eq $NULL) {
  write-host "SharePoint SnapIn not loaded. Loading..."
  Add-PSSnapin $snapinName -ErrorAction SilentlyContinue
}
#Change the URL for different environment.
$webUrl = "http://usdttdevbq005:1000/sites/Test/"
$listUrl = "http://usdttdevbq005:1000/sites/Test/Resumes/"



$destination=".\"
$Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss 
#Log file name 
$LogFileName=([string]::Concat("Output_RMSS_BulkDownload_Log" , $Datetime ,".txt"))
$ListOfGuidNotFound=""



##############################################################################

     New-Item  .\$LogFileName  -ItemType file 
        "variable initialization completed.."
        Add-Content  .\$LogFileName -Value "--->   variable initialization completed.."

        $web = Get-SPWeb -Identity $webUrl
        $list = $web.GetList($listUrl)
        "Document Library access.."
        Add-Content  .\$LogFileName -Value "--->   Document Library access.."

        $userGUIDCollection=import-Csv .\Input_CA_GUID.csv |  where {$_.key -eq $keyword} |select UserGUID
        "Read the CSV.."
        Add-Content  .\$LogFileName -Value "--->   Read the CSV.."
        
#Function start        
function ProcessFolder 
{
        param($folderUrl)
        $folder = $web.GetFolder($folderUrl)
       If($folder.Files.Count -ne 0)
    {
        foreach ($file in $folder.Files) 
        {
            Try
              { # Start Try
            
                    #Ensure destination directory
                    $destinationfolder = $destination + "/" + $folder.Url 
                   if (!(Test-Path -path $destinationfolder))
                    {
                        $dest = New-Item $destinationfolder -type directory 
                        "Create folder to disk." +$dest
                        Add-Content .\$LogFileName -Value ([string]::Concat("--->   Create folder to disk. : ",$dest))
                    }
                        #Download file
                        $binary = $file.OpenBinary()
                       
                        $stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create
                        $writer = New-Object System.IO.BinaryWriter($stream)
                        
                      
                        "Start File writting to disk ." +$file.Name
                         Add-Content .\$LogFileName -Value ([string]::Concat("--->   Start File writting to disk : ",$file.Name))
                         
                        $writer.write($binary)
                        $writer.Close()
                        
                        "End File writting to disk ." +$file.Name
                        Add-Content .\$LogFileName -Value ([string]::Concat("--->   End File writting to disk : ",$file.Name))
                        
                       
                      
                        
                 } # End Try
              
            catch 
                {

                    $ErrorMessage = $_.Exception.Message
                    Add-Content .\$LogFileName -Value ([string]::Concat("************************************"))
                    Add-Content .\$LogFileName -Value ([string]::Concat("**********Error with writing files to folder*******************"))
                    Add-Content .\$LogFileName -Value ([string]::Concat("System Message: ",$ErrorMessage))
                    Add-Content .\$LogFileName -Value ([string]::Concat("************************************"))
                    continue
   
                }  
                      
        } #End of For
        }
       
              
}

#Function end 








#Main start

#Download files in folders
 foreach($VaruserGUID in $userGUIDCollection)
 {
        "working for CSV GUID : " + $VaruserGUID.UserGUID.Trim().ToString()
         Add-Content .\$LogFileName -Value ([string]::Concat("`r`n--->   working for CSV GUID :  ",$VaruserGUID.UserGUID.Trim().ToString()))
    
    $varTemp = 0
    
    foreach ($folder in $list.Folders) 
    {# Start of For

            If($VaruserGUID.UserGUID.Trim().ToString() -eq $folder.DisplayName.Trim().ToString())
        {
           "GUID Matches : " + $VaruserGUID.UserGUID.Trim().ToString()
            Add-Content .\$LogFileName -Value ([string]::Concat("--->   GUID Matches with Resume folder name :  ",$folder.DisplayName.Trim().ToString()))
      ###############################################

            ProcessFolder($folder.Url)
             $varTemp = 1
         
           
        }
          
    }#End of For
      
            If($varTemp -eq 0)  # Checking that the GUID is found in Resume folder, Yes or No
        {
                        
            $ListOfGuidNotFound = $ListOfGuidNotFound.Trim().ToString() +"`r`n"+ $VaruserGUID.UserGUID.Trim().ToString()
        }    

}
 Add-Content .\$LogFileName -Value ([string]::Concat("`r`n*******START*** GUID Not Matches with Resume folder for GUID Start***********`r`n"+ $ListOfGuidNotFound +"*******END*** GUID Not Matches with Resume folder for GUID END***********`r`n"))

Fetch all non missing DOCID from the document library

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
############################################################################################################################################
# Script: Fetch all non missing DOCID from the resume repository

############################################################################################################################################

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

$host.Runspace.ThreadOptions = "ReuseThread"

#Definition of the function that allows to do the CAML query
function DoCAMLQuery
{
    param ($sSiteCollection,$sListName)
    try
    {
        $spSite=Get-SPSite -Identity $sSiteCollection
        $spwWeb=$spSite.OpenWeb()        
        $splList = $spwWeb.Lists.TryGetList($sListName)
        if ($splList)
        {
            $spqQuery = New-Object Microsoft.SharePoint.SPQuery
   $spqQuery.ViewAttributes = "Scope = 'Recursive'"
            $spqQuery.Query =  ""
   #$spQuery.ViewAttributes = "Scope = 'Recursive'"
   
            #$spqQuery.ViewFields = "" 
            #$spqQuery.ViewFieldsOnly = $true
            $splListItems = $splList.GetItems($spqQuery)

            $iNumber=1
            foreach ($splListItem in $splListItems)
            {
                  
    Add-Content .\$LogFileName -Value ([string]::Concat( ($splListItem["ows_ID"] -as [string]) +"|"+ $splListItem["PDI GUID"] +"|"+ $splListItem["Document Title"] +"|"+ $splListItem["Created"]+"|"+ $splListItem["_dlc_DocIdUrl"]))
            }
        }    
        $spwWeb.Dispose()
    }
    catch [System.Exception]
    {

               $ErrorVar= $_.Exception.ToString()
                    Add-Content .\$LogFileName_Error -Value ([string]::Concat("************************************"))
                 
                    Add-Content .\$LogFileName_Error -Value ([string]::Concat("System Message: "+ $ErrorVar))
           
                    Add-Content .\$LogFileName_Error -Value ([string]::Concat("************************************"))
                    continue
    }
}
#Start-SPAssignment –Global
#Calling the function
$sSiteCollection="http://sp2010:23934/"

$sListName="Resumes"

$Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss
#Log file for Missing DocID
$LogFileName=([string]::Concat("Output_DocID_Missing_Log " , $Datetime ,".csv"))
New-Item  .\$LogFileName  -ItemType file
#Log file for Error
$LogFileName_Error=([string]::Concat("Error_DocID_Missing_Log " , $Datetime ,".txt"))
New-Item  .\$LogFileName_Error  -ItemType file
     
     
Add-Content  .\$LogFileName -Value $webUrl
Add-Content .\$LogFileName -Value ([string]::Concat("ID"+"|"+"GUID_Name" +"|"+ "File_Name" +"|"+ "Created_Date"+"|"+ "DOCID"))
write-host "Started..."
DoCamlQuery -sSiteCollection $sSiteCollection -sListName $sListName
write-host "Finished.."
#Stop-SPAssignment –Global

Remove-PSSnapin Microsoft.SharePoint.PowerShell

Tuesday, April 28, 2015

Powershell Script to fetch the GUID and Document Name for Null DOCID

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
###############################################################
#Script Function : Script will fetch the GUID and Document Name for Null DOCID,
#Developed: Sanjiv kumar                

################################################################


If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }
#Get SPWeb and Our List we are targeting.
 try
    {
        $web = Get-SPWeb "http://sp2010:23934/"
        $list = $web.Lists["Resumes"]
        $Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss
  
        #Log file for Missing DocID
        $LogFileName=([string]::Concat("Output_DocID_Missing_Log " , $Datetime ,".csv"))
        New-Item  .\$LogFileName  -ItemType file
       
        #Log file for Error
        $LogFileName_Error=([string]::Concat("Error_DocID_Missing_Log " , $Datetime ,".txt"))
        New-Item  .\$LogFileName_Error  -ItemType file
       
       
        Add-Content  .\$LogFileName -Value $webUrl
        Add-Content  .\$LogFileName -Value "Number of Folders : $folderscount"
        Add-Content .\$LogFileName -Value ([string]::Concat("GUID_Name" +","+ "File_Name"))
       
       
       
       
        #Build Query
        $spQuery = New-Object Microsoft.SharePoint.SPQuery
        #CAML Query Using a DateTime Value and and Offset of Today
        $query = ''
        $spQuery.ViewAttributes = "Scope = 'Recursive'"
        $spQuery.Query = $query
        $spQuery.RowLimit = $list.ItemCount
        $spListItemCol = $list.GetItems($spQuery)
       
        #Writting the data to CSV
        foreach ($item in $spListItemCol)
        {
         #write-host "PD GUID:" $item["PDIGUID"] "File Name:" $item["Name"] -ForegroundColor Green
         Add-Content .\$LogFileName -Value ([string]::Concat($item["PDIGUID"] +","+ $item["Name"]))
        }
       
        $web.Dispose()
  }
  catch [System.Exception]
  {
   #write-host -f red $_.Exception.ToString()
   #write-host -f red $_.Exception.Message
   
     #write-host -f red $Error[0].Exception.Message
             #$ErrorVar= $_.Exception.ToString()
                    Add-Content .\$LogFileName_Error -Value ([string]::Concat("************************************"))
                 
                    Add-Content .\$LogFileName_Error -Value ([string]::Concat("System Message: "+ $ErrorVar))
                    #Add-Content .\$LogFileName_Error -Value ([string]::Concat("System Message: "+ $Error[0]))
                   
                    #Add-Content .\$LogFileName_Error -Value ([string]::Concat("System Message: "+ $_.Exception.ItemName))
                    Add-Content .\$LogFileName_Error -Value ([string]::Concat("************************************"))
                    continue
 
  }

  Remove-PSSnapin Microsoft.SharePoint.PowerShell

Wednesday, April 22, 2015

PowerShell to get list of SharePoint Folders Names , Files counts and File Name in the CSV format

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")


$webUrl ="http://sp2010:23934/TEST" # Weburl till the Library
$listName = "TEST" # Document Library Name
$destination=".\"

$Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss 
$LogFileName=([string]::Concat("DPN_LogFile " , $Datetime ,".csv"))
     New-Item  .\$LogFileName  -ItemType file 
        "variable initialization completed.."
        


$sc = New-Object Microsoft.SharePoint.SPSite($webURL)
$web = $sc.OpenWeb()
$list = $web.Lists[$listName]
$folderscount = 0
$folderswithresumes =0
$filesCount =0
$folderscount = $list.Folders.Count
Add-Content  .\$LogFileName -Value $webUrl
 Add-Content  .\$LogFileName -Value "Number of Folders : $folderscount"
 Add-Content .\$LogFileName -Value ([string]::Concat("GUID_Name" +","+ "Files_Count"+","+ "File_Name"))

 #Folder Name in each of the folder
foreach ($folder in $list.Folders) 
{
   $FileNames=""
   $foldFirstLvl = $list.ParentWeb.GetFolder($web.Url + "/" + $list.RootFolder.Url + "/" + $folder.Name)
   $filesCount = $foldFirstLvl.Files.Count
   
   #File Counts from each SP folder
   foreach ($file in $foldFirstLvl.Files) 
   {
 $FileNames = $FileNames + ","+ $file.Name
   }
   $FileNames = $FileNames.trim(",")
   Add-Content .\$LogFileName -Value ([string]::Concat($folder.Name +","+ $filesCount +","+ $FileNames))
   
   
}


$web.Dispose()

PowerShell to delete the SPFolder from the SharePoint Document Library using input CSV file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
$snapinName = "Microsoft.SharePoint.PowerShell"  
 if ((Get-PSSnapin | Where-Object {$_.Name -eq $snapinName }) -eq $NULL) {  
  write-host "SharePoint SnapIn not loaded. Loading..."  
  Add-PSSnapin $snapinName -ErrorAction SilentlyContinue  
 }  
 #Change the URL for different environment.  
 #$webUrl = "http://usdttdevbq005:1000/sites/Test/"  
 #$listUrl = "http://usdttdevbq005:1000/sites/Test/Resumes/"  
 $webUrl = "http://sp2010:23934/"  
 $listUrl = "http://sp2010:23934/TEST/"  
 $destination=".\"  
 $Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss   
 $InputCSVFile=".\Input_GUID.csv"  
 #Log file name   
 $LogFileName=([string]::Concat("Output_GRR_Bulk_DeleteFolder_Log" , $Datetime ,".txt"))  
 $ListOfGuidNotFound=""  
  Try  
     { # Start Try  
    New-Item .\$LogFileName -ItemType file   
     "variable initialization completed.."  
     Add-Content .\$LogFileName -Value "--->  variable initialization completed.."  
     $web = Get-SPWeb -Identity $webUrl  
     $list = $web.GetList($listUrl)  
     "Document Library access.."  
     Add-Content .\$LogFileName -Value "--->  Document Library access.."  
     $userGUIDCollection=import-Csv $InputCSVFile | where {$_.key -eq $keyword} |select UserGUID   
     "Read the CSV.."  
     Add-Content .\$LogFileName -Value "--->  Read the CSV.."  
 #Main start  
 #Download files in folders  
  foreach($VaruserGUID in $userGUIDCollection)  
  {  
     "working for CSV GUID : " + $VaruserGUID.UserGUID.Trim().ToString()  
      Add-Content .\$LogFileName -Value ([string]::Concat("`r`n--->  working for CSV GUID : ",$VaruserGUID.UserGUID.Trim().ToString()))  
    $varTemp = 0  
   foreach ($folder in $list.Folders)   
   {# Start of For  
       If($VaruserGUID.UserGUID.Trim().ToString() -eq $folder.DisplayName.Trim().ToString())  
     {  
       "GUID Matches : " + $VaruserGUID.UserGUID.Trim().ToString()  
       Add-Content .\$LogFileName -Value ([string]::Concat("--->  GUID Matches with Resume folder name : "+ $VaruserGUID.UserGUID.Trim().ToString() ))  
       $list.Folders.DeleteItemById($folder.ID)   
                  Add-Content .\$LogFileName -Value ([string]::Concat("--->  Folder has been deleted for : "+ $VaruserGUID.UserGUID.Trim().ToString() ))  
        $varTemp = 1  
     }  
   }#End of For  
       If($varTemp -eq 0) # Checking that the GUID is found in Resume folder, Yes or No  
     {  
       $ListOfGuidNotFound = $ListOfGuidNotFound.Trim().ToString() +"`r`n"+ $VaruserGUID.UserGUID.Trim().ToString()  
     }    
 }  
   Add-Content .\$LogFileName -Value ([string]::Concat("`r`n*******START*** GUID Not Matches with Resume folder for GUID Start***********`r`n"+ $ListOfGuidNotFound +"*******END*** GUID Not Matches with Resume folder for GUID END***********`r`n"))  
     } # End Try  
   catch   
   {  
           $ErrorMessage = $_.Exception.Message  
           Add-Content .\$LogFileName -Value ([string]::Concat("************************************"))  
           Add-Content .\$LogFileName -Value ([string]::Concat("**********Error with writing files to folder*******************"))  
           Add-Content .\$LogFileName -Value ([string]::Concat("System Message: ",$ErrorMessage))  
           Add-Content .\$LogFileName -Value ([string]::Concat("************************************"))  
           continue  
   }   

Powershell to create SharePoint folder in SharePoint Library with adding two different set of files

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#Create Folder from the given Range and copy the file
# Keep the file in C:\mydoc.txt

$snapinName = "Microsoft.SharePoint.PowerShell"
if ((Get-PSSnapin | Where-Object {$_.Name -eq $snapinName }) -eq $NULL) {
  write-host "SharePoint SnapIn not loaded. Loading..."
  Add-PSSnapin $snapinName -ErrorAction SilentlyContinue
}
$webUrl = "http://sp2010:23934/"
$listName = "TEST" #Document Library
$StartCounterGUID=1000; #Starting Folder number
$EndCounterGUID = 1003; #End Folder number



 Try
       { # Start Try 
       
                # Open web and library
                $web = Get-SPWeb $webUrl
                $list = $web.Lists[$listName]
                 
                # Create desired number of subfolders
                for($i=$StartCounterGUID; $i -le $EndCounterGUID; $i++)
                {
                $folder = $list.AddItem("", [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "$i")
                $folder.Update()

                $spFolder = $web.GetFolder("$listName\$i")
                # Get the file on Disk that we want to upload
                $file = Get-Item C:\mydoc.txt
                # upload the file.
                write-host "$listName\$i\mydoc.txt"
                [Microsoft.SharePoint.SPFile]$spFile = $spFolder.Files.Add("$i"+"mydoc.txt",$file.OpenRead(),$false)
                     
                $spFile.Item["Title"] = "$i"+"mydoc.txt"           
                $spFile.Item.Update()

                write-host "$listName\$i\yourdoc.doc"
                [Microsoft.SharePoint.SPFile]$spFile = $spFolder.Files.Add("$i"+"yourdoc.doc",$file.OpenRead(),$false)
                     
                $spFile.Item["Title"] = "$i"+"yourdoc.doc"    
                 #$spFile.Item["GUID"] = "$i"+"yourdoc.doc"          
                $spFile.Item.Update()

                write-host $i
                }
                $web.Dispose() 
              
              
    }
     
                
     catch 
   {

                 
      $web.Dispose() 
                    write-host  "Web Disposed"
                    $ErrorMessage = $_.Exception.Message
                    write-host  $ErrorMessage
                    continue
   
    }
    

Monday, March 9, 2015

Host header for SiteCollection in SharePoint 2010/ 2013


New-SPSite 'http://HR.MiracleInformatics.com' -HostHeaderWebApplication 'http://Win2012:1000' -Name 'HR Site' -Description 'Customer root' -OwnerAlias 'Miracle\administrator' -language 1033 -Template 'STS#0'

HTML

Script:

JS