SharePoint 2013 Site Collection deletion and restore options


In this post I want to review PowerShell Commands available for managing Site Collections to do operations like delete, restore-deleted and remove-deleted, viz., Remove-SPSite, Restore-SPDeletedSite, Remove-SPDeletedSite. I will also be reviewing differences in deleting Site Collection from Central Admin feature against using PowerShell commands with and without using -gradualdelete option.



Deleting Site Collection from Central Admin:




The Site Collection deletion action from central admin will not permanently delete the Site Collection but it will only be marked as deleted in the Site map table in the Configuration Database.


The Central admin deletion of Site Collection is same as deleting site using PowerShell Command with gradualdelete option.
Example:


If you run the following SQL Query against configuration database you will find the delete transaction id for the deleted site. (Please note that, since is a lab exercise I took liberty to execute query against a SharePoint Database. Querying SharePoint database is not supported by Microsoft)






This deleted Site Collection will only get deleted permanently only when the Timer Job for ‘Gradual Site Delete’ for that specific Web Application is ran as per schedule.



Before the timer-job is ran, the deleted site collection, can be found in the deleted Sites Collections list using the command Get-SPSiteDeleted.





If deleted site still exist in the deleted site list, then it can be restored successfully using Restore-SPDeletedSite





After restore, the Site Collection can be seen back at the same place where it was before deletion.





Remove-SPDeletedSite

Let’s redo the deletion as a -gradualdelete and then perform removing site permanently from the SharePoint Farm (from Site Map).




Verify in Site Map Table in Config Database.

No record of the site


Using 'Remove-SPSite' without using option 'gradualdelete'. (Deleting the Site Permanently).


If site is deleted using PowerShell with Remove-SPSite without gradualdelete option, then the site gets deleted permanently from the farm configuration - it can not be restored.


Remove-SPSite –Identity "http://test.sp2013.corp/Sites/SiteABC"



“Gradual Site Delete” Timer-Job


However the site may have got deleted permanently from the SharePoint Farm, and confirmed as per information in “Site Map” table, and even it can not be restored further, the Content Database only get back the deleted site space only after the ‘Gradual Site Delete’ timer-job is ran.


Ref: http://blogs.technet.com/b/wbaer/archive/2010/08/02/gradual-site-delete-in-sharepoint-2010.aspx

Provisioning CEWP on Share Point Pages


Project Structure:-

1. Add Default Data to Content Editor Web Part

Create any Pages in Solution and Add necessary tag:-


<asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
<SharePoint:ListItemProperty Property="BaseName" maxlength="40" runat="server" />
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<meta name="GENERATOR" content="Microsoft SharePoint" />
<meta name="ProgId" content="SharePoint.WebPartPage.Document" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="CollaborationServer" content="SharePoint Team Web Site" />

</asp:Content>

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

<WebPartPages:WebPartZone runat="server" title="loc:TitleBar" id="TitleBar" AllowLayoutChange="false" AllowPersonalization="false" Style="display:none;" >

 </WebPartPages:WebPartZone>

</asp:Content>


Add XML tag in Element File with C-Data tag

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="TestModule" Url="SitePages">

    <File Path="TestModule\asas.aspx" Url="TestModule/asas.aspx" Type="GhostableInLibrary"  >
      <Property Name="Title" Value="CEWP- Provisioning"/>

      <AllUsersWebPart WebPartZoneID="TopZone" WebPartOrder="0">

        <![CDATA[<WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
                  <Title>Content Editor</Title>
                      <FrameType>Default</FrameType>
                      <Description>Allows authors to enter rich text content.</Description>
                      <IsIncluded>true</IsIncluded>
                      <ZoneID>TopZone</ZoneID>
                      <PartOrder>0</PartOrder>
                      <FrameState>Normal</FrameState>
                      <Height />
                      <Width />
                      <AllowRemove>true</AllowRemove>
                      <AllowZoneChange>true</AllowZoneChange>
                      <AllowMinimize>true</AllowMinimize>
                      <AllowConnect>true</AllowConnect>
                      <AllowEdit>true</AllowEdit>
                      <AllowHide>true</AllowHide>
                      <IsVisible>true</IsVisible>
                      <DetailLink />
                      <HelpLink />
                      <HelpMode>Modeless</HelpMode>
                      <Dir>Default</Dir>
                      <PartImageSmall />
                      <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
                      <PartImageLarge>/_layouts/15/images/mscontl.gif</PartImageLarge>
                      <IsIncludedFilter />
                      <Assembly>Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
                      <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
                      <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
                      <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor"><![CDATA[ ​This is my test Content editor webpart ]]]]><![CDATA[></Content>
                      <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
                      </WebPart>]]>


      </AllUsersWebPart>
      
    </File>
  </Module>
</Elements>


2. Add HTML File link to Content Editor Web Part


Use above code as is and replace the Content Link tag with below mention setting.

Note:- here i am using HTML file reference from style library. 

 <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">~SiteCollection/Style%20Library/HTMLFiles/abc.html</ContentLink>



Add Print Button to List/Library form in SharePoint 2013 using jQuery


To Add the Print button, Open SharePoint list in browser, go to List Tab -> Customize List Tab -> Form Web Parts and then click on Default Display Form as shown in the fig below:




Then in this page, click on Add a Web Part 
and then from the web part Categories select Media and Content and then select Content Editor web part as shown in the fig below:



Then in the Content Editor web part click on Click here to add new content, then click on FORMAT TEXT -> Markup -> Edit Source as shown in the fig below:



Then in the HTML Souce, Add the below code as shown below:



<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script><script>

$(document).ready(function() {
  $('.printList').click(function() { 
  window.print(); 
  return false; 
  });
});</script>

<style> 
.printList{ 
    color:#666666; 
    font-weight:bold; 
    cursor:pointer; 
}
.printList:hover{ 
color:#333333; 
font-weight:bold; 
cursor:pointer; 
}
</style>
<button class="printList">Print This Item</button>



Configure outgoing Email settings using Gmail in SharePoint


Open Server Manager and then click on Add roles and features under Configure this local server as shown in the fig below:



Then in the Add Roles and Features Wizard click on Next, In the Installation Type, select Role-based or feature-based installation. And then click on Next. In the Server selection select the server (default also selected) and then click on Next. Do not do anything in the Server Roles click Next to go to Features. There check the check box SMTP server Then it will ask for Add features that are required for SMTP server? Click on Add Features. And click on Install. After this we do not need to do anything in this step, just wait that to finish.

Once finish,  Put cursor at right corner of the windows server 2012 and there click on the Search Icon. In the search box type IIS and then Click on Internet Information Services (IIS) 6.0 Manager.


This will open Internet Information Services (IIS) 6.0 Manager, Expand the server and Right click on SMTP Virtual server and Select Start as shown in the fig below:



Again Right click on SMTP Virtual server click on Properties. This will open the [SMTP Virtual server #1] properties dialog box.



In the General Tab, Click on Advanced... button and it will open the Indentification dialog box, IP address (All Unassigned) and then in the TCP port put 587 and click on OK.

Then click on the Access tab from the [SMTP Virtual server #1] properties dialog box. Here click on Authentication... button. Then in the Authentication dialog box, check the Anonymous access check box as shown in the fig below.



Then click on the Connections button and select radio button All Except the list below and click on OK as shown in the fig below.


http://www.sharepointads.com/members/scripts/imp.php?a_aid=enjoysharepoint&a_bid=a5b8afe5&a_rid=c0107ab9


Then click on Relay... button.
 Then in the Relay Restrictions dialog box select All Except the list below button as shown in the fig below and click on OK.



Then go to the Delivery tab and on the Delivery tab, click on Outbound Security, on the new window that opens select Basic Authentication and type your Gmail email and password in the Username and Password fields, and also select TLS encryption 



Then on the Delivery tab, click Outbound connections… and in the new Outbound connections change TCP port to 587 as shown in the fig below:



Then in the Advanced... button, In the Delivery tab, click on Advanced... button and in the Advanced Delivery dialog box in the Smart host field type smtp.gmail.com and in the Fully-qualified domain name, give system name click OK as shown in the fig below.



Then click on Apply and OK.

But here POP should be enabled in Gmail Account. That we can found in Gmail -> Settings -> Forwarding and POP/IMAP.



Now Open SharePoint Central Administration then go to System Settings. And then Click on Configure outgoing e-mail settings as shown in the fig below:



Then in the Outgoing E-Mail Settings, give Outbound SMTP server as smtp.gmail.com, From address as: abc@gmail.com and click on OK as shown in the fig below:



This finishes our configuration.