0

I'm trying to read task details from a mpp file using net.sf.mpxj library. However, when trying to read custom fields, I get a byte array which I do not know what to do with! It is not the exact value of the custom field from that specific task. Can anyone tell me what to do?

ProjectReader reader = new MPPReader();
ProjectFile project = reader.read(@"C:\EPM\test2.mpp");
foreach (net.sf.mpxj.Task task in project.Tasks)
{
       var Value = task.GetFieldByAlias("My Custom Field Name");
}

The "Value" will be a byte array and I do not know how to get the real value from it.

  • Does this help? [How to convert UTF-8 byte to string](https://stackoverflow.com/questions/1003275/how-to-convert-utf-8-byte-to-string) – Rachel Hettinger Aug 16 '21 at 21:08
  • @RachelHettinger Thanks for your response. I have tried converting that to a string but the thing is that the byte array it returns, is almost all zeros and doesn't have any valid data. – Epm Ticketing System Aug 17 '21 at 04:15

1 Answers1

1

UPDATED ANSWER: As of MPXJ 10.7.0 you can retrieve correctly typed values for enterprise custom fields. You'll also find a CustomFieldDataType attribute as part of the CustomField class which indicates what type you'll be retrieving.

(One interesting "gotcha" is that if your MPP file contains an enterprise custom field which is based on a lookup table, i.e. the user can only select from a fixed set of values, the user-visible text is NOT stored in the MPP file. You'll only get back a GUID representing the value the user has selected. Microsoft Project itself has this same issue... if you open the MPP file when you're not connected to Project Server, these values will appears as blanks...)

ORIGINAL ANSWER: The main problem is unfortunately that MPXJ doesn't currently offer the same level of support for Enterprise Custom Fields as it does for other fields. While it is able to identify Enterprise Custom Fields and the aliases they've been given, at the moment it is only able to read the raw bytes representing the field data.

Enterprise Custom Fields are not as commonly used as other field types so there hasn't been as much time invested in locating the definitions of these fields in the MPP file. The field definition will contain the type information necessary to convert from the raw bytes to the expected data type.

Improved support for Enterprise Custom Fields is on the "to do" list for MPXJ.

Jon Iles
  • 2,519
  • 1
  • 20
  • 30
  • Thanks for your response. Do you know any class library for reading custom fields from mpp files? – Epm Ticketing System Aug 17 '21 at 10:13
  • You could have a look at Aspose Tasks which may have better support for Enterprise Custom Fields. (I'm assuming you're not working with Project Server itself, as Ithe API it exposes would probably provide access) – Jon Iles Aug 17 '21 at 13:19