I'm trying to view and edit Tasks on a mpp file using mpxj on c#. I wrote some lines and tring to write a file that is already complete adding a new Task.
But when the code arrives to the write part, it create the file in the path I meant but the file is empty and if I try to read that file it give me the System.NullReferenceException : Object reference not set to an instance of an object error. It's the first time code with this mpxj library.
ProjectReader reader = new MPPReader();
ProjectWriter writer = new MPXWriter();
private ProjectFile project;
public ProjectFile OpenReaderProject()
{
string filePath = "Files/Prova file1.mpp";
try
{
project = reader.read(filePath);
}
catch (MPXJException ex)
{
Console.WriteLine("Errore durante l'apertura del file .mpp: " + ex.Message);
}
return project;
}
public ProjectFile OpenWriterProject()
{
string filePath = "Files/Prova file1.mpp";
try
{
writer.write(project, filePath);
}
catch (MPXJException ex)
{
Console.WriteLine("Errore durante la scrittura del file .mpp: " + ex.Message);
}
return project;
}
This is the write and reading part.
public void AddTask()
{
var project = OpenReaderProject();
var task = project.addTask();
task.setName(java.lang.String.valueOf("Attività di esempio"));
var taskDto = _mapper.Map<TaskDto>(task);
OpenWriterProject();
}`
This is the add task function and calling the OpenWriterProject. What's wrong with it? Feel free to answer me ;) Thanks