ĐÀO TẠO DOANH NGHIỆP : SỞ KHOA HỌC CÔNG NGHỆ TỈNH ĐỒNG NAI

ENTERPRISE TRAINING: DONG NAI DEPARTMENT OF SCIENCE AND TECHNOLOGY.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

Monday, September 26, 2016

Using PowerShell to find site/subsite/list/library size in SharePoint


Size of Site collection and all subsites


#Get Size of all Sub-sites in a Site Collection
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

# Function to calculate folder size
Function CalculateFolderSize($Folder)
{
    [long]$FolderSize = 0
 
    foreach ($File in $Folder.Files)
    {
   #Get File Size
        $FolderSize += $file.TotalLength;
   
  #Get the Versions Size
        foreach ($FileVersion in $File.Versions)
        {
            $FolderSize += $FileVersion.Size
        }   
    }
 #Iterate through all subfolders
    foreach ($SubFolder in $Folder.SubFolders)
    {
  #Call the function recursively
        $FolderSize += CalculateFolderSize $SubFolder
    }
    return $FolderSize
}

 
$SiteURL = "http://yoursite"
$Site = new-object Microsoft.SharePoint.SPSite($SiteURL)
  #Array to Hold Result - PSObjects
  $ListItemCollection = @()
 
  foreach($Web in $Site.AllWebs)
  {
    $ExportItem = New-Object PSObject
    #Call function to calculate Folder Size
    [long]$WebSize = CalculateFolderSize($Web.RootFolder)
   
    #Get Recycle Bin Size
    foreach($RecycleBinItem in $Web.RecycleBin)
        {
           $WebSize += $RecycleBinItem.Size
        }
        $Size = [Math]::Round(($WebSize/1024)/1024, 2)
        Write-Host  $web.Url ":`t" $Size "MB"
        $ExportItem | Add-Member -MemberType NoteProperty -name "Web URL" -value $web.Url
        $ExportItem | Add-Member -MemberType NoteProperty -name "Web Size" -value $Size
        $ListItemCollection += $ExportItem
    #Dispose the object
    $web.dispose()
   }
  
   $ListItemCollection | Export-CSV C:\allsubsitesof.csv -NoTypeInformation

Size of Lists and Libraries include version

#Set variables
$siteURL = "http://yoursite"
$site = new-object Microsoft.SharePoint.SPSite($siteURL)

$ListItemCollection = @()
foreach ($web in $site.AllWebs)
{
  foreach ($list in $web.Lists)
   {
   $ExportItem = New-Object PSObject
           $listSize = 0
           foreach ($item in $list.items)
            {
            $listSize += ($item.file).length
            foreach($FileVersion in $item.File.Versions) 
                {
                   $listSize += $FileVersion.Size
                }               
            }
            $Size = [Math]::Round(($listSize/1024)/1024, 2)
            Write-Host  $web.Title ":`t" $list.Title ":`t" $listSize   
            $ExportItem | Add-Member -MemberType NoteProperty -name "WebTitle" -value $web.Title
            $ExportItem | Add-Member -MemberType NoteProperty -name "WebURL" -value $web.URL
            $ExportItem | Add-Member -MemberType NoteProperty -name "WebDescription" -value $web.Description
            $ExportItem | Add-Member -MemberType NoteProperty -name "List_Library_Name" -value $list.Title
            $ExportItem | Add-Member -MemberType NoteProperty -name "Size (MB)" -value $Size
        $ListItemCollection += $ExportItem
    }
   
}
$ListItemCollection | Export-CSV C:\sizeoflistsandlibrary.csv -NoTypeInformation
$Site.Dispose()

Tuesday, March 8, 2016

SharePoint 2010 get list items using list.asmx service using Jquery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="/Style%20Library/DownloadDocuments/jquery.SPServices-2014.02.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function popupCenter(title, w, h, url) {
            var url = "/SitePages/Download.aspx?ID=" + url;
            var left = (screen.width / 2) - (w / 2);
            var top = (screen.height / 2) - (h / 2);
            var win = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
            win = null;
            return false;
        }


        function GetSoapQuery() {
            var soapEnv =
                "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                     <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                        <listName>ListOfDownloadDocument</listName> \
                        <viewFields> \
                            <ViewFields> \
                               <FieldRef Name='ID' />\
                               <FieldRef Name='Title' />\
                               <FieldRef Name='LinkToDocument' />\
                               <FieldRef Name='IsShow' />\
                               <FieldRef Name='DisplayOrder' />\
                           </ViewFields> \
                        </viewFields> \
                        <query> \
                         <Query> \
                           <Where> \
                              <Eq> \
                                 <FieldRef Name='IsShow' /> \
                                 <Value Type='Integer'>1</Value> \
                              </Eq> \
                           </Where> \
                           <OrderBy> \
                               <FieldRef Name='DisplayOrder' Ascending='true'/> \
                           </OrderBy> \
                </Query> \
             </query> \
                    </GetListItems> \
                </soapenv:Body> \
            </soapenv:Envelope>";
            return soapEnv;
        }

        $(document).ready(function () {
            var soapEnv = GetSoapQuery();
            $.ajax({
                url: "http://ServerName/_vti_bin/lists.asmx",
                type: "POST",
                dataType: "xml",
                data: soapEnv,
                complete: processResult1,
                contentType: "text/xml; charset=\"utf-8\""
            });
        });


        function processResult1(xData, status) {
            $(xData.responseXML).SPFilterNode("z:row").each(function () {
                var id = $(this).attr("ows_ID");
                /*alert("ID:" + id);*/
                var title = $(this).attr("ows_Title");
                /*alert("Title:" +title);*/
                var linkToDocument = $(this).attr("ows_LinkToDocument");
                var hyperLink = linkToDocument.split(',')[1];
                /*alert("hyperLink:" +hyperLink);*/

                /*$("#download").append('<li><p><a href="javascript:void(0);" onclick="popupCenter(&#39;myPop1&#39;,450,200,&#39;' + hyperLink + '&#39;);">' + title + '</a></p></li>');*/
                $("#download").append('<li><p><a href="javascript:void(0);" onclick="popupCenter(&#39;myPop1&#39;,450,200,' + id + ');">' + title + '</a></p></li>');
            });
        }   
 
    </script>
   
   
    <h1>List of download document</h1>
        <ul id="download">
        </ul>
    </div>

Friday, November 6, 2015

Sharepoint PowerShell List of all site collections in Web Application

$xl=New-Object -ComObject "Excel.Application"
$xl.Visible=$True
$xl.Workbooks.Add()
$ws=$xl.ActiveWorkbook.ActiveSheet
$cells=$ws.Cells
$i = 1
$sites = Get-SPSite -Limit All -WebApplication http://pc362/
foreach ($site in $sites)
{
 $cells.item($i,1)= invoke-command { $site.URL }
 $cells.item($i,2)= invoke-command { $site.Owner.UserLogin }
 $cells.item($i,3)= invoke-command { $site.SecondaryContact.UserLogin }
 $cells.item($i,4)= invoke-command { $site.WebApplication.DisplayName }
 $cells.item($i,5)= invoke-command { $site.Usage.Storage/1MB }
 $cells.item($i,6)= invoke-command { $site.ContentDatabase.Name }
 $cells.item($i,7)= invoke-command { $site.Quota.Storagemaximumlevel }
 $cells.item($i,8)= invoke-command { $site.RootWeb.SiteUsers.Count }
 $cells.item($i,9)= invoke-command { $site.Usage.Hits }
 $cells.item($i,10)= invoke-command { $site.Usage.Bandwidth }
 $i++
}

Or

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
#Configure the location for the output file
$Output="C:\Output.csv";
"Site URL"+","+"Owner Login"+","+"SecondaryContact Login"+","+"WebApplication DisplayName"+","+"Quota Limit (MB)"+","+"Total Storage Used (MB)"+","+"Site Quota Percentage Used"+","+"ContentDatabase"+","+"SiteUsers"+","+"UsageHits"+","+"UsageBandwidth" | Out-File -Encoding Default -FilePath $Output;
#Specify the root site collection within the Web app
$Siteurl="https://your web application";
$Rootweb=New-Object Microsoft.Sharepoint.Spsite($Siteurl);
$Webapp=$Rootweb.Webapplication;
#Loops through each site collection within the Web app, if the owner has an e-mail address this is written to the output file
Foreach ($Site in $Webapp.Sites)
{if ($Site.Quota.Storagemaximumlevel -gt 0) {[int]$MaxStorage=$Site.Quota.StorageMaximumLevel /1MB} else {$MaxStorage="0"};
if ($Site.Usage.Storage -gt 0) {[int]$StorageUsed=$Site.Usage.Storage /1MB};
if ($Storageused-gt 0 -and $Maxstorage-gt 0){[int]$SiteQuotaUsed=$Storageused/$Maxstorage* 100} else {$SiteQuotaUsed="0"};
$Web=$Site.Rootweb; $Site.Url + "," + $Site.Owner.UserLogin + "," + $Site.SecondaryContact.UserLogin + "," +$Site.WebApplication.DisplayName + "," +$MaxStorage+","+$StorageUsed + "," + $SiteQuotaUsed+ "," + $Site.ContentDatabase.Name+ "," + $Site.RootWeb.SiteUsers.Count+ "," + $Site.Usage.Hits+ "," + $Site.Usage.Bandwidth | Out-File -Encoding Default -Append -FilePath $Output;$Site.Dispose()};

Monday, November 2, 2015

Sharepoint designer workflow update current item from lookup list based on current lookup field

Sharepoint designer workflow update current item from lookup list based on current lookup field

1. Create new custom list "Provinces". Rename Title to ProvinceID. Create new field ProvinceName (single line of text)

2. Create new custom list Employees. Rename Title to FullName. Create new field ProvinceID lookup to list Province and return ProvinceID.  Create new field ProvinceName (single line of text)

3. Create new workflow (list workflow)

4. Insert action Update item and configure like image below. Then configure workflow setting is "start workflow automatically when an item is created" and start workflow automatically when an item is changed. Then publish workflow.

5. Create new item and leave ProvinceName

6. Workflow auto update ProvinceName.

Done.

Thursday, October 22, 2015

PowerShell copy list item to another list with same structure

Insert item from source list

$web = Get-SPWeb http://yourURL
$lista =$web.Lists["Source List Name"]
$listb =$web.Lists["Target List Name"]
$items = $lista.items
foreach ($item in $items) {
write-host -foregroundcolor yellow $item["Title"]
$newitem= $listb.items.Add()
$newitem["Title"] = $item["Title"]
$newitem["MultiLine"] = $item["MultiLine"]
$newitem["Number"] = $item["Number"]
$newitem["HyperLink"] = $item["HyperLink"]
$newitem["Choice"] = $item["Choice"]
$newitem["Created"] = $item["Created"]
$newitem["Author"] = $item["Author"]
$newitem["Modified"] = $item["Modified"]
$newitem["Editor"] = $item["Editor"]
$newitem.update()
start-sleep 1
}
$web.dispose
start-sleep 10

Powershell sharepoint get item by id

$web = Get-SPWeb http://yourURL
$lista =$web.Lists["Source List Name"]
$listb =$web.Lists["Target List Name"]
$items = $lista.GetItemById(523)
foreach ($item in $items) {
write-host -foregroundcolor yellow $item["ID"]
write-host -foregroundcolor yellow $item["Title"]
start-sleep 1
}
$web.dispose
start-sleep 10

Update Item by ID

$web = Get-SPWeb http://yourURL
$lista =$web.Lists["Source List Name"]
$listb =$web.Lists["Target List Name"]
$items = $lista.GetItemById(523)
foreach ($item in $items) {
write-host -foregroundcolor yellow $item["Title"]
$newitem= $listb.GetItemById(524)
$newitem["Title"] = $item["Title"]
$newitem["MultiLine"] = $item["MultiLine"]
$newitem["Number"] = $item["Number"]
$newitem["HyperLink"] = $item["HyperLink"]
$newitem["Choice"] = $item["Choice"]
$newitem["Created"] = $item["Created"]
$newitem["Author"] = $item["Author"]
$newitem["Modified"] = $item["Modified"]
$newitem["Editor"] = $item["Editor"]
$newitem.update()
start-sleep 1
}
$web.dispose
start-sleep 10

Thanks.

Thursday, October 1, 2015

Listing All SharePoint Server Features of Web Application dynamic by power shell

Listing All SharePoint Server Features of Web Application dynamic by power shell
1. Writing the function to export all features of web application with parameter
function Get-SPFeatureActivated
{
[CmdletBinding()]
param(
    [parameter(Mandatory=$true)][string]$Url,#Input your URL of web application
    [parameter(Mandatory=$true)][string]$Path,#Input your file name which you want to export like (c:\features.csv)
    [Parameter(position = 1, valueFromPipeline=$true)]#Default para
    [Microsoft.SharePoint.PowerShell.SPFeatureDefinitionPipeBind]   
    $Identity
)#end param
    Begin
    {       
        $results = @()
       
        $params = @{}
    }
    Process
    {
        if([string]::IsNullOrEmpty($Identity) -eq $false)
        {
            $params = @{Identity = $Identity
                        ErrorAction = "SilentlyContinue"
            }
        }   

        # Get web application URL
    $webApplication = Get-SPWebApplication -Identity $Url
        foreach($webApp in $webApplication)
        {
            $results += (Get-SPFeature -WebApplication $webApp -Limit All @params |
                             % {Add-Member -InputObject $_ -MemberType noteproperty -Name Url -Value $webApp.Url -PassThru} |
                             Select-Object -Property Scope, DisplayName, Id, Url)

            # check site collection features in current web app
            foreach($site in ($webApp.Sites))
            {
                $results += (Get-SPFeature -Site $site -Limit All @params |
                                 % {Add-Member -InputObject $_ -MemberType noteproperty -Name Url -Value $site.Url -PassThru} |
                                 Select-Object -Property Scope, DisplayName, Id, Url)
                                
                $site.Dispose()

                # check site features in current site collection
                foreach($web in ($site.AllWebs))
                {
                    $results += (Get-SPFeature -Web $web -Limit All @params |
                                     % {Add-Member -InputObject $_ -MemberType noteproperty -Name Url -Value $web.Url -PassThru} |
                                     Select-Object -Property Scope, DisplayName, Id, Url)

                    $web.Dispose()
                }
            }
        }
    }
    End
    {
        $results > $Path
    }
}

2. Call function then input the value via parameter in above function

3. The result is all features is exported to csv file 
 Thanks.

Thursday, September 24, 2015

export and import lists and libraries full version and permission

How to export and import lists and libraries full version and permission
Exporting

# specify the site URL to export

$web = Get-SPWeb "microsofttechnology.net/sites/sharepoint"

# specify output folder to store exported lists

$path = "D:\SharepointLists"

foreach($list in $web.lists)

{

"Exporting " + $list.RootFolder.URL

export-spweb $web.URL -ItemUrl $list.RootFolder.URL -IncludeUserSecurity -IncludeVersions All -path ($path + $list + ".cmp")

}

Importing

# specify target SharePoint site to import into

$site = "microsofttechnology.net/sites/sharepoint1"

# specify folder containing exported lists

$folder = "D:\SharepointLists"

$Files = Get-ChildItem $folder

foreach ($file in $files)
{

$name = $file.Name

"Importing: " + "$folder$name"

import-spweb $site -path ("$folder$name") -includeusersecurity –UpdateVersions Overwrite
}