Monday 21 March 2016

Load Vs LoadQuery

Load vs Loadquery

The LoadQuery method works in much the same way as the Load method, but it allows the client to process the queries more efficiently. The main difference is that the Load method populates the client object or client object collection that is passed into it. The LoadQuery method instead returns an entirely new collection of client objects. To get a clarification of these differences, examine the following examples for .NET managed code.
Retrieving the Number of Lists via the Load Method
class Program
{
static void Main(string[] args)
{
ClientContext ctx = new ClientContext(“http://server”);
ctx.Load(ctx.Web.Lists);
ctx.ExecuteQuery();
Console.WriteLine(“” + ctx.Web.Lists.Count);
Console.ReadLine(“Press RETURN…”);
}
}
In the above example Console.WriteLine(“” + ctx.Web.Lists.Count); will write the count of lists in the web since the ctx.Web.Lists gets loaded with the lists in the context.
Now lets see the other example, which uses the LoadQuery method, which is also initialized with the ctx.Web.Lists object. However, after the query is executed, the lists are returned as a completely new client object collection. If you try to directly access the property ctx.Web.Lists.Count, a CollectionNotInitialized exception is raised. This implies that, unlike in the above code, the original ctx.Web.Lists property has not been populated. Instead, a new allLists collection has been created and populated.
Retrieving the Number of Lists via the LoadQuery Method
class Program
{
static void Main(string[] args)
{
ClientContext ctx = new ClientContext(“http://server”);
IEnumerable allLists = ctx.LoadQuery(ctx.Web.Lists);
ctx.ExecuteQuery();
Console.WriteLine(“” + allLists.Count());
Console.ReadLine(“Press RETURN…”);
}
}
The advantage of LoadQuery over the Load method is its flexibility, especially when working with more than one query. It gives you better control over memory consumption, and query processing is more efficient. Consider garbage collection: the Load method populates objects that reside within the ClientContext instance. Those objects can only be cleaned up when the ClientContext instance is destroyed. Conversely, objects created by LoadQuery are separate from the ClientContext instance and can be destroyed much more readily, for example by setting them to NULL.

Step by step guide on upgrading a SharePoint 2010 site to a SharePoint 2013

  1. Add and deploy any required O14 custom solutions in your SharePoint 2013 farm, notice that all O14 solutions being deployed under 14 hive but eventually it’s recommended to migrate the custom code to O15.
  2. Backup and restore the SharePoint 2010 content database to your SQL Server hosting SharePoint 2013 farm.
  3. Run Test-SPContentDatabase cmdlet to identify missing components along with potential errors and related warnings. Check the upgrade log and deploy any missing components and re run the cmdlet to verify.
  4. Attach the content database to the desired web application using Mount-SPContentDatabase cmdlet.
  5. After successfully mounting the content database to web application, the site should be accessible in 14 mode.
  6. To upgrade the site simply click on “Start now” link on the toolbar, you can also go to SiteUpgrade page from Site Setting page as well.
  7. Click on “TRY A DEMO UPGRADE” link to verify the site collection upgrade (This step can be performed by Site Collection Administrators, farm admins can run
    Request-SPUpgradeEvaluationSiteCollection cmdlet as well).
  8. Provision a temporary site collection to validate the site post-upgrade.
  9. An email should be sent out to Site Collection admin when the temporary site is provisioned.
  10. After validating the temporary site we upgrade the site by going to SiteUpgrade.aspx page and clicking on “Upgrade the Site Collection” button (Farm admins can run Upgrade-SPSite cmdlet as well).
  11. During the upgrade The SiteUpgrade.aspx page shows the progress and provides a link to an upgrade log for troubleshooting purposes.
  12. Your site collection should now be accessible in 15 mode along with all new capabilities enabled in the farm and for the hosting web application such as Social and Office Web Apps.
Note: If there are any reference you manually added to CSS, JS, Images or any other files in your custom solutions which are in Layouts, you need to change the path of these references to point it to 15 hive layout.
e.g.
14 Hive – _/layouts/myPlugin.js
15 Hive – _/layouts/15/myPlugin.js



Sunday 20 March 2016

Send Email Using SMTP Client

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("ToEmailAddress");
message.Subject = "The subject";
message.From = new System.Net.Mail.MailAddress("FromEmailAddress");
message.Body = "Email Body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("Address to your SMPT server");
smtp.Send(message);