How to move an application to a folder programmatically


  
 Prerequisites
  1.  Add AdminUI.WqlQueryEngine.dll as a reference
    
  2.  Get the ContainerID of a folder by querying SMS_ObjectContainerNode WMI Class with ObjectType = 6000 (6000 indicates Application).
    
  3.  Model Name of the application by querying ModelName from SMS_ApplicationLatest WMI Class 
    
  
 Solution
 Call MoveMembers method on SMS_ObjectContainerItem method by specifying InstanceKeys as the modelname of the application, ContainerNodeID is the containerID where the application is stored( By Default all applications are stored at 0).
 ObjectType indicates the type of the object. In this case, it is application 
  
 The same method can be used to move packages, Configuration Items, UserCollection etc.
  
 Sample Code:  
  

WqlConnectionManagerconnectionManager = new WqlConnectionManager();

connectionManager.Connect("MySiteServer");

 try

 {

 Dictionary<string, object> parameters =new Dictionary<string, object>();

 string[] sourceItems = new string[1];

 

 // Only one item is being moved, the arraysize is 1.

 sourceItems[0]="ScopeId_E57E2598-FBB0-4A20-8E35-FE284072C7F9/Application_9bcacf78-9fdf-41b1-8978-42ed2de2ffa8";

 parameters.Add("InstanceKeys",sourceItems);

 parameters.Add("ContainerNodeID",0);

 parameters.Add("TargetContainerNodeID",16777217);

 parameters.Add("ObjectType", 6000);

 connectionManager.ExecuteMethod("SMS_ObjectContainerItem","MoveMembers", parameters);

 }

  
  
  
  
 Thanks
 Sreekar Mankala