Project

Project()

Initializes a new instance of the Project class.

public Project()

Examples

Shows how to create a project and save it into MPP format without passing of an MPP template file.

var project = new Project();

// The project will be saved into MPP by using internal MPP template.
project.Save(OutDir + "CreateEmptyProjectSaveMPP_out.mpp", SaveFileFormat.Mpp);

See Also


Project(string, string)

Initializes a new instance of the Project class from a password protected template (existent mpp or mpt file).

public Project(string projectTemplate, string protectionPassword)
ParameterTypeDescription
projectTemplateStringPath to template to create project from.
protectionPasswordStringProtection password.

Remarks

Reading password protected files currently supported for MSP 2003 file format only.

Examples

Shows how to read password protected MPP files.

var project = new Project(DataDir + "PasswordProtectedProject.mpp", "password");
Console.WriteLine(project.Get(Prj.Name));

See Also


Project(string)

Initializes a new instance of the Project class from a template (existent mpp or mpt file).

public Project(string projectTemplate)
ParameterTypeDescription
projectTemplateStringPath to template to create project from.

Examples

Shows how to read a MPP file.

var project = new Project(DataDir + "ReadProjectFiles.mpp");
project.Save(OutDir + "ReadProjectFiles_out.mpp", SaveFileFormat.Xml);

See Also


Project(Stream, PrimaveraReadOptions)

Initializes a new instance of the Project class from the Stream with the specified instance of the PrimaveraReadOptions class.

public Project(Stream stream, PrimaveraReadOptions options)
ParameterTypeDescription
streamStreamStream of the Project Streamclass
optionsPrimaveraReadOptionsthe specified instance of the PrimaveraReadOptionsclass which allows to customize reading of Primavera formats (XER or XML).

Examples

Shows how to read a project from a stream with Primavera XML or Primavera XER file containing multiple projects.

var options = new PrimaveraReadOptions
{
    ProjectUid = 4557
};
using (var stream = new FileStream(DataDir + "Project.xml", FileMode.Open, FileAccess.Read))
{
    // Returns project with special Uid
    var project = new Project(stream, options);
    Console.WriteLine(project.Get(Prj.Name));
}

See Also


Project(string, ParseErrorCallback)

Initializes a new instance of the Project class from a template (existent mpp or mpt file).

public Project(string projectTemplate, ParseErrorCallback parseErrorHandler)
ParameterTypeDescription
projectTemplateStringPath to template to create project from.
parseErrorHandlerParseErrorCallbackthe specified callback method to handle xml parse errors.

Examples

Shows how to read a project from a stream with XML file with invalid characters.

public static void LoadProjectFromFile(string pathToModifiedXml)
{
    // open the file which contains XML with broken timespans
    var project = new Project(pathToModifiedXml, CustomDurationHandlerForFile2);
    Console.WriteLine(project.Get(Prj.Name));
}

public static object CustomDurationHandlerForFile2(object sender, ParseErrorArgs args)
{
    var regex = new Regex("[*]{2}(\\d+)Hrs(\\d+)Mins(\\d+)Secs[*]{2}");
    if (args.FieldType != typeof(TimeSpan))
    {
        throw args.Exception;
    }

    Console.WriteLine("Object field: {0}, Object field type: {1}, Invalid value: {2}", args.FieldName, args.FieldType, args.InvalidValue);
    var duration = regex.Replace(args.InvalidValue, "PT$1H$2M$3S");
    var newValue = Duration.ParseTimeSpan(duration);
    Console.WriteLine("New value : {0}", newValue);
    return newValue;
}

See Also


Project(Stream)

Initializes a new instance of the Project class from a stream.

public Project(Stream stream)
ParameterTypeDescription
streamStreamStream to load a template from.

Examples

Shows how to read XML project file from a stream.

using (Stream stream = new FileStream(DataDir + "Project.xml", FileMode.Open))
{
    var project = new Project(stream);
    project.Save(OutDir + "ReadProjectFileFromStream_out.xml", SaveFileFormat.Xml);
}

See Also


Project(StreamReader)

Initializes a new instance of the Project class from a StreamReader instance.

public Project(StreamReader reader)
ParameterTypeDescription
readerStreamReaderThe stream reader where to load a template from.

Examples

Shows how to read MPX files with specific encoding.

using (var streamReader = new StreamReader(DataDir + "EUC-KR-encoding.mpx", System.Text.Encoding.GetEncoding("ISO-8859-1")))
{
    var project = new Project(streamReader);
    Console.WriteLine(project.RootTask.Children.ToList()[0].Get(Tsk.Name));
    project.Save(OutDir + "WorkingWithEncodings_out.mpx", SaveFileFormat.Mpx);
}

See Also


Project(string, PrimaveraReadOptions)

Initializes a new instance of the Project class from a template (existent MPP or MPT file) with the specified instance of the PrimaveraReadOptions class.

public Project(string projectTemplate, PrimaveraReadOptions options)
ParameterTypeDescription
projectTemplateStringPath to template to create project from
optionsPrimaveraReadOptionsthe specified instance of the PrimaveraReadOptions class.

Examples

Shows how to read a project from a Primavera XML or Primavera XER file containing multiple projects by using Primavera reading options.

var options = new PrimaveraReadOptions()
{
    ProjectUid = 4557
};

// Returns project with special Uid
var project = new Project(DataDir + "Project.xml", options);
Console.WriteLine(project.Get(Prj.Name));

See Also


Project(DbSettings)

Initializes a new instance of the Project class to read data from a database which is specified by the instance of the DbSettings class.

public Project(DbSettings settings)
ParameterTypeDescription
settingsDbSettingsthe specified instance of the DbSettings class.

Examples

Shows how to import a project from a Primavera database by using database settings.

var sb = new SqlConnectionStringBuilder
{
    DataSource = "192.168.56.3,1433",
    Encrypt = true,
    TrustServerCertificate = true,
    InitialCatalog = "PrimaveraEDB",
    NetworkLibrary = "DBMSSOCN",
    UserID = "privuser",
    Password = "***",
};

// Initialize a new instance of the PrimaveraDbSettings class with connection string and project id
var settings = new PrimaveraDbSettings(sb.ConnectionString, 4502);

// Initialize a new instance of the Project class
var project = new Project(settings);
Console.WriteLine(project.Get(Prj.Name));

See Also


Project(Stream, ParseErrorCallback)

Initializes a new instance of the Project class from a template(existent mpp or mpt file).

public Project(Stream stream, ParseErrorCallback parseErrorHandler)
ParameterTypeDescription
streamStreamStream to load a template from.
parseErrorHandlerParseErrorCallbackthe specified callback method to handle xml parse errors.

Examples

Shows how to read a project from XML file with invalid characters.

public static void LoadProjectFromStream(string brokenXmlData)
{
    // open the stream which contains XML with broken timespans
    byte[] bytes = Encoding.UTF8.GetBytes(brokenXmlData);
    using (var stream = new MemoryStream(bytes))
    {
        var project = new Project(stream, CustomDurationHandlerForStream2);
        Console.WriteLine(project.Get(Prj.Name));
    }
}

public static object CustomDurationHandlerForStream2(object sender, ParseErrorArgs args)
{
    var regex = new Regex("[*]{2}(\\d+)Hrs(\\d+)Mins(\\d+)Secs[*]{2}");
    if (args.FieldType != typeof(TimeSpan))
    {
        throw args.Exception;
    }

    Debug.Print("Object field : {0}, Invalid value : {1}", args.FieldName, args.InvalidValue);
    var duration = regex.Replace(args.InvalidValue, "PT$1H$2M$3S");
    var newValue = Duration.ParseTimeSpan(duration);
    Debug.Print("New value : {0}", newValue);
    return newValue;
}

See Also


Project(Stream, string)

Initializes a new instance of the Project class from a template(existent mpp or mpt file).

public Project(Stream stream, string protectionPassword)
ParameterTypeDescription
streamStreamStream to load a template from.
protectionPasswordStringProtection password.

Remarks

Reading password protected files currently supported for MSP 2003 file format only.

Examples

Shows how to check if MPP is password protected.

var info = Project.GetProjectFileInfo(DataDir + "PasswordProtected.mpp");
Console.WriteLine("Is file password protected?:" + info.IsPasswordProtected);

Shows how to read password protected MPP files from a stream.

using (var stream = new FileStream(DataDir + "PasswordProtectedProject.mpp", FileMode.Open))
{
    var project = new Project(stream, "password");
    Console.WriteLine(project.Get(Prj.Name));
}

See Also


Project(string, LoadOptions)

Initializes a new instance of the Project class from a template (existent mpp or mpt file) with the specified instance of the LoadOptions class.

public Project(string projectTemplate, LoadOptions options)
ParameterTypeDescription
projectTemplateStringPath to template to create project from
optionsLoadOptionsthe specified instance of the LoadOptions class.

Examples

Shows how to load the project from a file by using <see cref=“Aspose.Tasks.LoadOptions”/> instance.

var options = new LoadOptions
{
    Password = "password"
};
var project = new Project(DataDir + "PasswordProtectedProject.mpp", options);
Console.WriteLine(project.Get(Prj.Name));

Shows how to read a project from a Primavera XML file with error parsing.

var options = new PrimaveraReadOptions
{
    ProjectUid = 4557
};

var loadOptions = new LoadOptions()
{
    PrimaveraReadOptions = options,
    ErrorHandler = CustomDurationHandlerForFile
};

// Returns project with special Uid
var project = new Project(OutDir + "IgnoreInvalidCharacters_out.xml", loadOptions);
Console.WriteLine(project.Get(Prj.Name));

See Also


Project(Stream, LoadOptions)

Initializes a new instance of the Project class from the Stream with the specified instance of the LoadOptions class.

public Project(Stream stream, LoadOptions options)
ParameterTypeDescription
streamStreamStream of the Project Streamclass
optionsLoadOptionsthe specified instance of the LoadOptionsclass

Examples

Shows how to load the project from a stream by using <see cref=“Aspose.Tasks.LoadOptions”/> instance.

using (var stream = new FileStream(DataDir + "PasswordProtectedProject.mpp", FileMode.Open))
{
    var options = new LoadOptions
    {
        Password = "password"
    };
    var project = new Project(stream, options);
    Console.WriteLine(project.Get(Prj.Name));
}

See Also