Friday, July 24, 2009

What is the difference between SPListItem.SystemUpdate and SPListItem.Update Method (Microsoft.SharePoint)

What is the difference between SPListItem.SystemUpdate and SPListItem.Update Method (Microsoft.SharePoint):

SPListItem.SystemUpdate:

Updates the database(Sharepoint list) with changes that are made to the list item, without effecting changes in the Modified Time or Modified By fields.

SPListItem.SystemUpdate Overloaded Method:

SPListItem.SystemUpdate():
Updates the database with changes made to the list item, without effecting changes in the Modified or Modified By fields.

SPListItem.SystemUpdate(Boolean):
Updates the database with changes that are made to the list item, without effecting changes in the Modified Time or Modified By fields, or optionally, the item version.

Example:

//Take the reference of that item

SPListItem listItem = listItemCOll[icount];

listItem["FIRST_NAME"] = “Amit”;

listItem["LAST_NAME"] = “Kumar”;

listItem["EMAIL_ADDR"] = “mcapassion@gmail.com”;

//Update the Item

listItem.SystemUpdate(false);

The argument false informs the SP object Model not increment versions.



SPListItem.Update:

SPListItem.Update():
Updates the database(Sharepoint list) with changes that are made to the list item/new version of item, and changes in the Modified Time or Modified By fields.


Example:

//Take the reference of that item

SPListItem listItem = listItemCOll[icount];

listItem["FIRST_NAME"] = “Amit”;

listItem["LAST_NAME"] = “Kumar”;

listItem["EMAIL_ADDR"] = “mcapassion@gmail.com”;

//Update the Item

listItem.Update();
Share:

Different between .ToString() and Convert.ToString() in C-Sharp(C#): Convert.ToString() vs .ToString()

I will explain you what is the different between .ToString() and Convert.ToString() with the help of below mentioned code:

int intAmit =0;
Response.write(intAmit.ToString());
Response.write(Convert.ToString(intAmit));

We can convert the integer “intAmit” using “intAmit.ToString()” or “Convert.ToString(intAmit)” ,so what is the basic difference between them:

Convert: function handles NULLS
.ToString(): does not handles NULLS and it will throw a NULL reference exception error.

So as good coding practice is to use “convert” and it is always safe.

Example:

For example you received the data from database in the DataTable. One of the column in datatable is "Amit" and "Amit" column value in some rows of datatable are NULL.

So, when you will try to convert "Amit" column value to string if column value is NULL, with the help of dt.Row[0]["Amit"].ToString() it will throw a NULL reference exception error.

According to me when you need to convert an object to a string and it may be null, you can do it without throwing an exception using Convert.ToString().
Share:

Sitecore® Technology MVP 2019

Featured Post

Sitecore-Front-end performance tuning points

In the previous Sitecore Performance Tuning article, i tried to explain about that Sitecore website performance depends upon Front-end ...

Total Pageviews

State Counter

Popular

About Me

My photo
Based in Bangalore, INDIA, Amit is a Sitecore MVP and MCC. He has an MCA from the U.P.T.U., INDIA and holds certifications including Sitecore and SharePoint 2007/2010. He is an contributor to Sitecore/MSDN communities and http://amitkumarmca04.blogspot.com/. Amit have experience in Sitecore, ASP.Net with C#, MVC, SharePoint, Classic ASP, VB,Macros,HTML,JavaScript,JSON,BootStrap and AngularJS.

Followers

Follow me on Twitter