This project has moved and is read-only. For the latest updates, please go here.

Deserialize Task Xml

Topics: Examples
Aug 31, 2015 at 2:01 PM
Is there any way to deserialize the Task XML of the created task using wrapper ? I'm actually working on an application, developed with C#.

Does Task Definition contains some kind of property or method which would help me to do this ?


Thanks In Advance
Aug 31, 2015 at 5:44 PM
Edited Aug 31, 2015 at 5:44 PM
First you must have XML in the right format. This can be done via the library by capturing the output from an existing task via the Task.Xml property or by calling the task's Export method. If the task doesn't already exist, build up the TaskDefinition as outlined in the documentation and then capture the TaskDefinition instance's XmlText property. Note that all these suggestions return Xml using the schema defined by Microsoft for tasks.

Once you have the properly formatted Xml, you can create tasks by:
  1. Call the TaskService instance's NewTaskFromFile method passing the file path and then registering the returned TaskDefintion.
  2. Get an instance to the TaskFolder in which you want to create the task and call its RegisterTask method passing in the xml (not the file) as the second parameter.
  3. Get an instance to the TaskFolder in which you want to create the task and call its ImportTask method passing in the xml file path as the second parameter.
Marked as answer by dahall on 9/1/2015 at 9:26 AM
Sep 1, 2015 at 6:10 AM
@dahall: Thanks for the reply.
But I don't want to create tasks using the XML. I have created a task and stored its Xml(using Task.Xml) in a sql db. I am retrieving this XML.
So, now the problem is that I want to deserialize this XML. So is there any method provided by the wrapper to deserialize this XML ?

Thanks again
Sep 1, 2015 at 5:26 PM
Yes, step 1 above will accomplish what you are asking. It only creates a TaskDefinition and does not register it.
Marked as answer by dahall on 9/1/2015 at 9:26 AM
Sep 1, 2015 at 9:38 PM
Okay. And will it work with the Tasks present on some remote machine in my domain ? I mean I am able to create tasks on the remote machines, so how I do make sure that the tasks with their XML (on remote machines) can be deserialized as well ?
Thanks for replying and taking time to solve all the queries .
Really appreciate it
Sep 2, 2015 at 3:36 PM
It will work as long as the XML have extracted complies with all the versions of Windows in your environment. You can do a few things to ensure this:
  1. Use the Task Scheduler applet from Windows on the oldest version of Windows in the environment to export the XML for your task.
  2. Use the same applet on any version, but make sure the OS selected on the first tab is the oldest in your environment.
  3. In the library, use the TaskDefintion's LowestSupportedVersion to confirm it complies or use the Validate method to get a list of reasons it doesn't.
Marked as answer by dahall on 9/2/2015 at 7:36 AM