Thursday, April 24, 2014

Site backup and restore programmatically - SharePoint 2013

Site backup and restore programmatically in SharePoint 2013 can be simple just like that in two lines of code.
To run this code successfully you must have the permission on the SharePoint farm and site collection administration.

Create the Shared folder on your server and set the permission to "Everyone" on the folder.

SPSecurity.RunWithElevatedPrivileges(delegate()
 {
 SPWebApplication webApps = SPWebApplication.Lookup(new Uri("http://webapplicationUrl/"));
SPSiteCollection sites = webApps.Sites;
 sites.Backup(SPContext.Current.Site.Url, @"\\Server\\SiteBackUp\\backup.dat", false);
 });
After this ensure your backup file work as expected by restoring the site using powershell command Restore-SPSite -Identity http:/site/sites/restoreSite -Path d:\backup.dat -DatabaseServer database serverName -DatabaseName WSS_Content -Force Alternatively you can also use Restore method of SPSiteCollection method. SPSiteCollection Class

Managing the unused site in SharePoint 2013

Before starting of reading this,its best to know how to identify the inactive site ? There is couple of properties available for SPSite class.


  1. LastContentModifiedDate
  2. LastSecurityModifiedDate

         using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                DateTime lastContentModified = site.LastContentModifiedDate;
                DateTime lastSecurityModified = site.LastSecurityModifiedDate;
            }

So you can decide to keep the inactive site in the server or not based on the number of days.
Unused site collection in SharePoint 2013 can be deleted from the server to free up some resources.
Before deleting the unused site collection, farm admin need to configure the outgoing email setting for sending the email notification to Site Owner. [Note: - Not Site collection administrator]
See the difference between Site Collection Administrator Vs Site Owner.
Farm admin can define to delete the SC then he need to determine what will be the waiting period for site collection to be declared as inactive.
He can schedule the email notification to SCA at daily, weekly and monthly intervals.
SharePoint 2013 restricts the number of email notices to be sent to site owners. Below table depicts the limitation on number of emails can be sent on chosen interval.

Interval
Min
Max
Daily
28
164
Weekly
4
24
Monthly
2
6

The email will contain the link to capture the site owner acknowledgment over his/her site status. If site owner does not respond to the email notification on specified duration then site will be deleted automatically. This feature must be turned on by the member of farm administrator group.
If site collection configured to delete automatically, it’s advisable to have site backup before site being deleted by the timer job.
If Site Owner specified the secondary site owner while creating the site then secondary site owner also will receive the email notices about the site deletion.
Site collection can be deleted by giving intimation of 30 days duration as minimum and maximum 365 days.
CAàClick on Application Management header linkà under site collection à Site Use Confirmation and Deletion.
Screen looks like this.

8

Another way is to delete the site create the site policy as seen in this post

Thursday, March 27, 2014

Creating List Definition and List Instance in Visual Studio 2012

This post may be seems to be simple for creating the List Definition,List Instance in SharePoint using Visual Studio 2010.

But definitely not when you are trying to implement using latest visual studio 2012 or 2013. Of course there are many instances to be created visually in VS 2012 but there you cannot find the "List Definition" project item as you were seen in VS2010.

To create the List Definition in VS 2012 or 2013 you need to select the "List" item template and select the "Create a customizable list template and list instance of it" and choose default (Custom List) as shown in the figure



else you will not get the List definition templates (List Instance, Element.xml, List template and its element.xml and Schema.xml).

Some points to note down here..Why should we need ? just consider you wanted to create the site definition with desired list (Feature Stapling - You will get two feature with site and web scoped from List definition template) and another scenario where you wanted to organize the SharePoint folders based on multiple layer.
Finally its helpful to develop the Model-View-Control (MVC) pattern based SharePoint application

Visual Studio 2013 simplifies the developer job by letting them to create the columns visually.In WSS 3.0 days It was so tedious job to manually creating the Field tag with multiple attributes and GUID for each fields.
The only simplest way is keeping the List Definitions Feature ID and ListInstance's Feature ID same

Now everything is just like that create all your columns and bind the content types in GUI as shown in the below screen.


Schema.xml file will be generated as you select columns and views from the above screen

List Definition Folder structure in SharePoint 2013



Friday, March 21, 2014

SharePoint App custom properties

This workaround is based on how to create the SharePoint hosted app using very basic level of "Twitter" widget.

How to prepare your twitter widget.
Steps
Login into your twitter account.
Click on the "Setting icon" in top of the right hand side.On pop up menu select the "Settings".
It will navigate to https://twitter.com/settings/account
On this page click the "Widget" on the "Configuration" select the desired settings such as height,width,theme,include replies and expand photos,based on this selection html tag and scripts will be generated.

Example : my twitter widget code to be placed on web page.



SharePoint hosted App with Custom Properties





Now create the SharePoint hosted app through visual studio 2012.
help link
http://msdn.microsoft.com/en-us/library/office/fp142379(v=office.15).aspx
All you need to do here is,add the "Client web part(hosted web).
Right click on the "SharePoint Project" ->Add New Item->Client WebPart (hosted web)
When you add you will be prompted to add this webpart in the existing page or in new page as shown in this picture.


Now go to your "WebPart's" Element.xml file and insert the properties like shown below.

Construct the content type xml node exactly same and see the Query value starts and ends with underscore.
Content Type="html" Src="~appWebUrl/Pages/TWP.aspx?TweetLimit=_TweetLimit_&theme=_theme_&IsReplyShow=_IsReplyShow_&" />


At run time you can change the number of tweets to be displayed and desired theme.

Download the code to learn more on  SharePoint app development

Source code.

       
       After this my App looks like this