This project has moved. For the latest updates, please go here.

Export... but no import?

Topics: Setup
May 9, 2014 at 8:46 PM
Is it possible to import a task from xml?

Maybe i just missed something in the documentation and the code but i didn't see the word "import" anywhere.

help?
Coordinator
May 10, 2014 at 5:46 PM
Yes. There are actually a few ways:

1) As a file, you can pass the filename to the ImportTask method on the instantiated TaskFolder object of the task's destination.
using (TaskService ts = new TaskService())
   ts.RootFolder.ImportTask("TaskName", @"C:\temp\task.xml");
2) As a string, you have a few options:
string myTaskXml = "<(blah blah blah)>...";
using (TaskService ts = new TaskService())
{
   // First option is straight to registration using current user.
   // You can also supply parameters to register under a different user
   ts.RootFolder.RegisterTask("TaskName", myTaskXml);

   // You can also feed the XML to a task definition and even change it before registering it
   TaskDefinition td = ts.NewTask();
   td.XmlText = myTaskXml;
   td.RegistrationInfo.Description = "Update description";
   ts.RootFolder.RegisterTaskDefinition("Test", td);
}
Marked as answer by dahall on 5/10/2014 at 7:36 PM
May 10, 2014 at 6:34 PM
Excellent response! I will try this when i get back to work