Wednesday, March 7, 2018

Get number of all files on SharePoint farm

How to get number of all files in libraries in SharePoint farm


Add-PSSnapin Microsoft.SharePoint.PowerShell
Start-SPAssignment -Global
$OutputFile = “C:\Temp\DocCount.csv”
$results = @()
$webApps = Get-SPWebApplication
foreach($webApp in $webApps)
{
    foreach($siteColl in $webApp.Sites)
    {
        foreach($web in $siteColl.AllWebs)
        {
            $webUrl = $web.url
            $docLibs = $web.Lists | Where-Object {$_.baseType -eq “DocumentLibrary”}
            $docLibs | Add-Member -MemberType ScriptProperty -Name WebUrl -Value {$webUrl}
            $results += ($docLibs | Select-Object -Property WebUrl, Title, ItemCount)
        }
    }
}
$results | Export-Csv -Path $OutputFile -NoTypeInformation
   
Stop-SPAssignment -Global

Thursday, February 8, 2018

Create custom views on survey lists - SharePoint 2013

Cannot create custom view in SharePoint survey List.


Select any Survey list-->Survey Settings

http://********/InvIncidentReporting/_layouts/survedit.aspx?
List=%7BBF870743%2D9654%2D4E19%2DB4B1%2D35527D4BE942%7D


Edit URL with "viewtype" in place of "survedit"

http://********/InvIncidentReporting/_layouts/viewtype.aspx?
List=%7BBF870743%2D9654%2D4E19%2DB4B1%2D35527D4BE942%7D


Now you are able to see all types view and you can create views based filters,sorting, grouping etc like custom/issue tracking list.

SharePoint 2013 Display promoted links on multiple rows - script

Every item has a default of 160px, so when you want to show rows of 3 items, just limit the space to 3*160 = 480px.
Simply add a content editor or script editor to the page and add this code:

<style>
/*display rows of 3 items*/
.ms-promlink-body {
      width: 480px;
}
</style>

If you also have buttons on top (when you have more items in the row than can be shown on the page), you can add this part to the script to remove those buttons:

<style>
/*hide the arrows when you have more items than viewable*/
.ms-promlink-header{
display:none;
}
</style>

Always Open SharePoint 2013 Tasks in Edit Mode

  • Open the task list in SharePoint Designer and create a new List Form
  • In the Create New List Form window, set the Filename as “RedirectToEditForm”, the type as Display, and check “Set as the default for the selected type”. Also pick your Workflow Task content type.
  • Open the Form in Designer so that the code is displayed, then click the “Advanced Mode” button in the ribbon bar. This will open the entire page for edits. 
  • Insert the following javascript directly after the line <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"> (this is around line 15) 
  • <script type="text/javascript">
        <!--
        var origUrl = window.location.toString();
        var editUrl = origUrl.replace("RedirectToEditForm","EditForm");
        window.location = editUrl;
        //-->
    </script>
  • Save the form, accepting the change from the site definition

Now whenever someone opens a task, the EditForm is automatically displayed and only one click is needed to approve or reject the task

Hide "See Also" panel in Display Forms - SharePoint 2013

On the right-hand side of the screen when viewing the display form of a task item, there is a “See Also” section that displays documents which don’t apply to the task. How to hide "See Also"?


Add Content Editor web part in Display form. Insert code:


<style>

.ms-recommendations-panel{

       display:none !important;

}

</style>

Friday, November 17, 2017

Delete list items older than date - SharePoint, PowerShell

You need to delete SharePoint items older than date? It's easy with PowerShell.


Start Sharepoint Management Shell as Administrator

 Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
     
        #Configure target site and list.
     
        $list = $($(Get-SPWeb -Identity 'https://portal/test').Lists['ListName'])
     
        #Index count for list items.
     
        $index = $list.ItemCount
     
        #Index counter for paging.
     
        $page = 0
     
        #Configure how many items to delete per batch.
     
        $pagesize = 3000
     
        #Configure how may seconds to pause between batches.
     
        $sleep = 1
     
        #Turn verbose output on/off
     
        $verbose = $true
     
        While($index -ge 0){
     
        if($verbose){
     
        $("Check item at index $($index).")
     
        }
     
        if($page -lt $pagesize){
     
        try{
     
        if($($list.Items[$index])['DateField'] -lt [DateTime]::Parse("11/7/2017")){
     
        $list.Items[$index].Delete()
     
        write-host "Deleting item at index $($index)." -foregroundcolor "green"
     
        }
     
        }
     
        catch [System.Exception]{
     
        if($verbose){
        $("Skipping item at index $($index).")
     
        }
     
        }
     
        $index--
     
        $page++
     
        }
     
        else{
     
        if($verbose){
     
        $("Sleeping for $($sleep) seconds.")
     
        }
     
        [System.Threading.Thread]::Sleep($sleep * 1000)
     
        $page = 0
     
        }
     
        }

One picture icon with multiple links - SharePoint


How to click on one picture icon and open multiple links?

Add Content Editor Web Part

Edit source

<p><a href="#" onclick="window.open('http://google.com');
    window.open('http://yahoo.com');"><img src="https://projekti/test/pictures/freepik.jpg" style="margin:5px; width:68px; height=67px"></a></p>


 Save









Tuesday, October 24, 2017

Show / Hide fields based on choice field selection using JQuery in SharePoint


As example I have created a simple list with:
  • Name (Single line of text)
  • Insurance (Choice)
  • Family member1 (Single line of text)
  • Family member2 (Single line of text)
  • Family member3 (Single line of text)
If the Insurance field value is Family, fields Family member1, Family member2, Family member are "show". For other options in the Insurance, Family members fields are "hide".


Edit Default New form








Add a Web Part, Media and Content, Contend Editor.
In Edit Source paste next script

<script src="https://projekti/mc-putno_osiguranje/Shared%20Documents/jquery-1.3.2.js" type=text/javascript></script>
 
<script type="text/javascript">
 
// Execute the following JavaScript after the page has fully loaded, when it's ".ready"
$(document).ready(function(){
 
//Define which columns to show/hide by default
  $('nobr:contains("Family member1")').closest('tr').hide();
  $('nobr:contains("Family member2")').closest('tr').hide();
  $('nobr:contains("Family member3")').closest('tr').hide();
//Show/hide columns based on Drop Down Selection
 $("select[title='Insurance']").change(function() {
  if ($("select[title='Insurance']").val() == "Family") {
  $('nobr:contains("Family member1")').closest('tr').show();
  $('nobr:contains("Family member2")').closest('tr').show();
  $('nobr:contains("Family member3")').closest('tr').show()
  } else if($("select[title='Insurance']").val() != "Family"){
  $('nobr:contains("Family member1")').closest('tr').hide();
  $('nobr:contains("Family member2")').closest('tr').hide();
  $('nobr:contains("Family member3")').closest('tr').hide();
  }
 });
});
</script>


Save Page.














Download jquery-1.3.2.js from link

Friday, June 9, 2017

Start Workflow using Powershell - SharePoint 2013


# URL of Site
$web = Get-SPWeb -Identity "https://weburl/url"

$manager = $web.Site.WorkFlowManager

# Name of the list
$list = $web.Lists["ListName"]

# Name of the Workflow
$assoc = $list.WorkflowAssociations.GetAssociationByName("WorkflowName","en-US")

$data = $assoc.AssociationData
$items = $list.Items
foreach($item in $items)
 {
 $wf = $manager.StartWorkFlow($item,$assoc,$data,$true)
 }

$manager.Dispose()
$web.Dispose()
#

Friday, June 2, 2017

Add List Filter Search - SharePoint 2013

How to add custom filter search in SharePoint list?



Add Content editor web part













Instert code:

<script type="text/javascript">
 function RedirectUrl() {
 var tb = document.getElementById("tbSearch").value;
 var cs = document.getElementById("sfield").value;
 var url = "";

 if (tb != "") {
  if (cs == "Title" || cs == "Country"){
  url = "FilterField1=" + cs + "&FilterValue1=" + tb;
  window.location.href = "AllItems.aspx?" + url;
  }
  else { 
  url = "FilterName=" + cs + "&FilterMultiValue=*" + tb + "*";
  window.location.href = "AllItems.aspx?" + url;
  }
  }
  else {
  return false;
  }
 }
 function ClearUrl() {
 window.location.href = "AllItems.aspx";
 }
</script>
Search Field: <select id="sfield">
<option selected value="Title">Title</option>
<option value="Country">Country</option>
</select>
&nbsp;
Search text: <input type="text" id="tbSearch" />
<input type="button" id="btnSearch" value="Search" onclick="return RedirectUrl();" />
<input type="button" id="btnClear" value="Clear" onclick="return ClearUrl();" />















Save page.














Insert value in search box

Thursday, May 25, 2017

Hide Top Bar, Ribbon, and Quick Launch - SharePoint 2013

How to Hide Top Bar, Ribbon, and Quick Launch in SharePoint 2013 with css?

Edit page and add Content Editor Web Part














Insert code

<style type="text/css">
    #s4-ribbonrow, .ms-cui-topBar2, .s4-notdlg, .s4-pr s4-ribbonrowhidetitle, .s4-notdlg noindex, #ms-cui-ribbonTopBars, #s4-titlerow, #s4-pr s4-notdlg s4-titlerowhidetitle, #s4-leftpanel-content {display:none !important;}
    .s4-ca {margin-left:0px !important; margin-right:0px !important;}
    .ms-core-navigation { display: none; }
    #contentBox { margin-left: 0; }
</style>



Wednesday, May 24, 2017

Unable to delete site collection - SharePoint 2013

How to delete corrupted SharePoint Site Collection?

Error: Remove-SPSite : <nativehr>0x80070003</nativehr><nativestack></nativestack>


 




Solution:

$site = Get-SPSite https://siteurl

$siteId = $site.Id

$siteDatabase = $site.ContentDatabase

$siteDatabase.ForceDeleteSite($siteId, $false, $false)

Tuesday, January 24, 2017

Problem with database collation change SQL Server



The Database could not be exclusively locked to perform the operation.
ALTER DATABASE failed. The default collation of database 'DatabaseName' cannot be set to "Collaction Name".  (Microsoft SQL Server, Error: 5030)




use master
go
ALTER DATABASE xxx SET SINGLE_USER WITH ROLLBACK IMMEDIATE
go
ALTER DATABASE xxx COLLATE yyyy
go
ALTER DATABASE xxx SET MULTI_USER
go




WARNING: this call to SET SINGLE_USER WITH ROLLBACK IMMEDIATE will disconnect anyone who might be connected to that database without warning, without chance of saving data! 

Monday, January 9, 2017

Delete all subsites (All Child Webs) - SharePoint 2013 and PowerShell

Error: There was a problem deleting Web site "/Subsite". Sites that have subsites or certain apps can't be deleted. Please try again after deleting all subsites and removing the apps.


Solution:
Run PowerShell command
 
 
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
Function Remove-ChildSites([Microsoft.SharePoint.SPWeb]$Web)
{
 Foreach($ChildWeb in $Web.Webs)
  {
  #Call the function recursively TO DELETE all sub-childs
  Remove-ChildSites($ChildWeb)
 }
    Write-host Removing web $Web.Url
  
    #Remove the web
 Remove-SPWeb $Web -Confirm:$false
}
 
$ParentWebURL="http://portal/site/"
 
#Get the Parent Web
$ParentWeb= Get-SPWeb $ParentWebURL
 
#Call the function to remove all child webs
Remove-ChildSites $ParentWeb
 
 

Wednesday, September 28, 2016

Disable default "Send an email invitation" SharePoint 2013

How to permanently disable send an email invitation when granting access? We need it by default unchecked ( send an email invitation unchecked).























Open file C:\Program Files\Common Files\Microsoft Shared\web server extensions\15\TEMPLATE\LAYOUTS\aclinv.aspx
Change the Checked="true" to Checked="false"

<div class="ms-core-form-subsection">
                <asp:CheckBox
                    runat="server"
                    id="chkSendEmailv15"
                    Checked="true"
                    class = "ms-aclinv-checkbox"
                    OnClick="UpdateSendEmailMessage()"/>
                <label for=<%SPHttpUtility.WriteAddQuote(SPHttpUtility.NoEncode(chkSendEmailv15.ClientID),this.Page);%>>
                    <SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,aclinv_SendEmailCheckboxv15%>" EncodeMethod='HtmlEncode'/>
                </label>


Note: Change on all SharePoint Servers