protected void UpdateName()
{
DateTime issueDate = new DateTime();
if (SPContext.Current != null)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
writeFile = new StreamWriter("c:\\<foldrname>\\" + "test.txt");
textlogwirte(Sb.AppendLine("Update Strarted" + System.DateTime.Now.ToLongTimeString()));
using(SPSite elevatedSite = new SPSite(SPContext.Current.Web.Url))
{
using(SPWeb oWebsite = elevatedSite.OpenWeb())
{
SPQuery oQuery = new SPQuery();
string where = "<Where><IsNotNull><FieldRef Name='fieldName'></FieldRef></IsNotNull></Where>";
oQuery.Query = where;
if (txtSPQuery.Text.Length > 0)
{
oQuery.Query = txtSPQuery.Text;
}
int numItms = 0;
string listname = "Library Display Name";
//foreach (string listname in libraryName)
//{
Sb.Clear();
Sb.AppendLine("List Name :" + listname.ToString());
oWebsite.AllowUnsafeUpdates = true;
try
{
SPList oList = oWebsite.Lists.TryGetList(listname);
if (oList != null)
{
// if we update single or coupld of fileds you can use
// if (oList.Fields.ContainsField("filedinternalname")) this comments before after the loop start.
oQuery.ViewFields = "<FieldRef Name=\"FileRef\" />";
oQuery.ViewFields += @ "<FieldRef Name='field1' Nullable='TRUE' />";
oQuery.ViewFields += @ "<FieldRef Name='field1' Nullable='TRUE' />";
oQuery.ViewAttributes = "Scope=\"Recursive\"";
oQuery.RowLimit = 50;
int intIndex = 1;
do {
SPListItemCollection collListItems = oList.GetItems(oQuery);
foreach(SPListItem curItm in collListItems)
{
if (curItm.File.CheckOutType == Microsoft.SharePoint.SPFile.SPCheckOutType.None)
{
if (curItm["IssueDate"] != null)
{
Dateupdate = DateTime.Parse(curItm["fiedlsname"].ToString(), null, DateTimeStyles.None);
curItm["fieldname"] = Dateupdate;
}
curItm["fieldname"] = "XXXXXXXX";
curItm["fieldname"] = "xxx";
try
{
curItm.SystemUpdate(false);
numItms++;
}
catch (Exception ex)
{}
}
}
oQuery.ListItemCollectionPosition = collListItems.ListItemCollectionPosition;
intIndex++;
}
while (oQuery.ListItemCollectionPosition != null);
oWebsite.AllowUnsafeUpdates = false;
Sb.AppendLine("List Name :" + listname.ToString() + intIndex);
}
//list object null check
else
{
//log error msg }
}
catch (Exception ex)
{
Sb.AppendLine(ex.Message.ToString());
textlogwirte(Sb);
Sb.Clear();
}
//if list is not available.. try catch end
Sb.AppendLine("List Name :" + listname.ToString() + "-- update end ---");
textlogwirte(Sb);
Sb.Clear();
//} //for loop
Sb.AppendLine("Update process completed" + System.DateTime.Now.ToLongTimeString());
textlogwirte(Sb);
writeFile.Close();
writeFile = null;
lblMsg.Text = "There were " + numItms.ToString() + " item(s) updated";
}
//spweb
}
});
}
catch (Exception ex)
{
Sb.AppendLine(ex.Message.ToString());
textlogwirte(Sb);
Sb.Clear();
}
}
else
{
Sb.AppendLine("SP context Null");
textlogwirte(Sb);
Sb.Clear();
}
}
}This code snippet for SharePoint Update All Item In Library Not Update Version And Modified Date SSOM.