SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
        SPSite objsite = SPContext.Current.Site;
        using (SPWeb objWeb = SPContext.Current.Web)
            SPList objList = objWeb.Lists["1"];

            foreach (SPListItem item in objList.Items)

                if (item["xyz"] == null)
                    item["xyz"] = "PLEASE SET ME!";  

This workflow working fine but Manually.I want to execute it Automitically.Any Idea.

share|improve this question

You would use an Event Receiver

Use the Item Added or Item Updated events to execute a block of code async when an item is added in SharePoint.

share|improve this answer
This workflow is Site WorkFlow.can You Please Provide Some Code. – Harsh Bhavsar Apr 25 '13 at 12:44
What is the process you do to manually execute it now? – Sam Sussman Apr 25 '13 at 13:01
I want to add "Please set me" to field xyz if xyz is null in list 1. – Harsh Bhavsar Apr 26 '13 at 4:14

Just a small, but very important addition not related directly to your question (as it was already answered by Thantos).

There is an error in your code. You should never dispose SPWeb object obtained from SPContext.Current.Web (you don't need the using operator).

Here is an article about it: Disposing Objects

share|improve this answer
Ya,Thanks.What is the best practice in real scenario? – Harsh Bhavsar Apr 25 '13 at 12:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.