Retrieving Embedded Documents from a Task's Notes
Contents
[
Hide
Show
]Tasks in a project file may contain embedded documents as its part such as text files or Word documents. Though, Aspose.Tasks doesn’t support retrieving such documents from a task’s notes property in totality, it can be used in combination with Aspose.Words to retrieve and save such documents. This article shows how this can be achieved using Aspose.Tasks and Aspose.Words.
You will need Aspose.Words for .NET to retrieve the documents using NotesRTF property of a task.
Retrieving Embedded Documents from Task Notes
1Project project = new Project("New Project.mpp");
2Task task = project.RootTask.Children.GetById(1);
3
4File.WriteAllText("Notes_out.rtf", task.Get(Tsk.NotesRTF));
5
6Document doc = null;
7using (MemoryStream stream = new MemoryStream())
8using (StreamWriter streamWriter = new StreamWriter(stream))
9{
10 streamWriter.Write(task.Get(Tsk.NotesRTF));
11 doc = new Document(stream);
12}
13
14NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
15foreach (Aspose.Words.Drawing.Shape shape in shapes)
16{
17 if (shape.OleFormat != null)
18 {
19 if (!shape.OleFormat.IsLink)
20 {
21 // Extract OLE Word object
22 if (shape.OleFormat.ProgId == "Word.Document.12")
23 {
24 MemoryStream stream = new MemoryStream();
25 shape.OleFormat.Save(stream);
26
27 Document newDoc = new Document(stream);
28 newDoc.Save("RetrieveTaskEmbeddedDocuments_out.doc");
29 }
30 }
31 }
32}