title: How to programmatically close a TFS work item
body: <p>I am attempting to import items from a legacy issue tracking system stored in an Excel sheet into Team Foundation Server. I loop through the rows of the Excel file successfully, and I can create new work items, but they are always in the Proposed state. If I attempt to change the state to Closed, then call the Validate method for the work item, I receive a validation error on the State property - InvalidListValue{4}.</p>
  
  <pre><code>    Dim MyProj As Project = store.Projects("MyProject")
      Dim WIT As WorkItemType = MyProj.WorkItemTypes("Task")
      Dim WorkItem As WorkItem = WIT.NewWorkItem()
  
      WorkItem.Title = Title
      WorkItem.Description = Description
      WorkItem.History = History
      WorkItem.State = "Closed"
      WorkItem.Fields("Assigned To").Value = AssignedTo
      WorkItem.Fields("Priority").Value = Priority
      WorkItem.Fields("Closed By").Value = ClosedBy
  </code></pre>
  
  <p>I have also tried the code below, attempting to save the work item, change the State to closed, and save it again, but this doesn't appear to work either - the State is still Proposed when I open it up under the My Work Items TFS query:</p>
  
  <pre><code>        WorkItem.Save()
  
          WorkItem.State = "Closed"
          WorkItem.Fields("Closed By").Value = ClosedBy
          WorkItem.Save()
  </code></pre>
  
  <p>Has anyone else tried such a thing and succeeded, or have ideas for doing it? Oh, and this is a CMMI task that I am trying to create and close. I wonder if I'm trying to skip over certain activities required by CMMI, but I'm new to this, and that's just a guess.</p>