I have created simple sequential workflow in visual studio with one application page(which has 3 buttons like Approve,Reject & Close buttons) for editing the task. i deployed it to site collection on (http://8888).it works as i want.

but when i deployed it to other site collection eg (http://8888/sites/mysite) then the Taskitem.Update() line throw an error,

I have also created two same lists (Request List and Task List with same name and fields) on : //8888/sites/mysite

protected void btnApprove_Click(object sender, EventArgs e)
            string siteurl = SPContext.Current.Web.Url.ToString();
            using (SPSite site = new SPSite(siteurl))
                using (SPWeb web = site.OpenWeb())
                    if (Request.QueryString["ID"] != string.Empty && Request.QueryString["ID"] != null)
                        web.AllowUnsafeUpdates = true;                            
                        SPList Tasklist = web.Lists["MyWorkflowTasks"];
                        int id = Convert.ToInt32(Request.QueryString["ID"]);
                        SPListItem Taskitem= Tasklist .GetItemById(id);                            
                        Taskitem["Status"] = "Completed";
                        Taskitem["RequestStatus"] = "Approved";
                        Taskitem.Update();// this line throw error : spexception was unhandled by user code 
                        web.AllowUnsafeUpdates = false;                            
                        this.Context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");

Remember above code works fine on my first site collection but not on other as described above.

can anyone know why this happens?

  • Are you sure the task with ID which you are passing exists in mysite ? – Asad Refai Jul 22 '15 at 11:01
  • yes, this task item is exist in my Task list. and while debugging i also able to see its all fields and values by QuickWatch. – SP Developer Jul 22 '15 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.