Is there a method to programmatically add TaskList item to TimeLine web part in SP2013,
I like the functionality, but do not want to user to manually click on 'add to timeline'
or how can i get timeline webpart in custom visual web part in VS 2012
Any ideas?

Akshay NihalaneyPosted Jan 7, 2014, 8:42 PM
The new Timeline control in SharePoint is nice, but Microsoft has no published APIs I know of that let's you add/delete programmatically to/from the timeline.
I had to create workflows that imported the task list from an external system and needed the tasks to be automatically added to the Timeline.
After spending a couple of days trying to find out using fiddler, SQL Profiler and all other tools at my disposal I finally got some clues as I was playing around the "Add to Timeline" and going thru the Request/Response in fiddler.
The Timeline data is actually embedded as properties of the Rootfolder of the Task list. There are 3 properties for the default timeline –
TimelineDefaultView=Timeline
· TimelineAllViews=Timeline*
· Timeline_Timeline=… (see below for sample XML)
The actual data for the timeline is embedded in the "Timeline_Timeline" property as XML. Note that this property has the formatting as well as the Task items included in the timeline.
Once this was determined, it was fairly easy to add new tasks to the timeline by changing this property. In the code below, I am removing the last item from my task list. Similarly you can add items as needed and add more validations as needed.
Sample Code:
XmlDocument doc = new XmlDocument();
projectTaskList = projectSite.Lists["Tasks"];
SPFolder root = projectTaskList.RootFolder;
if (root.Properties["Timeline_Timeline"] != null)
{
doc.LoadXml(root.Properties["Timeline_Timeline"].ToString());
doc.SelectSingleNode("/TLViewData/tskSet").RemoveChild(doc.SelectNodes("/TLViewData/tskSet/t")[doc.SelectNodes("/TLViewData/tskSet/t").Count - 1]);
doc.SelectSingleNode("/TLViewData/mlSet").RemoveChild(doc.SelectNodes("/TLViewData/mlSet/m")[doc.SelectNodes("/TLViewData/mlSet/m").Count - 1]);
root.SetProperty("Timeline_Timeline", doc.OuterXml);
root.Update();
}
Note, the code assumes items in the timeline. Please add your validation logic
Also, note that these properties will be available only after the timeline has at least one task, else these properties will have to be added to the Rootfolder object. In this case you'll have to build the entire Xml including the formatting.
Sample Timeline_Timeline XML -