Free Support Forum - aspose.com

Cannot Read Task Notes field

Hi,

I'm using Aspose.Tasks to write some contents to a Task Notes field, which is then read correctly by MSProject. (see Pic1.png attachment)

However, when I save the project back to an MPP file and read it back using Aspose.Tasks the contents of the Notes field is garbled. (see Pic2.png attachment)

Any ideas?

Thanks,

Jan

Hi,


Aspose.Tasks reads the Notes from MPP in RTF format as MS Project uses to store them in this format in MPP files. Have you tried to parse it as RTF text or just as a plain text?

I'm storing plain text in the Notes field and I'm not changing the notes in MSProject, so I'm expecting the same content back that I put in originally. Are you saying that saving the project in MPP format converts my plain text into RTF and that I need to explicitly convert it back to plain text? How?

Thanks,

Jan

Hi Jan,


Yes, when you open the XML and save it as MPP file MS Project converts text to RTF. More over, this is an encoded RTF, so you can not read it by Aspose.Words directly for example. Now Aspose.Tasks just reads it as a string.

I have created an issue ‘Reading Notes text from MPP files’ with ID=15004 and linked it to this forum thread. We will try fix the issue in this month release (end of March).

Sorry for inconvenience.

Hi Jan,

You can use the method below to extract the text from RTF:

private string GetTextFromMPPNotes(string note)

{

char ch;

int code;

MemoryStream ms = null;

StreamWriter sw = null;

string res;

try

{

ms = new MemoryStream();

sw = new StreamWriter(ms);

for (int i = 0; i < note.Length; i++)

{

code = (int)note[i];

ch = (char)(code & 0xff);

sw.Write(ch);

ch = (char)((code >> 8) & 0xff);

sw.Write(ch);

}

sw.Flush();

ms.Position = 0;

Document doc = new Document(ms);

res = doc.GetText();

}

finally

{

if (sw != null)

sw.Dispose();

if (ms != null)

ms.Dispose();

}

int length = res.Length;

return res.Substring(0, length - 1);

}

To use the method you have to utilize Aspose.Words. The Document class is in Aspose.Words namespace. You can download the last version here (just a dll required).

To get the text just use:

if (task1.Notes != null && task1.Notes.Length > 0)

{

string note = GetTextFromMPPNotes(task1.Notes);

task1.Notes = note;

}

We understand, that it can be a problem if you don’t have Aspose.Words license. We will consider putting the plain text extraction from the RTF in Aspose.Tasks itself. But I have to discuss it with my colleagues, as RTF parsing is an Aspose.Words field.

In case you need to extract more data from the Notes than just a text you have to use Aspose.Words and its license.

Hi Jan,

If you like you can use the method below for the Notes’ RTF parsing:

private string GetTextFromMPPNotes2(string note)

{

char ch;

int code;

StringBuilder sb = new StringBuilder();

for (int i = 0; i < note.Length; i++)

{

code = (int)note[i];

ch = (char)(code & 0xff);

sb.Append(ch);

ch = (char)((code >> 8) & 0xff);

sb.Append(ch);

}

System.Windows.Forms.RichTextBox rtb = new RichTextBox();

rtb.Rtf = sb.ToString();

return rtb.Text;

}

But you can use it only under Windows environment as Windows’ Riched20.dll is required. Call it like the GetTextFromMPPNotes method above.

Let us know if you can not use for some reason any of these samples and the issue is critical to you.

The issues you have found earlier (filed as 15004) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as 16279) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.