Additional syntax help for Tasks 8.0

I need some additional help with syntax with my migration over to 8.0. The following code worked in the older version ... I need to know what the new syntax would be.

Dim prjWriter As New ProjectWriter()

(it is saying that "the Type ProjectWriter is not defined.)

I have _newProject being the name of my project, and _task as the name of the new task. These statements are not valid.

_task.[Set](Tsk.Duration, _durationTime)
_task.Duration = New TimeSpan(_durationTime, 0, 0)_newProject.NewTasksAreManual = False
Task.Recalculate(_task)

thanks

This is how I was creating the project MPP file .. is there a new way of doing this now in 8.0? Is so .. what is it?

'EXPORT PROJECT .......

Dim varProject As String

Dim varDateTime As Date

varDateTime = CDate(Now)

varProject = "MSProject_" + _customer.ToString + "_" + _description.ToString + "__" + _entered + ".mpp"

Dim prjWriter As New ProjectWriter()

HttpContext.Current.Response.ContentType = "application/vnd.ms-project"

HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + varProject.ToString)

HttpContext.Current.Response.Flush()

Dim strm As System.IO.Stream = HttpContext.Current.Response.OutputStream

prjWriter.Write(_newProject, strm, TasksDataFormat.MPP)

Hi,


The revamped API of Aspose.Tasks for .NET no more contains the ProjectReader and ProjectWriter classes. The functionality of ProjectReader has been replaced by the Project class’s constructor while the functionality of the ProjectWriter is achieved via the Save method of Project class. The following code sample illustrates an example in this regard. Please let us know if we can be of any additional help to you in this regard.

Sample Code:


'Create a new Project. If you want to load from an existing MPP/XML file, pass the

'
file name to the Project constructor as input

'For example, Project project = new Project(“InputXMLorMPPfile”);

Dim project As New Project()


project.[Set](Prj.StartDate, DateTime.Now)


'
new Tasks are manual

project.[Set](Prj.NewTasksAreManual, True)


'Project is scheduled from start

project.[Set](Prj.ScheduleFromStart, True)


'
Add a task

Dim task As Task = project.RootTask.Children.Add(“Task1”)


'Set Task Duration to 8 hours

task.[Set](Tsk.Duration, project.GetDuration(8, TimeUnitType.Hour))


project.Recalculate()


project.Save(“TaskDuration1.xml”, SaveFileFormat.XML)

thank you for your help on this . I am still encountering an issue. We are using servers in which the MPP cannot be saved to .. as such we were using the ProjectWriter and an outputStream logic (see code below). How would we accomplish this now in 8.0?

'EXPORT PROJECT .......

Dim varProject As String

Dim varDateTime As Date

varDateTime = CDate(Now)

varProject = "MSProject_" + _customer.ToString + "_" + _description.ToString + "__" + _entered + ".mpp"

Dim prjWriter As New ProjectWriter()

HttpContext.Current.Response.ContentType = "application/vnd.ms-project"

HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + varProject.ToString)

HttpContext.Current.Response.Flush()

Dim strm As System.IO.Stream = HttpContext.Current.Response.OutputStream

prjWriter.Write(_newProject, strm, TasksDataFormat.MPP)

The Error that I am getting when I use the code listed above is :

"Access to the path 'C:\Program Files(x86)\IIS Express\MSProject_test.Customer3_descriptoin3.mpp' is denied.

We don't allow the end users to write to the directories on the server ... that is why in the old version we used the streaming option ..

How do we do it now?

so what we need is ..

how to use a memory stream instead of writing to a physical file

Hi,

The Project class’s Save method provides an overload version where you can specify instead of physical location. Assuming “project” as the Project class’s variable, you can use the following sample code for saving to stream. Let us know if we can be of any additional help to you in this regard:

Sample Code:


Dim ms As New MemoryStream()


project.Save(ms, SaveFileFormat.MPP)


ms.Position = 0

PS: Please note that when you create a new Project using the Tasks API as "new Project()", it can be saved as XML, but not as MPP. In order to save the project in proper MPP structure, you need to use an empty MPP file as template in the project constructor and then update the same for saving as MPP. Thus, instead of "new Project()", you will have to use "new Project("SomeBlankMPPfile.mpp")".

URGENT... thanks for your email that helped. However, in our situation we are using a MS PRoject template on a protected server, it appears that the code is trying to open the template file for READ/WRITE access and not just READ access. We can't grant the IIS account write access to the file. How do we open the template file as only READ access.

We need to get this out to our customers today.

thanks

Hi,


Well, you can avoid this by loading the file from your server in a stream (see example code for loading project from stream HERE) and then initiating the Project from this stream. The following code sample reads the file in Read-Only mode from the server after which you can load it in the Project constructor. Please have a look at the following code sample for your reference and let us know if we can be of any additional help to you.

Sample Code:


var fs = new FileStream(Server.MapPath(“sample.mpp”,FileMode.Open, FileAccess.Read);

fs.Position = 0;

Project project = new Project(fs);