1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<%@ Page Language="C#" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" CodeBehind="ReadProject.aspx.cs" Inherits="Aspose.Tasks.Demos._9.ReadProject" Title="Read Project" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <table width="90%" align="center" cellspacing="0" cellpadding="0" border="0"> <tr> <td height="41" valign="top"> <img src="/Common/images/heading_lft.jpg" width="19" height="41" /></td> <td width="100%" class="demos-heading-bg"> <h2 class="demos-heading-bg"> Reading an MPP Project Files - Aspose.Tasks for .NET</h2> </td> <td valign="top"> <img src="/Common/images/heading_rt.jpg" width="19" height="41" /></td> </tr> </table> Please browse a valid mpp project file and press 'Upload and View' button to upload file to server so that Aspose.Tasks reads and displays tasks. <br /> <br /> <asp:FileUpload ID="FileUpload1" runat="server" /><br /> <br /> <asp:Button ID="btn_up_view" runat="server" Text="Upload and View" OnClick="btn_up_view_Click" /> <br/> <%=Session["outvar"] %> <% Session["outvar"] = ""; %> </asp:Content>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Aspose.Tasks; using System.IO; namespace Aspose.Tasks.Demos._9 { public partial class ReadProject : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btn_up_view_Click(object sender, EventArgs e) { /********** MPP File Upload block [Starts]****************/ ///The MPP file name to be read string strFile = ""; ///Upload file to server if (this.FileUpload1.HasFile) { if (this.FileUpload1.FileName.EndsWith(".mpp")) { strFile = this.FileUpload1.FileName; this.FileUpload1.PostedFile.SaveAs(MapPath(this.FileUpload1.FileName)); } else { ///Write html message and exit Session["outVar"] = "<h3>Invalid file</h3>"; return; } } else { //////Write html message and exit Session["outVar"] = "<h3>No project file</h3>"; return; } /********** MPP File Upload block [Ends]****************/ ///Read mpp file from the server ProjectReader rdr = new ProjectReader(); Project prj = rdr.Read(new FileStream(Server.MapPath("") + "\\" + strFile,FileMode.Open)); //Display Tasks ArrayList alTasks = prj.RootTask.Children; Session["outVar"] = Session["outVar"] + "<h2>Tasks Assigned</h2><br/>"; if (alTasks.Count > 1) Session["outVar"] = Session["outVar"] + "<table border=1><tr bgcolor=blue><td><font color=white>Task ID</font></td><td><font color=white>Task Name</font></td><td><font color=white>Start Date(mm/dd)</font></td><td><font color=white>Task Duration</font></td><td><font color=white>End Date(mm/dd)</font></td><td><font color=white>Predecessor</font></td></tr>"; else Session["outVar"] = Session["outVar"] + "<h3>No Tasks Found...</h3><br/>"; foreach (Task tsk in alTasks) { Session["outVar"] = Session["outVar"] + "<tr>"; ///Get and Write Task ID Session["outVar"] = Session["outVar"] + "<td>" + tsk.Id + "</td>"; ///Get and Wrtie Task Name Session["outVar"] = Session["outVar"] + "<td>" + tsk.Name + "</td>"; ///Get and Wrtie Task Start Date DateTime dtStart = tsk.Start; Session["outVar"] = Session["outVar"] + "<td>" + dtStart.Month + "/" + dtStart.Day + "</td>"; ///Get and Wrtie Task Duration Aspose.Tasks.Calendar cal = prj.Calendar; //TimeSpan ts = tsk.Duration; DateTime dtFinish = tsk.Finish; DateTime dtTemp = dtStart; double durationInDays = 0; TimeSpan ts; while (dtTemp < dtFinish) { if (cal.IsDayWorking(dtTemp)) { ts = cal.GetWorkingHours(dtTemp); if (ts.TotalHours > 0) durationInDays = durationInDays + ts.TotalDays * (24 / (ts.TotalHours)); } dtTemp = dtTemp.AddDays(1); } string strDurValue = durationInDays.ToString() + "d"; bool blnTEMP = tsk.IsEstimated; string strEST; strEST = (blnTEMP) ? "?" : ""; string strDuration = strDurValue + strEST; Session["outVar"] = Session["outVar"] + "<td>" + strDuration + "</td>"; ///Get and Write Task End Date Session["outVar"] = Session["outVar"] + "<td>" + dtFinish.Month.ToString() + "/" + dtFinish.Day.ToString() + "</td>"; ///Get and Write Task Predecessor ArrayList alLNK= prj.TaskLinks; foreach( TaskLink tsklnk in alLNK ) { if(tsklnk.SuccTask.Name == tsk.Name ) Session["outVar"] = Session["outVar"] + "<td>" + tsklnk.PredTask.Id + "</td>"; //else // Session["outVar"] = Session["outVar"] + "<td>-</td>"; } Session["outVar"] = Session["outVar"] + "</tr>"; } Session["outVar"] = Session["outVar"] + "</table>"; } } }