Tuesday 27 November 2012

Difference between SpListItem.Update and SpListItem.SystemUpdate


To update a list item we have two ways. One of them is SPListitem.Update and its is most popular way. But this method is change version history and trigger all alerts. Some times, some reason you can want to avoid change version history or triggering allerts. Like this case, SpListitem.SystemUpdate medhod help us. Because that SystemUpdate() is not changing version history.
For Example; I have a list name Personel and I want to change secont record by a console application with SPitem.Update method. Before Run this code sample my list item history like this.
 using (SPSite site = new SPSite("http://testsite"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["Personel"];
                    SPListItem item = list.Items[1];
                    item["Title"] = "Sample Update with Versions.";
                    item.Update();
                    list.Update();
                }
            }
After work this Consle Application secont item version history changin like this;
The outher mathod which SystemUpdate() don't add new version history.
using (SPSite site = new SPSite("http://testsite"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["Personel"];
                    SPListItem item = list.Items[1];
                    item["Title"] = "Sample Update with out add Versions";
                    item.SystemUpdate();
                    list.Update();
                }
            }
Finnaly My item history changing but not a new version number.
Download Sample Code : SPSystemUpdate.rar (348.76 kb)

Wednesday 21 November 2012

How to download a WSP file from the Farm Solution Store



---------------------------------------------------------

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

    $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

    $solution = $farm.Solutions["uiframework.wsp"]

    $file = $solution.SolutionFile

    $file.SaveAs(“D:\wsp\uiframework.wsp”)








Default master set using powershell
====================================
$web = Get-SPWeb http://gsshyd-dt-5765:1111/

$web.CustomMasterUrl = "/_catalogs/masterpage/v4.master"

$web.MasterUrl = "/_catalogs/masterpage/v4.master"

$web.Update()