hari babu gopinathan

Greenhorn
+ Follow
since Jun 08, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by hari babu gopinathan

hi,
at last i was successful in appending a task to mspdi file .This time i had used xml DOM concept, and it was easy.
hi,
updateStructure() doesn't solve the problem.
hi,
can someone help me with the above mentioned code. I need to append the task to a micrososft xml file i.e MSPDI file, but when i do with the above mentioned code, the first appended task gets inserted after the first task in the file. Also when i try to add some different set of tasks, the first set of added tasks gets added again i,e inserted.
[ June 19, 2007: Message edited by: hari babu gopinathan ]
hi,
i was able to append a task to an mpx file but the task was not visible in the MS Project 2003 while opening, i,e Through program if i read the newly added task, i can able to read the new Task. But i was successful with microsoft xml format that is MSPDI.the code which was used is,




import java.io.PrintStream;
import java.text.SimpleDateFormat;
import net.sf.mpxj.*;
import net.sf.mpxj.mpp.MPPReader;
import net.sf.mpxj.mpx.MPXReader;
import net.sf.mpxj.mpx.MPXWriter;
import net.sf.mpxj.mspdi.*;
import net.sf.mpxj.mspdi.MSPDIWriter;
import net.sf.mpxj.utility.NumberUtility;
import net.sf.mpxj.writer.ProjectWriter;

public class CreateXML
{

public CreateXML ()
{
}

public static void main(String args[])
{
try
{
create("d:\\output.XML");
}
catch(Exception ex)
{
ex.printStackTrace(System.out);
}
}

private static ProjectWriter getWriter(String filename)
{
String suffix;
if(filename.length() < 4)
suffix = ".MPX";
else
suffix = filename.substring(filename.length() - 4).toUpperCase();
ProjectWriter result;
if(suffix.equals(".XML"))
result = new MSPDIWriter();
else
result = new MPXWriter();
return result;
}

private static void create(String filename)
throws Exception
{
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
MSPDIReader r=new MSPDIReader();
ProjectFile file=r.read("d:\\input.XML");

file.setAutoTaskID(true);
file.setAutoTaskUniqueID(true);
file.setAutoResourceID(true);
file.setAutoResourceUniqueID(true);
file.setAutoOutlineLevel(true);
file.setAutoOutlineNumber(true);
file.setAutoWBS(true);
file.setAutoCalendarUniqueID(true);

ProjectCalendar calendar = file.addDefaultBaseCalendar();
ProjectCalendarException exception = calendar.addCalendarException();
exception.setFromDate(df.parse("13/06/2007"));
exception.setToDate(df.parse("13/06/2007"));
exception.setWorking(false);
ProjectHeader header = file.getProjectHeader();
header.setStartDate(df.parse("1/06/2007"));
Resource resource1 = file.addResource();
resource1.setName("Resource1");
Resource resource2 = file.addResource();
resource2.setName("Resource2");
resource2.setMaxUnits(new Double(50D));



Task task1 = file.addTask();
task1.setName("Main Task2");
task1.setStart(df.parse("12/07/2007"));
task1.setDuration(Duration.getInstance(100D, TimeUnit.DAYS));

Task task2 = task1.addTask();
task2.setName("T13");
task2.setDuration(Duration.getInstance(5, TimeUnit.DAYS));
task2.setStart(df.parse("6/10/2007"));
task2.setPercentageComplete(NumberUtility.getDouble(50D));

ProjectWriter writer = getWriter(filename);
writer.write(file, filename);
}
}



But with the above code, The new task is not appending in the proper Order..
MPX file is Microsoft Project Exchange and MPXJ is the class used to handle this file in java.
hi,
i need to read from a mpx file, append a new task or insert a new task and write it back to the mpx file. I am able to read from the mpx file and write it as such. But i am not able to append or insert a new task and write it back to the mpx file. Can someone help me with the code to the above mentioned task.

Hari