I am trying to read an MS Project File using the .net version of MPJX in C# MVC3. I am using jQuery uploadify to upload the file to my controller.
Now, my problem is how to read the ProjectFile from my HttpPostedFileBase file = Request.Files[0]; I am getting an exception when reading the file because file.FileName doesn't contain the file's full path as part of browser security. If only I was good or at least have knowledge in java then I'd just convert the posted file to java.io.file as it's one of the valid parameters that ProjectReader.read supports.
Below is a code snippet of what I have right now (got the codes from the thread in Example of MPXJ library in C#).
[HttpPost]
public JsonResult UploadTask(int ProjectType)
{
try
{
HttpPostedFileBase file = Request.Files[0];
MpxjReader.ProjectReader mppReader = MpxjReader.ProjectReaderUtility.getProjectReader(file.FileName);
Mpxj.ProjectFile mpp = mppReader.read(file.FileName);
List tables = mpp.getTables();
Iterator iter = tables.iterator();
while (iter.hasNext())
{
MpxjCore.Table table = (MpxjCore.Table)iter.next();
if (table.getResourceFlag())
{
List resources = mpp.getAllResources();
Iterator resourceIter = resources.iterator();
while (resourceIter.hasNext())
{
MpxjCore.Resource resource = (MpxjCore.Resource)iter.next();
List columns = table.getColumns();
Iterator columnIter = columns.iterator();
while (columnIter.hasNext())
{
MpxjCore.Column column = (MpxjCore.Column)columnIter.next();
Object columnValue = resource.getCachedValue(column.getFieldType());
Console.Write(columnValue);
Console.Write(",");
}
Console.WriteLine();
}
}
else
{
List tasks = mpp.getAllTasks();
// etc. as above
}
}
return Json(new { data = "success" }, JsonRequestBehavior.AllowGet);
}
catch
{
return Json(new { data = "error" }, JsonRequestBehavior.AllowGet);
}
}
Any help would be greatly appreciated.
UPDATE: I'VE ALREADY SOLVED THE ISSUE BY SAVING THE .MPP FILE TO A SPECIFIED DIRECTORY FIRST THEN READ FROM THAT DIRECTORY (THIS IS HOW IT SHOULD BEHAVE WHEN DEPLOYED IN THE SERVER).