Wednesday, December 31, 2014

SharePoint App solution vs SharePoint solution deployment

Why should we need an App deployment model 

To fully understand Microsoft's motivation for beginning to transition away from SharePoint solution to the new app model  you must first understand the challenges in SharePoint solution..
Custom developed SharePoint solution runs within the host environment like Sandbox Solution runs within the sandbox worker process.  This behavior is not so good for farm's stability.
Second, SharePoint developed solutions with complex logic and highly dependability are not so easy to upgrade. What if any custom code is depended on a feature and that feature is deprecated or not coming in next version ?
Third is security and permission, code runs under the permission of  a specific user. Which could be risky sometimes.
So, App models solve these challenges..ex.
1.It is light weight. It doesn't carry extra markup like a webPart.
2. It runs in isolation of SharePoint. It has to authentication separately before using.

3.  Use any language - like HTML, JavaScript, PHP, or .NET - and your favorite web development tools - like Visual Studio 2012 or the new "Napa" Office 365 Development Tools.

4. Easy to upgrade.

Thursday, September 11, 2014

Create site collection programmatically in sharepoint 2013 with custom web template

To create site collection programmatically by using server object model use SPWebApplication .Sites.Add method. it has 12 overloads. choose any one which suits you. In this given code I am creating a site collection on host header (not on root site).
References :
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

Code:

 public void CreateSitecollection(string url, string title, string description, string ownerLogin, string ownerName, string ownerEmail, SPWebApplication webApp)
        {
            Uri urlNewSite = new Uri(url);
            try
            {
                if (!SPSite.Exists(urlNewSite))
                {

                    using (SPSite newSiteCollection = webApp.Sites.Add(
                        url,// url of the new site,give full url if you want to create site on host header else"/sites/anyname"
                       title,// title of the new site
                       description,//description
                       1053,//LCID
                       "WT_CollaborationSite",//give custom template naem
                       ownerLogin,// login anme like "corp\devuser"
                       ownerName,// name
                       ownerEmail,// email id of the primary user
                       ownerLogin, // secondry user
                       "",
                       "",
                       true))// user host header
                    {
                     
                    }
                }
                else
                {
                    throw new ArgumentNullException("Site already exists");
                }
            }
            catch (Exception)
            {
             
            }
        }


use this code anywhere like in a timer job or in a console application. give the "STS#0" in the template name if you want to use team site template.