2015-12-18 69 views
0

我有ac#對象具有ProjectInfo隨着ProjectTasks,現在如何將這些projectTasks添加到'net.sf.mpxj 。任務'在C#如何將項目任務詳細信息列表添加到'net.sf.mpxj.Task任務'在C#

雖然我爲net.sf.mpxj.Task創建新的對象,然後它顯示錯誤'net.sf.mpxj.Task類型沒有構造函數定義',所以它不能創建新的對象,那麼我如何添加projectTasks。

下面是它不工作的示例代碼:

 List<net.sf.mpxj.Task> tasks=new List<net.sf.mpxj.Task>(); 

      foreach (var pTask in projectInfo.ProjectTasks) 
      { 

       net.sf.mpxj.Task task = new net.sf.mpxj.Task(); 

         task.TaskId=ptask.TaskId; 
         task.Name = pTask.TaskName; 
         task.Notes = pTask.Description; 
         task.Start=pTask.EstimatedStartDate.ToJavaDate(); 
         task.Finish = pTask.EstimatedEndDate.ToJavaDate(); 
         task.Estimated = true; 
         task.Priority = null; 
         task.Type = null; 

        tasks.Add(task); 

      } 

在此先感謝。

回答

0

沒有創建MPXJ對象正確。請按照以下代碼創建MPXJ任務。這裏我正在創建MS Project的XML格式的MSPDI文件。

ProjectFile project = new ProjectFile(); 

    foreach (var pTask in projectInfo.ProjectTasks) 
    { 
     Task task = project.AddTask(); 
     task.Name = pTask.TaskName; 
     task.Notes = pTask.Description; 
     task.Start=pTask.EstimatedStartDate.ToJavaDate(); 
     task.Finish = pTask.EstimatedEndDate.ToJavaDate(); 
     task.Estimated = true; 
     task.Priority = null; 
     task.Type = null; 
    } 

    TaskContainer taskCon = project.AllTasks; 
    if (taskCon.Size() >= 1) 
    { 
     java.io.OutputStream outs = null; 
     try 
     { 
      // string serverPath = Server.MapPath(fileName); 
      if (System.IO.File.Exists(fullFileName)) 
      { 
       System.IO.File.Delete(fullFileName); 
      } 
      MSPDIWriter writer = new MSPDIWriter(); 
      outs = new java.io.FileOutputStream(fullFileName); 
      writer.Write(project, outs); 
      outs.close(); 

      if (System.IO.File.Exists(fullFileName)) 
      { 
       string fileName = "ProjectTask.xml"; 
       WebClient client = new WebClient(); 
       HttpResponse response = HttpContext.Current.Response; 
       response.Clear(); 
       response.ClearContent(); 
       response.ClearHeaders(); 
       response.Buffer = true; 
       response.ContentType = "Application/msproject"; 
       response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\""); 
       byte[] data = client.DownloadData(fullFileName); 
       response.BinaryWrite(data); 
       Response.End(); 
      } 
     } 
     catch (System.Exception ex) 
     { 

     } 
     finally 
     { 
      if (outs != null) 
      outs.close(); 
     } 
    } 

我做了很好的研究。請讓我知道如果需要更多的幫助。

相關問題