Saturday 26 April 2014

SHarePoint List item Update using ArrayList

UpdateSharepoint List using ArrayList
public void (ArrayList objArrayList, string ListItemID)
{
//WindowsIdentity objWindowsIdentity = WindowsIdentity.GetCurrent();
//RevertToSelf();
SPSite siteCollection = null;
SPWeb topLevelSite = null;
SPList list = null;
SPListItem objListItem = null;
try
{
if (objArrayList != null && objArrayList.Count > 0)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
siteCollection = new SPSite(System.Configuration.ConfigurationManager.AppSettings["SPDocumentLibrary"].ToString());
topLevelSite = siteCollection.AllWebs[ConfigurationManager.AppSettings["TopLevelSite"].ToString()];
});
topLevelSite.AllowUnsafeUpdates = true;
list = topLevelSite.Lists[System.Configuration.ConfigurationManager.AppSettings["ListName"]];
siteCollection.OpenWeb();
siteCollection.AllowUnsafeUpdates = true;
topLevelSite.AllowUnsafeUpdates = true;
objListItem = list.GetItemById(Convert.ToInt32(ListItemID.Trim()));
string[] myStringArray = (string[])objArrayList.ToArray(typeof(string));
for (int i = 0; i < myStringArray.Length; i++)
{
string[] strNameValue = myStringArray[i].Split(';');
objListItem[strNameValue[0]] = strNameValue[1];
}
objListItem.Update();
}
}
catch (Exception ex)
{
throw new Exception(ex.StackTrace);
}
finally
{
topLevelSite.AllowUnsafeUpdates = false;
siteCollection.AllowUnsafeUpdates = false;
siteCollection.Dispose();
topLevelSite.Dispose();
objListItem = null;
list = null;
topLevelSite = null;
siteCollection = null;
}
}