Click here to Skip to main content
15,886,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All, I am new to sharepoint 2010 project. When I went through the code, in many places i found SPWeb.AllowUnsafeUpdates property set to true, even when there is no updations in any of the lists. There is some list data fetching is only done. Is this relevant while there is no updation in any of the lists to use AllowUnsafeUpdates to be set to true?
C#
SPWeb thisWeb = workflowProperties.Web;
              thisWeb.AllowUnsafeUpdates = true;
              SPList EmployeeDetails = thisWeb.Lists[BasicEmployeeDetailsList];
              SPList list = workflowProperties.Web.Lists[workflowProperties.List.ID];
              SPListItem compensatoryLeaveItem = workflowProperties.Item;
              DataTable creatermail = new DataTable();
              editurl = workflowProperties.SiteUrl.ToString() + list.DefaultEditFormUrl + "?ID=" + compensatoryLeaveItem["ID"].ToString() + "&Popup=false";
              string EmployeeDetailsID = compensatoryLeaveItem["Created By"].ToString().Substring(compensatoryLeaveItem["Created By"].ToString().IndexOf('#') + 1);
              string listQuery = "<Where><Eq><FieldRef Name='LoginName' /><Value Type='User'>" + EmployeeDetailsID + "</Value></Eq></Where>";
              SPQuery query = new SPQuery();
              query.Query = listQuery;
              SPListItemCollection createrCol = EmployeeDetails.GetItems(query);
              creatermail = createrCol.GetDataTable();
              createdbymail = creatermail.Rows[0][FieldMail].ToString();
              creater = creatermail.Rows[0][FieldFullName].ToString();
              GetHrDetails(thisWeb);
              thisWeb.AllowUnsafeUpdates = false;
Posted
Updated 15-Apr-15 21:10pm
v2

1 solution

AllowUnsafeUpdates is set to true when you are trying to update the database as a result of the GET request.

Say you have a list and you want to update something, then you need to set
AllowUnsafeUpdates = true
for the web and after you have done you need to set it back to false.

So it is not relevant to use AllowUnsafeUpdates option when updating nothing in web.

Read full article here : Why do I need to use AllowUnsafeUpdates?

Hope this helps!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900