Retrieving Embedded Documents from a Task's Notes
Overview
In Microsoft Project files (MPP), task notes can contain embedded documents — such as .txt
, .doc
, or .rtf
files. These embedded objects are typically stored in RTF format within the task’s NotesRTF
property.
While Aspose.Tasks for .NET alone does not fully support parsing or extracting these embedded documents, it can be combined with Aspose.Words for .NET to interpret the RTF content and retrieve the embedded files.
This article demonstrates how to read the NotesRTF
data from a task and extract embedded documents using Aspose.Words.
Requirements
Before you proceed, make sure to:
- Reference Aspose.Tasks for .NET to access task data;
- Reference Aspose.Words for .NET to parse and save embedded objects from RTF content.
You can install both libraries via NuGet:
1Install-Package Aspose.Tasks
2Install-Package Aspose.Words
Retrieving Embedded Documents from Task Notes
The following code snippet:
- Loads the MPP file using
Aspose.Tasks
; - Reads the
NotesRTF
content of each task; - Parses RTF using
Aspose.Words
; - Saves each embedded object (if found) to disk.
✅ Code Example
{{<section “code-snippet” i18n-exclude>}}
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}
Notes
- The output files will preserve their original format and filename if available;
- Only RTF-based notes with embedded OLE objects can be processed;
- Make sure to handle exceptions when parsing unsupported or malformed RTF.
Summary
By combining Aspose.Tasks and Aspose.Words, developers can extract embedded documents from task notes stored in MPP files. This approach is especially useful when MPP files are used to carry additional specifications or attachments via the Notes field.