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
<%@ Page Language="vb" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" CodeBehind="ReadProject.aspx.vb" 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
Imports Microsoft.VisualBasic Imports System Imports System.Data Imports System.Configuration Imports System.Collections Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Imports Aspose.Tasks Imports System.IO Namespace Aspose.Tasks.Demos._9 Partial Public Class ReadProject Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) End Sub Protected Sub btn_up_view_Click(ByVal sender As Object, ByVal e As EventArgs) '********* MPP File Upload block [Starts]*************** '''The MPP file name to be read Dim strFile As String = "" '''Upload file to server If Me.FileUpload1.HasFile Then If Me.FileUpload1.FileName.EndsWith(".mpp") Then strFile = Me.FileUpload1.FileName Me.FileUpload1.PostedFile.SaveAs(MapPath(Me.FileUpload1.FileName)) Else '''Write html message and exit Session("outVar") = "<h3>Invalid file</h3>" Return End If Else '////Write html message and exit Session("outVar") = "<h3>No project file</h3>" Return End If '********* MPP File Upload block [Ends]*************** '''Read mpp file from the server Dim rdr As New ProjectReader() Dim prj As Project = rdr.Read(New FileStream(Server.MapPath("") & "\" & strFile,FileMode.Open)) 'Display Tasks Dim alTasks As ArrayList = prj.RootTask.Children Session("outVar") = Session("outVar") & "<h2>Tasks Assigned</h2><br/>" If alTasks.Count > 1 Then 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/>" End If For Each tsk As Task 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 Dim dtStart As DateTime = tsk.Start Session("outVar") = Session("outVar") & "<td>" & dtStart.Month & "/" & dtStart.Day & "</td>" '''Get and Wrtie Task Duration Dim cal As Aspose.Tasks.Calendar = prj.Calendar 'TimeSpan ts = tsk.Duration; Dim dtFinish As DateTime = tsk.Finish Dim dtTemp As DateTime = dtStart Dim durationInDays As Double = 0 Dim ts As TimeSpan Do While dtTemp < dtFinish If cal.IsDayWorking(dtTemp) Then ts = cal.GetWorkingHours(dtTemp) If ts.TotalHours > 0 Then durationInDays = durationInDays + ts.TotalDays * (24 / (ts.TotalHours)) End If End If dtTemp = dtTemp.AddDays(1) Loop Dim strDurValue As String = durationInDays.ToString() & "d" Dim blnTEMP As Boolean = tsk.IsEstimated Dim strEST As String If (blnTEMP) Then strEST = "?" Else strEST = "" End If Dim strDuration As String = 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 Dim alLNK As ArrayList= prj.TaskLinks For Each tsklnk As TaskLink In alLNK If tsklnk.SuccTask.Name = tsk.Name Then Session("outVar") = Session("outVar") & "<td>" & tsklnk.PredTask.Id & "</td>" End If 'else ' Session["outVar"] = Session["outVar"] + "<td>-</td>"; Next tsklnk Session("outVar") = Session("outVar") & "</tr>" Next tsk Session("outVar") = Session("outVar") & "</table>" End Sub End Class End Namespace