Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Muzammil-khan/649bfeed4873268fa95d16369691f8e8 to your computer and use it in GitHub Desktop.

Select an option

Save Muzammil-khan/649bfeed4873268fa95d16369691f8e8 to your computer and use it in GitHub Desktop.
This Gist contains CSharp code snippets for examples of Aspose.Tasks.
This gist exceeds the recommended number of files (~10). To access all files, please clone this gist.

This Gist contains code snippets for sample code of Aspose.Tasks

// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project2.mpp");
SaveOptions options = new PdfSaveOptions();
options.Timescale = Timescale.Months;
options.View = ProjectView.GetDefaultGanttChartView();
GanttChartColumn column1 = options.View.Columns[2] as GanttChartColumn;
column1.StringAlignment = StringAlignment.Center;
column1 = options.View.Columns[3] as GanttChartColumn;
column1.StringAlignment = StringAlignment.Far;
column1 = options.View.Columns[4] as GanttChartColumn;
column1.StringAlignment = StringAlignment.Far;
project.Save(dataDir + "AlignCellContents_GanttChart_out.pdf", options);
options.PresentationFormat = PresentationFormat.ResourceSheet;
options.View = ProjectView.GetDefaultResourceSheetView();
ResourceViewColumn column2 = options.View.Columns[2] as ResourceViewColumn;
column2.StringAlignment = StringAlignment.Center;
column2 = options.View.Columns[3] as ResourceViewColumn;
column2.StringAlignment = StringAlignment.Far;
column2 = options.View.Columns[4] as ResourceViewColumn;
column2.StringAlignment = StringAlignment.Far;
project.Save(dataDir + "AlignCellContents_ResourceSheet_out.pdf", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project2.mpp");
SaveOptions options = new XamlOptions();
options.UseGradientBrush = false;
project.Save(dataDir + "ChangeGanttBarsColorGradient_Solid_out.xaml", options);
options.UseGradientBrush = true;
project.Save(dataDir + "ChangeGanttBarsColorGradient_Gradient_out.xaml", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
static void ImplementCustomBarSytle()
{
try
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Blank2010.mpp");
project.RootTask.Children.Add("Task");
GanttChartView view = project.DefaultView as GanttChartView;
GanttBarStyle custom = GetCustomBarStyle();
// Add the custom bar style to the custom bar collection of the project view
view.CustomBarStyles.Add(custom);
string file = "ImplementCustomBarStyleWriting_out.mpp";
MPPSaveOptions options = new MPPSaveOptions();
options.WriteViewData = true;
project.Save(dataDir + file, options);
}
catch (NotSupportedException ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
}
}
private static GanttBarStyle GetCustomBarStyle()
{
GanttBarStyle style = new GanttBarStyle();
style.ShowFor = "1";
style.MiddleShape = GanttBarMiddleShape.RectangleBottom;
style.MiddleFillPattern = GanttBarFillPattern.MediumFill;
style.MiddleShapeColor = Color.Blue;
style.StartShape = GanttBarEndShape.ArrowDown;
style.StartShapeColor = Color.Red;
style.EndShape = GanttBarEndShape.ArrowUp;
style.EndShapeColor = Color.Yellow;
style.LeftField = Field.TaskResourceNames;
style.RightField = Field.TaskName;
style.TopField = Field.TaskStart;
style.BottomField = Field.TaskFinish;
style.InsideField = Field.TaskDuration;
return style;
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CustomBarStyle.mpp");
GanttChartView view = project.DefaultView as GanttChartView;
Console.WriteLine("Custom bar styles count: {0}", view.CustomBarStyles.Count);
GanttBarStyle style1 = view.CustomBarStyles[0];
Console.WriteLine("Style1.LeftField is TaskDurationText : {0}", style1.LeftField.Equals(Field.TaskDurationText));
Console.WriteLine("Style1.RightField is TaskResourceNames : {0}", style1.RightField.Equals(Field.TaskResourceNames));
Console.WriteLine("Style1.TopField is TaskACWP: {0}", style1.TopField.Equals(Field.TaskACWP));
Console.WriteLine("Style1.BottomField is Undefined : {0}", style1.BottomField.Equals(Field.Undefined));
Console.WriteLine("Style1.InsideField is Undefined : {0}", style1.InsideField.Equals(Field.Undefined));
GanttBarStyle style2 = view.CustomBarStyles[1];
Console.WriteLine("Style2.LeftField is TaskActualWork : {0}", style2.LeftField.Equals(Field.TaskActualWork));
Console.WriteLine("Style2.RightField is TaskActualCost : {0}", style2.RightField.Equals(Field.TaskActualCost));
Console.WriteLine("Style2.TopField is Undefined : {0}", style2.TopField.Equals(Field.Undefined));
Console.WriteLine("Style2.BottomField is Undefined : {0}", style2.BottomField.Equals(Field.Undefined));
Console.WriteLine("Style2.InsideField is Undefined : {0}", style2.InsideField.Equals(Field.Undefined));
GanttBarStyle style3 = view.CustomBarStyles[2];
Console.WriteLine("Style3.LeftField is TaskPercentComplete : {0}", style3.LeftField.Equals(Field.TaskPercentComplete));
Console.WriteLine("Style3.RightField is TaskPercentWorkComplete : {0}", style3.RightField.Equals(Field.TaskPercentWorkComplete));
Console.WriteLine("Style3.TopField is Field.TaskActive : {0}", style3.TopField.Equals(Field.TaskActive));
Console.WriteLine("Style3.BottomField is TaskActualCost : {0}", style3.BottomField.Equals(Field.TaskActualCost));
Console.WriteLine("Style3.InsideField is Field.TaskActualDuration : {0}", style3.InsideField.Equals(Field.TaskActualDuration));
Console.WriteLine("Style3.StartShape is HouseDown : {0}", style3.StartShape.Equals(GanttBarEndShape.HouseDown));
Console.WriteLine("Style3.StartShapeType is Framed : {0}", style3.StartShapeType.Equals(GanttBarType.Framed));
Console.WriteLine("Style3.StartShapeColor is Red : {0}", style3.StartShapeColor.Equals(Color.FromArgb(Color.Red.ToArgb())));
Console.WriteLine("Style3.EndShape is CircleDiamond : {0}", style3.EndShape.Equals(GanttBarEndShape.CircleDiamond));
Console.WriteLine("Style3.EndShapeType is Solid : {0}", style3.EndShapeType.Equals(GanttBarType.Solid) );
Console.WriteLine("Style3.EndShapeColor is Yellow : {0}", style3.EndShapeColor.Equals(Color.FromArgb(Color.Yellow.ToArgb())));
Console.WriteLine("Style3.MiddleShape is RectangleTop : {0}", style3.MiddleShape.Equals(GanttBarMiddleShape.RectangleTop));
Console.WriteLine("Style3.MiddleFillPattern is SolidFill : {0}", style3.MiddleFillPattern.Equals(GanttBarFillPattern.SolidFill));
Console.WriteLine("Style3.EndShapeColor is Red : {0}", style3.MiddleShapeColor.Equals(Color.FromArgb(Color.Red.ToArgb())));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project2.mpp");
PresentationFormat presentationFormat = PresentationFormat.GanttChart;
string resultFile = "RenderDifferentPresentationFormatsToXAML_" + presentationFormat + "_out.xaml";
SaveOptions options = new XamlOptions();
options.PresentationFormat = presentationFormat;
project.Save(dataDir + resultFile, options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
PdfSaveOptions options = new PdfSaveOptions();
options.PresentationFormat = PresentationFormat.GanttChart;
options.FitContent = true;
options.RollUpGanttBars = false;
options.DrawNonWorkingTime = false;
options.PageSize = PageSize.A3;
string file = Path.Combine(dataDir, fileName);
string resultFile = Path.Combine(dataDir, "RenderGanttChartWithBarsNotRolledUp_out.pdf");
Project project = new Project(file);
project.Save(resultFile, (SaveOptions)options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Source file to be converted to TIFF
string file = "Project2.mpp";
Project project = new Project(dataDir + file);
// Save the project to TIFF
project.Save(dataDir + "RenderMultipageTIFF_out.tif", SaveFileFormat.TIFF);
// Save the project with CCITT4 compression
ImageSaveOptions options = new ImageSaveOptions(SaveFileFormat.TIFF);
options.TiffCompression = TiffCompression.Ccitt4;
project.Save(dataDir + "RenderMultipageTIFF_options_out.tif", (SaveOptions)options);
// Remove the compression
options.TiffCompression = TiffCompression.None;
project.Save(dataDir + "RenderMultipageTIFF_comp_none_out.tif", (SaveOptions)options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Source File to Render
string fileName = "Project2.mpp";
// Read the Project
Project project1 = new Project(dataDir + fileName);
// Select a Presentation format
PresentationFormat format = PresentationFormat.GanttChart;
// Render the project to all Pre-Defined page sizes
foreach (PageSize pageSize in (PageSize[])Enum.GetValues(typeof(PageSize)))
{
PdfSaveOptions options = new PdfSaveOptions();
options.PresentationFormat = format;
options.FitContent = true;
options.PageSize = pageSize;
string resultFile = "result_PredefinedPageSizes_" + format.ToString() + "_" + pageSize.ToString() + "_out.pdf";
project1.Save(dataDir + resultFile, (SaveOptions)options);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project2.mpp");
string resultFile = "RenderToXAML_out.xaml";
project.Save(dataDir + resultFile, SaveFileFormat.XAML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project2.mpp");
const string resultFile = "RenderXAMLWithOptions_out.xaml";
SaveOptions options = new XamlOptions();
options.FitContent = true;
options.LegendOnEachPage = false;
options.Timescale = Timescale.ThirdsOfMonths;
project.Save(dataDir + resultFile, options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "TaskEmbeddedDocuments.mpp");
Task task = project.RootTask.Children.GetById(1);
File.WriteAllText(dataDir + "Notes_out.rtf", task.Get(Tsk.NotesRTF));
Document doc = null;
using (MemoryStream stream = new MemoryStream())
using (StreamWriter streamWriter = new StreamWriter(stream))
{
streamWriter.Write(task.Get(Tsk.NotesRTF));
doc = new Document(stream);
}
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Aspose.Words.Drawing.Shape shape in shapes)
{
if (shape.OleFormat != null)
{
if (!shape.OleFormat.IsLink)
{
// Extract OLE Word object
if (shape.OleFormat.ProgId == "Word.Document.12")
{
MemoryStream stream = new MemoryStream();
shape.OleFormat.Save(stream);
Document newDoc = new Document(stream);
newDoc.Save(dataDir + "RetrieveTaskEmbeddedDocuments_out.doc");
}
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project2.mpp");
project.Set(Prj.TimescaleStart, new DateTime(2012, 4, 30));
project.Save(dataDir + "SetGanttChartViewStartDate_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
class SortTasksByColumnInGanttChart
{
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Project2.mpp");
SaveOptions options = new PdfSaveOptions();
options.Timescale = Timescale.Months;
options.TasksComparer = new TasksNameComparer();
project.Save(dataDir + "SortedByNames_out.pdf", options);
options.TasksComparer = new TasksDurationComparer();
project.Save(dataDir + "SortedByDurations_out.pdf", options);
}
public class TasksNameComparer : IComparer<Task>
{
public int Compare(Task x, Task y)
{
return x.Get(Tsk.Name).CompareTo(y.Get(Tsk.Name));
}
}
public class TasksDurationComparer : IComparer<Task>
{
public int Compare(Task x, Task y)
{
Duration durX = x.Get(Tsk.Duration);
Duration durY = y.Get(Tsk.Duration);
return durX.TimeSpan.CompareTo(durY.TimeSpan);
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CreateProject2.mpp");
var options = new PdfSaveOptions
{
PresentationFormat = PresentationFormat.GanttChart,
FitContent = true,
UseProjectDefaultFont = false,
DefaultFontName = "Segoe UI Black"
};
project.Save(dataDir + "CreateProject2_out.pdf", (SaveOptions)options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CreateProject2.mpp");
HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();
// Determines whether to include project name in HTML title (true by default)
htmlSaveOptions.IncludeProjectNameInTitle = false;
// Determines whether to include project name in HTML page header (true by default)
htmlSaveOptions.IncludeProjectNameInPageHeader = false;
htmlSaveOptions.Pages = new List<int>();
htmlSaveOptions.Pages.Add(1);
project.Save(dataDir + "ControlHeaderNameDuringHTMLExport_out.html", htmlSaveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CreateProject2.mpp");
project.Set(Prj.StartDate, new DateTime(2014, 9, 22));
// By default project.DateFormat == DateFormat.Date_ddd_mm_dd_yy (Mon 09/22/14) customize DateFormat (September 22, 2014)
project.Set(Prj.DateFormat, DateFormat.DateMmmmDdYyyy);
project.Save(dataDir + "CustomizeDateFormats1_out.pdf", SaveFileFormat.PDF);
// Export to date format 19/07/2016
project.Set(Prj.DateFormat, DateFormat.DateDdMmYyyy);
project.Save(dataDir + "CustomizeDateFormats2_out.pdf", SaveFileFormat.PDF);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CreateProject2.mpp");
SaveOptions options = new PdfSaveOptions();
options.PresentationFormat = PresentationFormat.ResourceSheet;
TextStyle style = new TextStyle();
style.Color = Color.OrangeRed;
style.FontStyle = FontStyle.Bold;
style.FontStyle |= FontStyle.Italic;
style.ItemType = TextItemType.OverallocatedResources;
options.TextStyles = new List<TextStyle>();
options.TextStyles.Add(style);
project.Save(dataDir + "CustomizeTextStyle_out.pdf", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CreateProject2.mpp");
SaveOptions saveOptions = new PdfSaveOptions();
// Set option fit content to true
saveOptions.FitContent = true;
saveOptions.Timescale = Timescale.Months;
saveOptions.PresentationFormat = PresentationFormat.TaskUsage;
project.Save(dataDir + "FitContentsToCellSize_out.pdf", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
SaveOptions saveOptions = new PdfSaveOptions();
// Set the LegendOnEachPage property to false to hide legends
saveOptions.LegendOnEachPage = false;
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CreateProject2.mpp");
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFileFormat.PNG);
saveOptions.StartDate = project.Get(Prj.StartDate).AddDays(-3);
saveOptions.EndDate = project.Get(Prj.FinishDate);
saveOptions.MarkCriticalTasks = true;
saveOptions.LegendOnEachPage = false;
saveOptions.Gridlines = new List<Gridline>();
Gridline gridline = new Gridline();
gridline.GridlineType = GridlineType.GanttRow;
gridline.Color = Color.CornflowerBlue;
gridline.Pattern = LinePattern.Dashed;
saveOptions.Gridlines.Add(gridline);
// Save the whole project layout to one file
project.Save(dataDir + "PrintProjectPagesToSeparateFiles1_out.png", (SaveOptions)saveOptions);
// Save project layout to separate files
saveOptions.SaveToSeparateFiles = true;
project.Save(dataDir + "PrintProjectPagesToSeparateFiles2_out.png", (SaveOptions)saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
//Read the MPP file.
Project project = new Project(dataDir + "CreateProject2.mpp");
//Use ReduceFooterGap property to reduce the gap between list of tasks and Footer
var imageSaveOptions =
new ImageSaveOptions(SaveFileFormat.PNG) { ReduceFooterGap = true, /* set to true */ SaveToSeparateFiles = true, PageSize = PageSize.A0, Timescale = Timescale.Days };
project.Save(dataDir + "ReducingGapBetweenTasksListAndFooter_out.png", (SaveOptions)imageSaveOptions);
var pdfSaveOptions = new PdfSaveOptions { ReduceFooterGap = true, /* set to true */ SaveToSeparateFiles = true, PageSize = PageSize.A0, Timescale = Timescale.Days };
project.Save(dataDir + "ReducingGapBetweenTasksListAndFooter_out.pdf", (SaveOptions)pdfSaveOptions);
var htmlSaveOptions = new HtmlSaveOptions
{
ReduceFooterGap = false, // set to true
IncludeProjectNameInPageHeader = false,
IncludeProjectNameInTitle = false,
PageSize = PageSize.A0,
Timescale = Timescale.Days
};
project.Save(dataDir + "ReducingGapBetweenTasksListAndFooter_out.html", htmlSaveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "TestProject1.mpp");
ImageSaveOptions options = new ImageSaveOptions(SaveFileFormat.TIFF);
options.HorizontalResolution = 72;
options.VerticalResolution = 72;
options.PixelFormat = PixelFormat.Format24bppRgb;
project.Save(dataDir + "RenderProjectDataToFormat24bppRgb_out.tif", (SaveOptions)options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CreateProject1.mpp");
project.Save(dataDir + "SaveProjectAsCSV_out.csv", SaveFileFormat.CSV);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CreateProject2.mpp");
// in order to manipulate JPEG quality one can use ImageSaveOptions.JpegQuality property.
// The allowed value range is 0..100.
var options = new ImageSaveOptions(SaveFileFormat.JPEG) { JpegQuality = 50 };
project.Save(dataDir + "image_out.jpeg", (SaveOptions)options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Read the input Project file
Project project = new Project(dataDir + "CreateProject2.mpp");
// Save the Project as PDF
project.Save(dataDir + "SaveProjectAsPDF_out.pdf", SaveFileFormat.PDF);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Read the input Project file
Project project = new Project(dataDir + "CreateProject1.mpp");
// Save the Project as SVG
project.Save(dataDir + "SaveProjectAsSVG_out.SVG", SaveFileFormat.SVG);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Read the input Project file
Project project = new Project(dataDir + "CreateProject2.mpp");
// Save the Project as text
project.Save(dataDir + "SaveProjectAsText_out.txt", SaveFileFormat.TXT);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Read the input Project file
Project project = new Project(dataDir + "CreateProject2.mpp");
// Save the Project as XLSX
project.Save(dataDir + "SaveProjectAsXLSX_out.xlsx", SaveFileFormat.XLSX);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CreateProject2.mpp");
HtmlSaveOptions option = new HtmlSaveOptions();
project.Save(dataDir + "SaveProjectDataAsHTML_out.html", option);
// OR
// Adding only one page (page number 2)
option = new HtmlSaveOptions();
option.Pages.Add(2);
project.Save(dataDir + "SaveProjectDataAsHTML2_out.html", option);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
const string projectName = "Project2.mpp";
Project project = new Project(dataDir + projectName);
ProjectFileInfo projectFileInfo = Project.GetProjectFileInfo(dataDir + projectName);
if (FileFormat.MPP14 == projectFileInfo.ProjectFileFormat)
{
Console.WriteLine("Project file format is ok");
}
SaveTemplateOptions options = new SaveTemplateOptions();
options.RemoveActualValues = true;
options.RemoveBaselineValues = true;
const string templateName = "SaveProjectDataAsTemplate_out.mpt";
project.SaveAsTemplate(dataDir + templateName);
ProjectFileInfo templateFileInfo = Project.GetProjectFileInfo(dataDir + templateName);
if (FileFormat.MPT14 == templateFileInfo.ProjectFileFormat)
{
Console.WriteLine("Template FileFormat is ok");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CreateProject2.mpp");
project.Save(dataDir + "SaveProjectDataToSpreadsheet2003XML_out.xml", SaveFileFormat.Spreadsheet2003);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Software Development Plan.mpp");
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.SaveToSeparateFiles = true;
saveOptions.Pages = new List<int>();
saveOptions.Pages.Add(1);
saveOptions.Pages.Add(4);
project.Save(dataDir + "SaveToMultiplePDFFiles_out.pdf", (SaveOptions)saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Spreadsheet2003SaveOptions options = new Spreadsheet2003SaveOptions();
GanttChartColumn col = new GanttChartColumn("WBS", 100, delegate(Task task) { return task.Get(Tsk.WBS); });
options.View.Columns.Add(col);
ResourceViewColumn rscCol = new ResourceViewColumn("Cost center", 100, delegate(Resource resource)
{ return resource.Get(Rsc.CostCenter); });
options.ResourceView.Columns.Add(rscCol);
AssignmentViewColumn assnCol = new AssignmentViewColumn("Notes", 200, delegate(ResourceAssignment assignment)
{ return assignment.Get(Asn.Notes); });
options.AssignmentView.Columns.Add(assnCol);
project.Save(dataDir + "UsingSpreadsheet2003SaveOptions_out.xml", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Read the input Project file
Project project = new Project(dataDir + "CreateProject2.mpp");
SaveOptions saveOptions = new SvgOptions();
saveOptions.FitContent = true;
saveOptions.Timescale = Timescale.ThirdsOfMonths;
project.Save(dataDir + "UseSvgOptions_out.svg", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Read the input Project file
Project project = new Project(dataDir + "CreateProject2.mpp");
XlsxOptions options = new XlsxOptions();
// Add desired Gantt Chart columns
GanttChartColumn col = new GanttChartColumn("WBS", 100, delegate(Task task) { return task.Get(Tsk.WBS); });
options.View.Columns.Add(col);
// Add desired resource view columns
ResourceViewColumn rscCol = new ResourceViewColumn("Cost center", 100, delegate(Resource resource)
{ return resource.Get(Rsc.CostCenter); });
options.ResourceView.Columns.Add(rscCol);
// Add desired assignment view columns
AssignmentViewColumn assnCol = new AssignmentViewColumn("Notes", 200, delegate(ResourceAssignment assignment)
{ return assignment.Get(Asn.Notes); });
options.AssignmentView.Columns.Add(assnCol);
project.Save(dataDir + "UsingXlsxOptions_out.xlsx", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project2.mpp");
project.Set(Prj.StartDate, new DateTime(2014, 9, 22));
// By default project.DateFormat == DateFormat.Date_ddd_mm_dd_yy (Mon 09/22/14) customize DateFormat (September 22, 2014)
project.Set(Prj.DateFormat, DateFormat.DateMmmmDdYyyy);
project.Save(dataDir + "CustomizeDateFormats1_out.pdf", SaveFileFormat.PDF);
// Export to date format 19/07/2016
project.Set(Prj.DateFormat, DateFormat.DateDdMmYyyy);
project.Save(dataDir + "CustomizeDateFormats2_out.pdf", SaveFileFormat.PDF);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Create a project instance and Set default properties
Project project = new Project(dataDir + "Project2.mpp");
SaveOptions options = new PdfSaveOptions();
options.PresentationFormat = PresentationFormat.ResourceSheet;
TextStyle style = new TextStyle();
style.Color = Color.OrangeRed;
style.FontStyle = FontStyle.Bold;
style.FontStyle |= FontStyle.Italic;
style.ItemType = TextItemType.OverallocatedResources;
options.TextStyles = new List<TextStyle>();
options.TextStyles.Add(style);
project.Save(dataDir + "CustomizeTextStyle_out.pdf", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project2.mpp");
SaveOptions saveOptions = new PdfSaveOptions();
// Set the row height to fit cell content
saveOptions.FitContent = true;
saveOptions.Timescale = Timescale.Months;
saveOptions.PresentationFormat = PresentationFormat.TaskUsage;
project.Save(dataDir + "FitContentsToCellSize_out.pdf", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
public static void Run()
{
// open modified xml stream
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(GetModifiedXml())))
{
Project project = new Project(stream, new ParseErrorCallback(CustomDurationHandler));
}
}
private static string GetModifiedXml()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
string xml;
// open valid xml file and modify it
using (TextReader reader = new StreamReader(dataDir + "Project.xml"))
xml = reader.ReadToEnd();
Regex regex = new Regex("PT(\\d+)H(\\d+)M(\\d+)S");
return regex.Replace(xml, "**$1Hrs$2Mins$3Secs**");
}
private static object CustomDurationHandler(object sender, ParseErrorArgs args)
{
Regex regex = new Regex("[*]{2}(\\d+)Hrs(\\d+)Mins(\\d+)Secs[*]{2}");
if (args.FieldType == typeof(TimeSpan))
{
Debug.Print("Object field : {0}, Invalid value : {1}", args.FieldName, args.InvalidValue);
string duration = regex.Replace(args.InvalidValue, "PT$1H$2M$3S");
TimeSpan newValue = Duration.ParseTimeSpan(duration);
Debug.Print("New value : {0}", newValue);
return newValue;
}
// here we handle only TimeSpan instances, so rethrow original exception with other types
throw args.Exception;
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
SqlConnectionStringBuilder sqlConnectionString = new SqlConnectionStringBuilder();
sqlConnectionString.DataSource = "192.168.56.2,1433";
sqlConnectionString.Encrypt = true;
sqlConnectionString.TrustServerCertificate = true;
sqlConnectionString.InitialCatalog = "ProjectServer_Published";
sqlConnectionString.NetworkLibrary = "DBMSSOCN";
sqlConnectionString.UserID = "sa";
sqlConnectionString.Password = "*****";
// Use Aspose.Tasks.Connectivity namespace
MspDbSettings settings = new MspDbSettings(sqlConnectionString.ConnectionString, new Guid("E6426C44-D6CB-4B9C-AF16-48910ACE0F54"));
settings.Schema = "dbo";
Project project = new Project(settings);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project5.mpp", "password");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
ProjectReader reader = new ProjectReader("password");
Project project = reader.Read("Project2003.mpp");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp");
project.Save(dataDir + "SaveProjectAsCSV_out.csv", SaveFileFormat.CSV);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Read the input Project file and Save the Project as PDF
Project project = new Project(dataDir + "Projectask1.mpp");
project.Save(dataDir + "SaveProjectAsPDF_out.pdf", SaveFileFormat.PDF);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Read the input Project file and Save the Project as XLSX
Project project = new Project(dataDir + "Project2.mpp");
project.Save(dataDir + "SaveProjectAsXLSX_out.xlsx", SaveFileFormat.XLSX);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Read the input Project file and save the Project as text
Project project = new Project(dataDir + "Project2.mpp");
project.Save(dataDir + "SaveProjectAsXLSX_out.txt", SaveFileFormat.TXT);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project2.mpp");
HtmlSaveOptions option = new HtmlSaveOptions();
project.Save(dataDir + "SaveProjectDataAsHTML_out.html", option);
// OR
project = new Project(dataDir + "Project2.mpp");
option = new HtmlSaveOptions();
option.Pages.Add(2); // adding only one page (page number 2)
project.Save(dataDir + "SaveProjectDataAsHTML2_out.html", option);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
const string projectName = "Project2010.mpp"; // any mpp file (here 2010 format used)
Project project = new Project(projectName);
ProjectFileInfo projectFileInfo = Project.GetProjectFileInfo(projectName);
if (FileFormat.MPP14 == projectFileInfo.ProjectFileFormat)
{
Console.WriteLine("Project file format is ok");
}
SaveTemplateOptions options = new SaveTemplateOptions();
options.RemoveActualValues = true;
options.RemoveBaselineValues = true;
const string templateName = "result.mpt";
project.SaveAsTemplate(templateName);
ProjectFileInfo templateFileInfo = Project.GetProjectFileInfo(templateName);
if (FileFormat.MPT14 == templateFileInfo.ProjectFileFormat)
{
Console.WriteLine("Template FileFormat is ok");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project2.mpp");
project.Save(dataDir + "SaveProjectDataToSpreadsheet2003XML_out.xml", SaveFileFormat.Spreadsheet2003);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Projec1.mpp");
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.SaveToSeparateFiles = true;
saveOptions.Pages = new List<int>();
saveOptions.Pages.Add(1);
saveOptions.Pages.Add(4);
project.Save(dataDir + "SaveToMultiplePDFFiles_out.pdf", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Read the input Project file
Project project = new Project(dataDir + "Project2.mpp");
SaveOptions saveOptions = new SvgOptions();
saveOptions.FitContent = true;
saveOptions.Timescale = Timescale.ThirdsOfMonths;
project.Save(dataDir + "UseSvgOptions_out.svg", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Read the input Project file
Project project = new Project(dataDir + "Project2.mpp");
SaveOptions saveOptions = new SvgOptions();
saveOptions.FitContent = true;
saveOptions.Timescale = Timescale.ThirdsOfMonths;
project.Save(dataDir + "UseSvgOptions_out.svg", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir+ "CalculateCriticalPath.mpp");
project.CalculationMode = CalculationMode.Automatic;
Task subtask1 = project.RootTask.Children.Add("1");
Task subtask2 = project.RootTask.Children.Add("2");
Task subtask3 = project.RootTask.Children.Add("3");
project.TaskLinks.Add(subtask1, subtask2, TaskLinkType.FinishToStart);
// Display the critical path now
foreach (Task task in project.CriticalPath)
{
Console.WriteLine(task.Get(Tsk.Name));
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Create a project instance
Project newProject = new Project();
// Create a file stream and write the stream into XML format
FileStream projectStream = new FileStream(dataDir + "Project1.xml", FileMode.Create, FileAccess.Write);
newProject.Save(projectStream, Aspose.Tasks.Saving.SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project();
project.Save(dataDir+ "saved.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project prj = new Project(dataDir+ "ExtendedAttributes.mpp");
ExtendedAttributeDefinitionCollection eads = prj.ExtendedAttributes;
// Create extended attribute definition and get zero index task
ExtendedAttributeDefinition ead = new ExtendedAttributeDefinition();
ead.FieldId = ((int)ExtendedAttributeTask.Start7).ToString();
ead.FieldName = "Start7";
eads.Add(ead);
Task tsk = prj.RootTask.Children.GetById(1);
ExtendedAttributeCollection eas = tsk.ExtendedAttributes;
string dateTimeFormat = "yyyy-MM-ddTHH:mm:ss";
ExtendedAttribute ea = new ExtendedAttribute();
ea.FieldId = ead.FieldId;
ea.Value = XmlConvert.ToString(DateTime.Now, dateTimeFormat);
eas.Add(ea);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
//Read a project from template
Project project = new Project(dataDir + "Project1.mpp");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project5.mpp");
Calendar calendar = new Calendar("New Cal");
CalendarCollection calColl = project.Calendars;
foreach (Calendar getcalendar in calColl)
{
if (getcalendar.Name == "Standard")
{
calColl.Remove(getcalendar);
calColl.Add("Standard", getcalendar);
break;
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp");
project.Set(Prj.ScheduleFromStart, false);
project.Set(Prj.FinishDate, new DateTime(2020, 1, 1));
// Now all tasks dates (Start, Finish, EarlyStart, EarlyFinish, LateStart, LateFinish) are calculated. To get the critical path we need to calculate slacks (can be invoked in separate thread, but only after calculation of all early/late dates)
project.Recalculate();
TaskCollection criticalPath = project.CriticalPath;
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project2.mpp");
project.Set(Prj.ScheduleFromStart, true);
project.Set(Prj.StartDate, new DateTime(2014, 1, 1));
// Now all tasks dates (Start, Finish, EarlyStart, EarlyFinish, LateStart, LateFinish) are calculated. To get the critical path we need to calculate slacks (can be invoked in separate thread, but only after calculation of all early/late dates)
project.Recalculate();
TaskCollection criticalPath = project.CriticalPath;
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project2.mpp");
project.Set(Prj.ScheduleFromStart, false);
project.Set(Prj.FinishDate, new DateTime(2020, 1, 1));
// Now all tasks dates (Start, Finish, EarlyStart, EarlyFinish, LateStart, LateFinish) are calculated. To get the critical path we need to calculate slacks (can be invoked in separate thread, but only after calculation of all early/late dates)
project.Recalculate();
TaskCollection criticalPath = project.CriticalPath;
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Create a project reader instance and retrieve Calendars Information
Project project = new Project(dataDir + "RetrieveCalendarInfo.mpp");
CalendarCollection alCals = project.Calendars;
foreach (Calendar cal in alCals)
{
if (cal.Name != null)
{
Console.WriteLine("Calendar UID : " + cal.Uid);
Console.WriteLine("Calendar Name : " + cal.Name);
WeekDayCollection alDays = cal.WeekDays;
foreach (WeekDay wd in alDays)
{
TimeSpan ts = wd.GetWorkingTime();
if (wd.DayWorking)
{
Console.WriteLine(wd.DayType.ToString() + ":");
Console.WriteLine(ts.ToString());
}
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Read the input Project file and save the Project as SVG
Project project = new Project(dataDir + "Project1.mpp");
project.Save(dataDir + "Project1.SVG", SaveFileFormat.SVG);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Create a project instance Set new task property and Save the project as XML project file
Project project = new Project();
project.Set(Prj.NewTaskStartDate, TaskStartDateType.CurrentDate);
project.Save(dataDir + "Project.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "DefaultProperties.mpp");
// Display default properties
Console.WriteLine("New Task Default Start: " + project.Get(Prj.DefaultStartTime).ToShortDateString());
Console.WriteLine("New Task Default Type: " + project.Get(Prj.DefaultTaskType));
Console.WriteLine("Resouce Default Standard Rate: " + project.Get(Prj.DefaultStandardRate).ToString());
Console.WriteLine("Resource Default Overtime Rate: " + project.Get(Prj.DefaultOvertimeRate).ToString());
Console.WriteLine("Default Task EV Method: " + project.Get(Prj.DefaultTaskEVMethod).ToString());
Console.WriteLine("Default Cost Accrual: " + project.Get(Prj.DefaultFixedCostAccrual).ToString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "DetermineProjectVersion.mpp");
Console.WriteLine("Project Version : " + project.Get(Prj.SaveVersion).ToString());
Console.WriteLine("Last Saved : " + project.Get(Prj.LastSaved).ToShortDateString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "ReadCurrencyProperties.mpp");
// Display currency properties
Console.WriteLine("Currency Code : " + project.Get(Prj.CurrencyCode).ToString());
Console.WriteLine("<br>Currency Digits : " + project.Get(Prj.CurrencyDigits).ToString());
Console.WriteLine("<br>Currency Symbol : " + project.Get(Prj.CurrencySymbol).ToString());
Console.WriteLine("Currency Symbol Position" + project.Get(Prj.CurrencySymbolPosition).ToString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Create a project reader instance and Display fiscal year properties
Project project = new Project(dataDir + "ReadFiscalYearProperties.mpp");
Console.WriteLine("Fiscal Year Start Date : " + project.Get(Prj.FyStartDate).ToString());
Console.WriteLine("Fiscal Year Numbering : " + project.Get(Prj.FiscalYearStart).ToString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Create a project reader instance
Project project = new Project(dataDir+ "ReadProjectInfo.mpp");
if (project.Get(Prj.ScheduleFromStart))
Console.WriteLine("Project Finish Date : " + project.Get(Prj.StartDate).ToShortDateString());
else
Console.WriteLine("Project Finish Date : " + project.Get(Prj.FinishDate).ToShortDateString());
Console.WriteLine(project.Get(Prj.Author));
Console.WriteLine(project.Get(Prj.LastAuthor));
Console.WriteLine(project.Get(Prj.Revision));
Console.WriteLine(project.Get(Prj.Keywords));
Console.WriteLine(project.Get(Prj.Comments));
Console.WriteLine("The program has run successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "ReadWeekdayProperties.mpp");
// Display week days properties
Console.WriteLine("Week Start Date : " + project.Get(Prj.WeekStartDay).ToString());
Console.WriteLine("Days Per Month : " + project.Get(Prj.DaysPerMonth).ToString());
Console.WriteLine("Minutes Per Day : " + project.Get(Prj.MinutesPerDay).ToString());
Console.WriteLine("Minutes Per Week : " + project.Get(Prj.MinutesPerWeek).ToString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Create a project instance, Set currency properties and save the project as XML project file
Project project = new Project(dataDir+ "WriteCurrencyProperties.mpp");
project.Set(Prj.CurrencyCode, "AUD");
project.Set(Prj.CurrencyDigits, 2);
project.Set(Prj.CurrencySymbol, "$");
project.Set(Prj.CurrencySymbolPosition, CurrencySymbolPositionType.After);
project.Save(dataDir+ "project.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Create a project instance and Set default properties
Project project = new Project();
project.Set(Prj.ScheduleFromStart, true);
project.Set(Prj.StartDate, DateTime.Now);
project.Set(Prj.DefaultStartTime, project.Get(Prj.StartDate));
project.Set(Prj.DefaultTaskType, TaskType.FixedDuration);
project.Set(Prj.DefaultStandardRate, 15);
project.Set(Prj.DefaultOvertimeRate, 12);
project.Set(Prj.DefaultTaskEVMethod, EarnedValueMethodType.PercentComplete);
project.Set(Prj.DefaultFixedCostAccrual, CostAccrualType.Prorated);
// Save the project to XML format
project.Save(dataDir + "WriteDefaultProperties_out.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Create a project instance and set fiscal year properties
Project prj = new Project(dataDir + "WriteFiscalYearProperties.mpp");
prj.Set(Prj.FyStartDate, Month.July);
prj.Set(Prj.FiscalYearStart, true);
prj.Save(dataDir + "saved.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "WriteProjectInfo.mpp");
project.Set(Prj.Author, "Author");
project.Set(Prj.LastAuthor, "Last Author");
project.Set(Prj.Revision, 15);
project.Set(Prj.Keywords, "MSP Aspose");
project.Set(Prj.Comments, "Comments");
project.Save(dataDir + "saved.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Create a project instance and set week days properties
Project project = new Project(dataDir+ "WriteWeekdayProperties.mpp");
project.Set(Prj.WeekStartDay, DayType.Monday);
project.Set(Prj.DaysPerMonth, 24);
project.Set(Prj.MinutesPerDay, 540);
project.Set(Prj.MinutesPerWeek, 3240);
project.Save(dataDir+ "saved.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project1.mpp");
Task task = project.RootTask.Children.Add("Task1");
task.Set(Tsk.ActualStart, DateTime.Parse("23-Aug-2012"));
// Set duration in hours
task.Set(Tsk.Duration, project.GetDuration(24, TimeUnitType.Hour));
task.Set(Tsk.DurationFormat, TimeUnitType.Day);
// Save the Project as XML
project.Save(dataDir + "AddNewTask_out.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "SampleProject.mpp");
// Declare ChildTasksCollector class object
ChildTasksCollector collector = new ChildTasksCollector();
// Use TaskUtils to get all children tasks in RootTask
TaskUtils.Apply(project1.RootTask, collector, 0);
// Define Resources
for (int i = 0; i <= 4; i++)
{
string devloper = "Developer0" + i;
// Add resource to project
Resource newResource = project1.Resources.Add(devloper);
newResource.Set(Rsc.Type, ResourceType.Work);
// Define assignment
ResourceAssignment newResourceAssignment = project1.ResourceAssignments.Add((Task)collector.Tasks[i], newResource);
}
project1.Save(dataDir + "CreateResourcesAndLinkToTasks_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "SampleProject.mpp");
Task task1 = project.RootTask.Children.GetById(1);
Task task2 = project.RootTask.Children.GetById(2);
Task task3 = project.RootTask.Children.GetById(3);
Task task4 = project.RootTask.Children.GetById(4);
Task task5 = project.RootTask.Children.GetById(5);
// Link the tasks
TaskLink tsklnk = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
tsklnk = project.TaskLinks.Add(task2, task3, TaskLinkType.FinishToStart);
tsklnk = project.TaskLinks.Add(task3, task4, TaskLinkType.FinishToStart);
tsklnk = project.TaskLinks.Add(task4, task5, TaskLinkType.FinishToStart);
tsklnk = project.TaskLinks.Add(task2, task5, TaskLinkType.FinishToStart);
// Display links among the tasks
TaskLinkCollection allinks = project.TaskLinks;
foreach (TaskLink tasklnk in allinks)
{
Console.WriteLine("From ID = " + tasklnk.PredTask.Get(Tsk.Id) + "=>To ID = " + tasklnk.SuccTask.Get(Tsk.Id));
Console.WriteLine("________________________________________");
}
// Save the project
project.Save(dataDir + "LinkTasks_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Load MPP file
Project project = new Project(dataDir + "Project1.mpp");
// Get the critical path
TaskCollection criticalPath = project.CriticalPath;
// Enumerate the tasks in the critical path
foreach (Task task in criticalPath)
{
Console.WriteLine(task.Get(Tsk.Id) + " " + task.Get(Tsk.Name));
Console.WriteLine(task.Get(Tsk.Start));
Console.WriteLine(task.Get(Tsk.Finish) + "\n");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Load MPP file
Project project = new Project(dataDir + "Project1.mpp");
// Load all tasks
TaskCollection allTasks = project.RootTask.Children;
// Loop through each task and read information related to tasks
foreach (Task task in allTasks)
{
Console.WriteLine("Reading Task " + task.Get(Tsk.Name));
Console.WriteLine("\nID: " + task.Get(Tsk.Id));
Console.WriteLine("Start: " + task.Get(Tsk.Start));
Console.WriteLine("Finish: " + task.Get(Tsk.Finish));
Console.WriteLine("\n===========================\n");
}
// Loop through each resource and read information related to resources
foreach (Resource resource in project.Resources)
{
string resourceType = null;
switch (resource.Get(Rsc.Type))
{
case ResourceType.Material:
resourceType = "Material";
break;
case ResourceType.Work:
resourceType = "Work";
break;
default:
resourceType = "Cost";
break;
}
Console.WriteLine("Reading Resource " + resource.Get(Rsc.Name));
Console.WriteLine("\nID: " + resource.Get(Rsc.Id));
Console.WriteLine("Type: " + resourceType);
Console.WriteLine("\n===========================\n");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Aspose.Tasks.License license = new Aspose.Tasks.License();
license.SetLicense("Aspose.Tasks.lic");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Aspose.Tasks.License license = new Aspose.Tasks.License();
FileStream myStream = new FileStream("Aspose.Tasks.lic", FileMode.Open);
license.SetLicense(myStream);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create a prject instance
Project project1 = new Project();
// Define Tasks
Task task1 = project1.RootTask.Children.Add("Task1");
task1.Set(Tsk.ActualStart, DateTime.Parse("06-Apr-2010"));
Task task2 = project1.RootTask.Children.Add("Task2");
task2.Set(Tsk.ActualStart, DateTime.Parse("10-Apr-2010"));
// Save the Project as XML
project1.Save("EvalProject_out.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp");
project.RootTask.Children.Add("Task1");
PageInfo pageInfo = project.DefaultView.PageInfo;
using (Image image = Image.FromFile(dataDir + "Image1.png"))
{
pageInfo.Header.CenteredImage = image;
pageInfo.Legend.LeftImage = image;
pageInfo.Legend.LeftText = string.Empty;
MPPSaveOptions saveOptions = new MPPSaveOptions();
saveOptions.WriteViewData = true;
project.Save(dataDir + "ReadHeaderAndFooterInformationFromMPPFile1_out.mpp", saveOptions);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Read an existing project and create a new task and save the project as MPP project file
Project project = new Project(dataDir+ "MPPFileUpdate.mpp");
Task task = project.RootTask.Children.Add("Task1");
task.Set(Tsk.Start, new DateTime(2012, 8, 1));
task.Set(Tsk.Finish, new DateTime(2012, 8, 5));
project.Save(dataDir+ "AfterLinking.Mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "ReadProjectInfo.mpp");
Filter filter = project.TaskFilters.ToList()[1];
Console.WriteLine(filter.Criteria.CriteriaRows.Count);
Console.WriteLine(filter.Criteria.Operation.ToString());
FilterCriteria criteria1 = filter.Criteria.CriteriaRows[0];
Console.WriteLine(criteria1.Test.ToString());
Console.WriteLine(criteria1.Field.ToString());
Console.WriteLine(criteria1.Values[0].ToString());
FilterCriteria criteria2 = filter.Criteria.CriteriaRows[1];
Console.WriteLine(criteria2.Operation.ToString());
Console.WriteLine(criteria2.CriteriaRows.Count);
FilterCriteria criteria21 = criteria2.CriteriaRows[0];
Console.WriteLine(criteria21.Test.ToString());
Console.WriteLine(criteria21.Field.ToString());
Console.WriteLine(criteria21.Values[0].ToString());
FilterCriteria criteria22 = criteria2.CriteriaRows[1];
Console.WriteLine(criteria22.Test.ToString());
Console.WriteLine(criteria22.Field.ToString());
Console.WriteLine(criteria22.Values[0].ToString());
FilterCriteria criteria23 = criteria2.CriteriaRows[2];
Console.WriteLine(criteria23.Test.ToString());
Console.WriteLine(criteria23.Field.ToString());
Console.WriteLine(criteria23.Values[0].ToString());
FilterCriteria criteria3 = filter.Criteria.CriteriaRows[2];
Console.WriteLine(criteria3.CriteriaRows.Count);
Console.WriteLine(criteria3.Operation.ToString());
Console.WriteLine(filter.Criteria);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp");
List<Filter> taskFilters = project.TaskFilters.ToList();
Console.WriteLine("Task Filters Count: " + taskFilters.Count);
Console.WriteLine("All Tasks: " + taskFilters[0].Name);
Console.WriteLine("Task Item: " + taskFilters[0].FilterType);
Console.WriteLine("Task Filters Show In Menu: " + taskFilters[0].ShowInMenu);
Console.WriteLine("Task filter ShowRelatedSummaryRows: " + taskFilters[0].ShowRelatedSummaryRows);
Console.WriteLine("Task filter type: " + taskFilters[1].ShowInMenu);
Console.WriteLine("Task Filters Show In Menu: " + taskFilters[1].ShowInMenu);
Console.WriteLine("Task filter ShowRelatedSummaryRows: " + taskFilters[1].ShowRelatedSummaryRows);
Console.WriteLine("NEW FILTER", taskFilters[2].Name);
Console.WriteLine("Task filter type: " + taskFilters[2].ShowInMenu);
Console.WriteLine("Task Filters Show In Menu: " + taskFilters[2].ShowInMenu);
Console.WriteLine("Task filter ShowRelatedSummaryRows: " + taskFilters[2].ShowRelatedSummaryRows);
Console.WriteLine("Task FilterCriteria:m", taskFilters[2].Criteria);
Console.WriteLine("(TaskName Contains T)", taskFilters[2].Criteria.ToString());
List<Filter> rscFilters = project.ResourceFilters.ToList();
Console.WriteLine("Project.ResourceFilters count: " + rscFilters.Count);
Console.WriteLine("Resource Filter Item Type: Item.ResourceType: " + rscFilters[0].FilterType);
Console.WriteLine("Resource filter ShowInMenu" + rscFilters[0].ShowInMenu);
Console.WriteLine("Resource filter ShowRelatedSummaryRows: " + rscFilters[0].ShowRelatedSummaryRows);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
public void TASKSNET_16019()
{
Project project = new Project("HeaderFooter2007_3.mpp"); // Attached test project
PageInfo info = project.DefaultView.PageInfo;
Assert.IsNotNull(info, "Page data cannot be null");
AssertHeaderFooterCorrect(info);
AssertPageSettingsCorrect(info);
AssertPageViewSettingsCorrect(info);
AssertMarginsCorrect(info);
AssertLegendCorrect(info);
}
private void AssertHeaderFooterCorrect(PageInfo info)
{
Assert.AreEqual("LEFT HEADER", info.Header.LeftText, "Header left text");
Assert.AreEqual("CENTER HEADER", info.Header.CenteredText, "Header center text");
Assert.AreEqual("RIGHT HEADER", info.Header.RightText, "Header right text");
Assert.AreEqual("LEFT FOOTER", info.Footer.LeftText, "Footer left text");
Assert.AreEqual("CENTER FOOTER", info.Footer.CenteredText, "Footer center text");
Assert.AreEqual("RIGHT FOOTER", info.Footer.RightText, "Footer right text");
}
private void AssertPageSettingsCorrect(PageInfo info)
{
Assert.IsTrue(info.PageSettings.IsPortrait, "Portrait Orientation");
Assert.IsTrue(info.PageSettings.AdjustToPercentOfNormalSize, "AdjustToPercentOfNormalSize");
Assert.AreEqual(150, info.PageSettings.PercentOfNormalSize, "PercentOfNormalSize");
Assert.AreEqual(3, info.PageSettings.PagesInWidth, "PagesInWidth");
Assert.AreEqual(7, info.PageSettings.PagesInHeight, "PagesInHeight");
Assert.AreEqual(PrinterPaperSize.PaperA4, info.PageSettings.PaperSize, "PaperSize");
Assert.AreEqual(short.MinValue + 2, info.PageSettings.FirstPageNumber, "FirstPageNumber");
}
private void AssertPageViewSettingsCorrect(PageInfo info)
{
Assert.IsFalse(info.PageViewSettings.PrintAllSheetColumns, "PrintAllSheetColumns");
Assert.IsTrue(info.PageViewSettings.PrintFirstColumnsCountOnAllPages, "PrintFirstColumnsCountOnAllPages");
Assert.AreEqual(3, info.PageViewSettings.FirstColumnsCount, "FirstColumnsCount");
Assert.IsTrue(info.PageViewSettings.PrintNotes, "PrintNotes");
Assert.IsFalse(info.PageViewSettings.PrintBlankPages, "PrintBlankPages");
Assert.IsTrue(info.PageViewSettings.FitTimescaleToEndOfPage, "FitTimescaleToEndOfPage");
}
private void AssertMarginsCorrect(PageInfo info)
{
Assert.AreEqual(1, info.Margins.Left, 1e-5, "Margins.Left");
Assert.AreEqual(1.1, info.Margins.Top, 1e-5, "Margins.Top");
Assert.AreEqual(1.2, info.Margins.Right, 1e-5, "Margins.Right");
Assert.AreEqual(1.3, info.Margins.Bottom, 1e-5, "Margins.Bottom");
Assert.AreEqual(Border.AroundEveryPage, info.Margins.Borders, "Margin.Borders");
}
private void AssertLegendCorrect(PageInfo info)
{
Assert.AreEqual("LEFT LEGEND", info.Legend.LeftText, "Legend left text");
Assert.AreEqual("CENTER LEGEND", info.Legend.CenteredText, "Legend center text");
Assert.AreEqual("RIGHT LEGEND", info.Legend.RightText, "Legend right text");
Assert.AreEqual(Legend.OnEveryPage, info.Legend.LegendOn, "LegendOn");
Assert.AreEqual(7.77, info.Legend.Width, 1e-5, "Legend Width");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
public void TASKSNET_16019()
{
Project project = new Project("HeaderFooter2007_3.mpp"); // Attached test project
PageInfo info = project.DefaultView.PageInfo;
Assert.IsNotNull(info, "Page data cannot be null");
AssertHeaderFooterCorrect(info);
AssertPageSettingsCorrect(info);
AssertPageViewSettingsCorrect(info);
AssertMarginsCorrect(info);
AssertLegendCorrect(info);
}
private void AssertHeaderFooterCorrect(PageInfo info)
{
Assert.AreEqual("LEFT HEADER", info.Header.LeftText, "Header left text");
Assert.AreEqual("CENTER HEADER", info.Header.CenteredText, "Header center text");
Assert.AreEqual("RIGHT HEADER", info.Header.RightText, "Header right text");
Assert.AreEqual("LEFT FOOTER", info.Footer.LeftText, "Footer left text");
Assert.AreEqual("CENTER FOOTER", info.Footer.CenteredText, "Footer center text");
Assert.AreEqual("RIGHT FOOTER", info.Footer.RightText, "Footer right text");
}
private void AssertPageSettingsCorrect(PageInfo info)
{
Assert.IsTrue(info.PageSettings.IsPortrait, "Portrait Orientation");
Assert.IsTrue(info.PageSettings.AdjustToPercentOfNormalSize, "AdjustToPercentOfNormalSize");
Assert.AreEqual(150, info.PageSettings.PercentOfNormalSize, "PercentOfNormalSize");
Assert.AreEqual(3, info.PageSettings.PagesInWidth, "PagesInWidth");
Assert.AreEqual(7, info.PageSettings.PagesInHeight, "PagesInHeight");
Assert.AreEqual(PrinterPaperSize.PaperA4, info.PageSettings.PaperSize, "PaperSize");
Assert.AreEqual(short.MinValue + 2, info.PageSettings.FirstPageNumber, "FirstPageNumber");
}
private void AssertPageViewSettingsCorrect(PageInfo info)
{
Assert.IsFalse(info.PageViewSettings.PrintAllSheetColumns, "PrintAllSheetColumns");
Assert.IsTrue(info.PageViewSettings.PrintFirstColumnsCountOnAllPages, "PrintFirstColumnsCountOnAllPages");
Assert.AreEqual(3, info.PageViewSettings.FirstColumnsCount, "FirstColumnsCount");
Assert.IsTrue(info.PageViewSettings.PrintNotes, "PrintNotes");
Assert.IsFalse(info.PageViewSettings.PrintBlankPages, "PrintBlankPages");
Assert.IsTrue(info.PageViewSettings.FitTimescaleToEndOfPage, "FitTimescaleToEndOfPage");
}
private void AssertMarginsCorrect(PageInfo info)
{
Assert.AreEqual(1, info.Margins.Left, 1e-5, "Margins.Left");
Assert.AreEqual(1.1, info.Margins.Top, 1e-5, "Margins.Top");
Assert.AreEqual(1.2, info.Margins.Right, 1e-5, "Margins.Right");
Assert.AreEqual(1.3, info.Margins.Bottom, 1e-5, "Margins.Bottom");
Assert.AreEqual(Border.AroundEveryPage, info.Margins.Borders, "Margin.Borders");
}
private void AssertLegendCorrect(PageInfo info)
{
Assert.AreEqual("LEFT LEGEND", info.Legend.LeftText, "Legend left text");
Assert.AreEqual("CENTER LEGEND", info.Legend.CenteredText, "Legend center text");
Assert.AreEqual("RIGHT LEGEND", info.Legend.RightText, "Legend right text");
Assert.AreEqual(Legend.OnEveryPage, info.Legend.LegendOn, "LegendOn");
Assert.AreEqual(7.77, info.Legend.Width, 1e-5, "Legend Width");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
string path = "";
string newFile = path + "Blank2010.mpp";
string resultFile = path + "OutputMPP.mpp";
Project project = new Project(newFile);
// Add new text3 extended attribute and one text value
ExtendedAttributeDefinition taskTextAttr = new ExtendedAttributeDefinition();
taskTextAttr.Alias = "New text3 attribute";
taskTextAttr.FieldName = "Text3";
taskTextAttr.ElementType = ElementType.Task;
taskTextAttr.CfType = CustomFieldType.Text;
taskTextAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Text3).ToString();
taskTextAttr.LookupUid = Guid.NewGuid().ToString();
project.ExtendedAttributes.Add(taskTextAttr);
Value textVal = new Value();
textVal.Id = 1;
textVal.Description = "Text value descr";
textVal.Val = "Text value1";
taskTextAttr.ValueList.Add(textVal);
// Add new cost1 extended attribute and two cost values
ExtendedAttributeDefinition taskCostAttr = new ExtendedAttributeDefinition();
taskCostAttr.Alias = "New cost1 attribute";
taskCostAttr.FieldName = "Cost1";
taskCostAttr.ElementType = ElementType.Task;
taskCostAttr.CfType = CustomFieldType.Cost;
taskCostAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Cost1).ToString();
taskCostAttr.LookupUid = Guid.NewGuid().ToString();
project.ExtendedAttributes.Add(taskCostAttr);
Value costVal1 = new Value();
costVal1.Id = 2;
costVal1.Description = "Cost value 1 descr";
costVal1.Val = "99900";
Value costVal2 = new Value();
costVal2.Id = 3;
costVal2.Description = "Cost value 2 descr";
costVal2.Val = "11100";
taskCostAttr.ValueList.Add(costVal1);
taskCostAttr.ValueList.Add(costVal2);
// Add new task and assign attribute value
Aspose.Tasks.Task task = project.RootTask.Children.Add("New task");
ExtendedAttribute taskAttr = new ExtendedAttribute();
taskAttr.AttributeDefinition = taskCostAttr;
taskAttr.Value = "99900";
taskAttr.FieldId = taskCostAttr.FieldId;
task.ExtendedAttributes.Add(taskAttr);
ExtendedAttributeDefinition taskStartAttr = new ExtendedAttributeDefinition();
taskStartAttr.Alias = "New start 7 attribute";
taskStartAttr.CfType = CustomFieldType.Start;
taskStartAttr.ElementType = ElementType.Task;
taskStartAttr.FieldName = "Start7";
taskStartAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Start7).ToString();
taskStartAttr.LookupUid = Guid.NewGuid().ToString();
Value startVal = new Value();
startVal.Val = DateTime.Now.ToString();
startVal.Description = "Start 7 value description";
taskStartAttr.ValueList.Add(startVal);
project.ExtendedAttributes.Add(taskStartAttr);
ExtendedAttributeDefinition taskFinishAttr = new ExtendedAttributeDefinition();
taskFinishAttr.Alias = "New finish 4 attribute";
taskFinishAttr.CfType = CustomFieldType.Finish;
taskFinishAttr.ElementType = ElementType.Task;
taskFinishAttr.FieldName = "Finish4";
taskFinishAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Finish4).ToString();
taskFinishAttr.LookupUid = Guid.NewGuid().ToString();
Value finishVal = new Value();
finishVal.Val = DateTime.Now.ToString();
finishVal.Description = "Finish 4 value description";
taskFinishAttr.ValueList.Add(finishVal);
project.ExtendedAttributes.Add(taskFinishAttr);
ExtendedAttributeDefinition numberAttr = new ExtendedAttributeDefinition();
numberAttr.Alias = "New number attribute";
numberAttr.FieldName = "Number20";
numberAttr.CfType = CustomFieldType.Number;
numberAttr.ElementType = ElementType.Task;
numberAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Number20).ToString();
numberAttr.LookupUid = Guid.NewGuid().ToString();
Value val1 = new Value();
val1.Val = "1";
val1.Description = "Number 1 value";
Value val2 = new Value();
val2.Val = "2";
val2.Description = "Number 2 value";
Value val3 = new Value();
val3.Val = "3";
val3.Description = "Number 3 value";
numberAttr.ValueList.Add(val1);
numberAttr.ValueList.Add(val2);
numberAttr.ValueList.Add(val3);
project.ExtendedAttributes.Add(numberAttr);
ExtendedAttributeDefinition rscStartAttr = new ExtendedAttributeDefinition();
rscStartAttr.Alias = "New start5 attribute";
rscStartAttr.FieldName = "Start5";
rscStartAttr.ElementType = ElementType.Resource;
rscStartAttr.CfType = CustomFieldType.Start;
rscStartAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Start5).ToString(); ;
rscStartAttr.LookupUid = Guid.NewGuid().ToString();
Value startVal2 = new Value();
startVal2.Id = 4;
startVal2.Val = DateTime.Now.ToString();
startVal2.Description = "this is start5 value descr";
rscStartAttr.ValueList.Add(startVal2);
project.ExtendedAttributes.Add(rscStartAttr);
// Save the project as MPP project file
project.Save(resultFile, Aspose.Tasks.Saving.SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Instantiate ProjectReader class
Project project = new Project(dataDir+ "WriteMPPProjectSummary.mpp");
project.Set(Prj.Author, "Author");
project.Set(Prj.LastAuthor, "Last Author");
project.Set(Prj.Revision, 15);
project.Set(Prj.Keywords, "MSP Aspose");
project.Set(Prj.Comments, "Comments");
project.Save(dataDir+ "saved.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project;
try
{
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
project = new Project(dataDir + "project.mpp");
}
catch (TasksReadingException ex)
{
Console.WriteLine("Message:");
Console.WriteLine(ex.Message);
Console.WriteLine("Log:");
Console.WriteLine(ex.LogText);
if (ex.InnerException != null)
{
Console.WriteLine("Inner exception message:");
Console.WriteLine(ex.InnerException.Message);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Analyze the project risks
RiskAnalyzer analyzer = new RiskAnalyzer(settings);
RiskAnalysisResult analysisResult = analyzer.Analyze(project);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Software Development Plan-1.mpp");
Task task = project.RootTask.Children.GetById(17);
// Initialize a risk pattern
RiskPattern pattern = new RiskPattern(task);
// Select a distribution type for the random number generator to generate possible values from (only two types currently supported, namely normal and uniform)
// For more details see here: https://en.wikipedia.org/wiki/Normal_distribution)
pattern.Distribution = ProbabilityDistributionType.Normal;
// Set the percentage of the most likely task duration which can happen in the best possible project scenario
// The default value is 75, which means that if the estimated specified task duration is 4 days then the optimistic duration will be 3 days
pattern.Optimistic = 70;
// Set the percentage of the most likely task duration which can happen in the worst possible project scenario
// The defaut value is 125, which means that if the estimated specified task duration is 4 days then the pessimistic duration will be 5 days.
pattern.Pessimistic = 130;
// Set a confidence level that correspond to the percentage of the time the actual values will be within optimistic and pessimistic estimates.
// You can think of it as a value of standard deviation: the more uncertain about your estimates you are, the more the value of standard deviation used in random number generator is
pattern.ConfidenceLevel = ConfidenceLevel.CL75;
settings.Patterns.Add(pattern);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
RiskAnalysisSettings settings = new RiskAnalysisSettings();
// Set number of iterations for Monte Carlo simulation (the default value is 100).
settings.IterationsCount = 200;
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Select the desired output (here we get early finish of the root task)
RiskItemStatistics rootEarlyFinish = analysisResult.GetRiskItems(RiskItemType.EarlyFinish).Get(project.RootTask);
Console.WriteLine("Expected value: {0}", rootEarlyFinish.ExpectedValue);
Console.WriteLine("StandardDeviation: {0}", rootEarlyFinish.StandardDeviation);
Console.WriteLine("10% Percentile: {0}", rootEarlyFinish.GetPercentile(10));
Console.WriteLine("50% Percentile: {0}", rootEarlyFinish.GetPercentile(50));
Console.WriteLine("90% Percentile: {0}", rootEarlyFinish.GetPercentile(90));
Console.WriteLine("Minimum: {0}", rootEarlyFinish.Minimum);
Console.WriteLine("Maximum: {0}", rootEarlyFinish.Maximum);
// Save PDF report which is rendered for Project Root Task Finish date
analysisResult.SaveReport(dataDir + "AnalysisReport_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Cyclic stucture.mpp");
project1.SaveReport(dataDir + "BestPracticeAnalyzer_out.pdf", ReportType.BestPracticeAnalyzer);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Homemoveplan.mpp");
project1.SaveReport(dataDir + "Burndown_out.pdf", ReportType.Burndown);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "OzBuild 16 Orig.mpp");
project1.SaveReport(dataDir + "CashFlow_out.pdf", ReportType.CashFlow);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Software Development.mpp");
project1.SaveReport(dataDir + "CostOverruns_out.pdf", ReportType.CostOverruns);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "OzBuild 16 Orig.mpp");
project1.SaveReport(dataDir + "CostOverview_out.pdf", ReportType.CostOverview);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Residential Construction.mpp");
project1.SaveReport(dataDir + "CriticalTasks_out.pdf", ReportType.CriticalTasks);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Residential Construction.mpp");
project1.SaveReport(dataDir + "LateTasks_out.pdf", ReportType.LateTasks);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Residential Construction.mpp");
project1.SaveReport(dataDir + "Milestones_out.pdf", ReportType.Milestones);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Software Development Plan.mpp");
project1.SaveReport(dataDir + "OverAllocatedResources_out.pdf", ReportType.OverallocatedResources);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Cyclic stucture.mpp");
project1.SaveReport(dataDir + "ProjectOverView_out.pdf", ReportType.ProjectOverview);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "OzBuild 16 Orig.mpp");
project1.SaveReport(dataDir + "ResourceCostOverview_out.pdf", ReportType.ResourceCostOverview);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Software Development Plan.mpp");
project1.SaveReport(dataDir + "ResourceOverview_out.pdf", ReportType.ResourceOverview);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Homemoveplan.mpp");
project1.SaveReport(dataDir + "SlippingTasks_out.pdf", ReportType.SlippingTasks);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Software Development.mpp");
project1.SaveReport(dataDir + "TaskCostOverview_out.pdf", ReportType.TaskCostOverview);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "UpcomingTasks.mpp");
project1.SaveReport(dataDir + "UpcomingTasks_out.pdf", ReportType.UpcomingTask);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Residential Construction.mpp");
project1.SaveReport(dataDir + "WorkOverview_out.pdf", ReportType.WorkOverview);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
private class RscNameComparer : IComparer<Resource>
{
public int Compare(Resource x, Resource y)
{
if (string.IsNullOrEmpty(x.Get(Rsc.Name)))
return 1;
if (string.IsNullOrEmpty(y.Get(Rsc.Name)))
return -1;
return x.Get(Rsc.Name).CompareTo(y.Get(Rsc.Name));
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "project-sort.mpp");
List<Resource> resources = project.Resources.ToList();
resources.Sort(new RscNameComparer());
foreach (Resource rsc in resources)
{
Console.WriteLine(rsc);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
private class TaskNameComparer : IComparer<Task>
{
public int Compare(Task x, Task y)
{
if (string.IsNullOrEmpty(x.Get(Tsk.Name)))
return 1;
if (string.IsNullOrEmpty(y.Get(Tsk.Name)))
return -1;
return x.Get(Tsk.Name).CompareTo(y.Get(Tsk.Name));
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "project-sort.mpp");
ChildTasksCollector coll = new ChildTasksCollector();
TaskUtils.Apply(project.RootTask, coll, 0);
List<Task> tasks = coll.Tasks;
tasks.Sort(new TaskNameComparer());
foreach (Task task in tasks)
{
Console.WriteLine(task);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "project.mpp");
// Define outline code and its outline mask
OutlineCodeDefinition code1 = new OutlineCodeDefinition();
code1.Alias = "New task outline code1";
code1.FieldId = ((int)ExtendedAttributeTask.OutlineCode1).ToString();
code1.FieldName = "Outline Code1";
OutlineMask mask = new OutlineMask();
mask.Separator = "+";
mask.Level = 1;
mask.Type = MaskType.Numbers;
code1.Masks.Add(mask);
// Add outline value
OutlineValue value = new OutlineValue();
value.Description = "Value description";
value.ValueId = 1;
value.Value = "123456";
value.Type = OutlineValueType.Number;
code1.Values.Add(value);
// Add outline code to project
project.OutlineCodes.Add(code1);
// Define outline code and its outline mask
OutlineCodeDefinition code2 = new OutlineCodeDefinition();
code2.Alias = "New rsc outline code2";
code2.FieldId = ((int)ExtendedAttributeResource.OutlineCode2).ToString();
code2.FieldName = "Outline Code2";
OutlineMask mask2 = new OutlineMask();
mask2.Separator = "/";
mask2.Level = 1;
mask2.Type = MaskType.Numbers;
code2.Masks.Add(mask2);
// Add outline value
OutlineValue value2 = new OutlineValue();
value2.Description = "Value2 description";
value2.ValueId = 2;
value2.Value = "987654";
value2.Type = OutlineValueType.Number;
code2.Values.Add(value2);
// Add outline code to project
project.OutlineCodes.Add(code2);
// Save project as MPP
project.Save(dataDir + "Updated_project_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Project1.mpp");
// Add working times to project calendar
WorkingTime wt = new WorkingTime();
wt.FromTime = new DateTime(2010, 1, 1, 19, 0, 0);
wt.ToTime = new DateTime(2010, 1, 1, 20, 0, 0);
WeekDay day = project.Get(Prj.Calendar).WeekDays.ToList()[1];
day.WorkingTimes.Add(wt);
// Change calendar name
project.Get(Prj.Calendar).Name = "CHANGED NAME!";
// Add tasks and set task meta data
Task task = project.RootTask.Children.Add("Task 1");
task.Set(Tsk.DurationFormat, TimeUnitType.Day);
task.Set(Tsk.Duration, project.GetDuration(3));
task.Set(Tsk.Contact, "Rsc 1");
task.Set(Tsk.IsMarked, true);
task.Set(Tsk.IgnoreWarnings, true);
Task task2 = project.RootTask.Children.Add("Task 2");
task2.Set(Tsk.DurationFormat, TimeUnitType.Day);
task2.Set(Tsk.Contact, "Rsc 2");
// Link tasks
project.TaskLinks.Add(task, task2, TaskLinkType.FinishToStart, project.GetDuration(-1, TimeUnitType.Day));
// Set project start date
project.Set(Prj.StartDate, new DateTime(2013, 8, 13, 9, 0, 0));
// Add resource and set resource meta data
Resource rsc1 = project.Resources.Add("Rsc 1");
rsc1.Set(Rsc.Type, ResourceType.Work);
rsc1.Set(Rsc.Initials, "WR");
rsc1.Set(Rsc.AccrueAt, CostAccrualType.Prorated);
rsc1.Set(Rsc.MaxUnits, 1);
rsc1.Set(Rsc.Code, "Code 1");
rsc1.Set(Rsc.Group, "Workers");
rsc1.Set(Rsc.EMailAddress, "[email protected]");
rsc1.Set(Rsc.WindowsUserAccount, "user_acc1");
rsc1.Set(Rsc.IsGeneric, new NullableBool(true));
rsc1.Set(Rsc.AccrueAt, CostAccrualType.End);
rsc1.Set(Rsc.StandardRate, 10);
rsc1.Set(Rsc.StandardRateFormat, RateFormatType.Day);
rsc1.Set(Rsc.OvertimeRate, 15);
rsc1.Set(Rsc.OvertimeRateFormat, RateFormatType.Hour);
rsc1.Set(Rsc.IsTeamAssignmentPool, true);
rsc1.Set(Rsc.CostCenter, "Cost Center 1");
// Create resource assignment and set resource assignment meta data
ResourceAssignment assn = project.ResourceAssignments.Add(task, rsc1);
assn.Set(Asn.Uid, 1);
assn.Set(Asn.Work, task.Get(Tsk.Duration));
assn.Set(Asn.RemainingWork, assn.Get(Asn.Work));
assn.Set(Asn.RegularWork, assn.Get(Asn.Work));
task.Set(Tsk.Work, assn.Get(Asn.Work));
rsc1.Set(Rsc.Work, task.Get(Tsk.Work));
assn.Set(Asn.Start, task.Get(Tsk.Start));
assn.Set(Asn.Finish, task.Get(Tsk.Finish));
// Add extended attribute for project and task
ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Flag, ExtendedAttributeTask.Flag1, "My Flag Field");
project.ExtendedAttributes.Add(attr);
ExtendedAttribute taskAttr = attr.CreateExtendedAttribute();
taskAttr.FlagValue = true;
task2.ExtendedAttributes.Add(taskAttr);
// Save project as MPP
project.Save(dataDir + "WriteMetaData_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project5.mpp"); // Create a new project task
Task task = project.RootTask.Children.Add("New Activity");
// Add custom text attribute to created task.
ExtendedAttribute attr = new ExtendedAttribute();
attr.FieldId = ((int)ExtendedAttributeTask.Text1).ToString();
attr.Value = "Activity attribute";
task.ExtendedAttributes.Add(attr);
// Customize table by adding text attribute field
TableField attrField = new TableField();
attrField.Field = Field.TaskText1;
attrField.Width = 20;
attrField.Title = "Custom attribute";
attrField.AlignTitle = StringAlignment.Center;
attrField.AlignData = StringAlignment.Center;
Table table = project.Tables.ToList()[0];
table.TableFields.Insert(3, attrField);
project.Save(dataDir + "ConfigureGantChart_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
try
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project5.mpp"); // Create a new project task
Task task = project.RootTask.Children.Add("New Activity");
// Add custom text attribute to created task.
ExtendedAttribute attr = new ExtendedAttribute();
attr.FieldId = ((int)ExtendedAttributeTask.Text1).ToString();
attr.Value = "Activity attribute";
task.ExtendedAttributes.Add(attr);
// Customize table by adding text attribute field
TableField attrField = new TableField();
attrField.Field = Field.TaskText1;
attrField.Width = 20;
attrField.Title = "Custom attribute";
attrField.AlignTitle = StringAlignment.Center;
attrField.AlignData = StringAlignment.Center;
Table table = project.Tables.ToList()[0];
table.TableFields.Insert(3, attrField);
project.Save(dataDir + "ConfigureTheGantChartViewShowSelectedColumnFields_out.mpp", SaveFileFormat.MPP);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project5.mpp");
project.TaskLinks.Add(project.RootTask.Children.Add("Task 1"), project.RootTask.Children.Add("Task 2"));
GanttChartView view = (GanttChartView)project.DefaultView;
view.MiddleTimescaleTier.Unit = TimescaleUnit.Months;
project.Set(Prj.TimescaleStart, new DateTime(2012, 8, 6));
view.MiddleTimescaleTier.DateTimeConverter =
date => new[] { "Янв.", "Фев.", "Мар.", "Апр.", "Май", "Июнь", "Июль", "Авг.", "Сен.", "Окт.", "Ноя.", "Дек." }[date.Month - 1];
project.Save(dataDir + "Result_out.pdf", SaveFileFormat.PDF);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
try
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
IDictionary<string, string> fileFormatExt = new Dictionary<string, string>();
fileFormatExt.Add(dataDir + "Image1", ".png");
fileFormatExt.Add(dataDir + "Document1", ".docx");
fileFormatExt.Add(dataDir + "Documennt1", ".xlsx");
Project project = new Project(dataDir + "Project1.mpp"); // see this test project attached to this issue
foreach (OleObject oleObject in project.OleObjects)
{
if (!string.IsNullOrEmpty(oleObject.FileFormat) && fileFormatExt.ContainsKey(oleObject.FileFormat))
{
string path = dataDir + "EmbeddedContent_out" + fileFormatExt[oleObject.FileFormat];
using (FileStream fileStream = new FileStream(path, FileMode.Create))
fileStream.Write(oleObject.Content, 0, oleObject.Content.Length);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp");
OleObject ole = project.OleObjects.ToList()[0];
// we have to check this property because it can be null if the embedded object was created inside the ms project application Or, alternatively, you can use this check: if (ole.FileFormat == "Package")
if (!string.IsNullOrEmpty(ole.FullPath))
{
using (FileStream fileStream = new FileStream(dataDir, FileMode.Create))
fileStream.Write(ole.Content, 0, ole.Content.Length);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = CreateTestProjectWithCustomField();
project.ExtendedAttributes[0].Formula = "[Critical]-[Marked]+4+[Active]-Not [Active]";
Task task = project.RootTask.Children.GetById(1);
Console.WriteLine("Formula with boolean values" + task.ExtendedAttributes[0].Value);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = CreateTestProjectWithCustomFieldWithoutResource();
project.ExtendedAttributes[0].Formula = "\"Total tasks: \" & [Task Count] & \" Total resources: \" & [Resource Count]";
Task task = project.RootTask.Children.GetById(1);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project();
project.CalculationMode = CalculationMode.Automatic;
project.Set(Prj.StartDate, new DateTime(2015, 4, 15));
Task task1 = project.RootTask.Children.Add("Task 1");
Task task2 = project.RootTask.Children.Add("Task 2");
TaskLink link = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
// Dates have been recalculated
Assert.AreEqual(task1.Get(Tsk.Start).AddDays(1), task2.Get(Tsk.Start), "Task 2 Start");
Assert.AreEqual(task1.Get(Tsk.Finish).AddDays(1), task2.Get(Tsk.Finish), "Task 2 Finish");
Assert.AreEqual(task2.Get(Tsk.Finish), project.RootTask.Get(Tsk.Finish), "RootTask Finish");
Assert.AreEqual(task2.Get(Tsk.Finish), project.Get(Prj.FinishDate), "Project Finish Date");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project();
project.CalculationMode = CalculationMode.Manual;
project.Set(Prj.StartDate, new DateTime(2015, 4, 15));
Task task1 = project.RootTask.Children.Add("Task 1");
Task task2 = project.RootTask.Children.Add("Task 2");
// The necessary properties are set in manual mode
Assert.AreEqual(1, task1.Get(Tsk.Id), "Task1 Id");
Assert.AreEqual(1, task1.Get(Tsk.OutlineLevel), "Task1 OutlineLevel");
Assert.AreEqual(new DateTime(2015, 4, 15, 8, 0, 0), task1.Get(Tsk.Start), "Task1 Start");
Assert.AreEqual(new DateTime(2015, 4, 15, 17, 0, 0), task1.Get(Tsk.Finish), "Task1 Finish");
Assert.AreEqual("1 day", task1.Get(Tsk.Duration).ToString(), "Task1 Duration");
// When we link two tasks together their dates are not recalculated in manual mode
TaskLink link = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
// Task 2 Start has not been changed
Assert.AreEqual(task1.Get(Tsk.Start), task2.Get(Tsk.Start), "Task 2 Start");
Assert.AreEqual(task1.Get(Tsk.Finish), task2.Get(Tsk.Finish), "Task 2 Finish");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project();
project.CalculationMode = CalculationMode.None;
Task task = project.RootTask.Children.Add("Task");
// note that even ids were not calculated
Assert.AreEqual(0, task.Get(Tsk.Id), "Task.Id");
Assert.AreEqual(0, task.Get(Tsk.OutlineLevel), "Task.OutlineLevel");
Assert.AreEqual(DateTime.MinValue, task.Get(Tsk.Start), "Task Start");
Assert.AreEqual(DateTime.MinValue, task.Get(Tsk.Finish), "Task Finish");
Assert.AreEqual("0 mins", task.Get(Tsk.Duration).ToString(), "Task Duration");
task.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));
// only duration property is set
Assert.AreEqual("2 days", task.Get(Tsk.Duration).ToString(), "Task Duration");
Assert.AreEqual(DateTime.MinValue, task.Get(Tsk.Start), "Task Start");
Assert.AreEqual(DateTime.MinValue, task.Get(Tsk.Finish), "Task Finish");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project proj = new Project(dataDir + "Project1.mpp"); // attached test mpp
ExtendedAttributeDefinition attr = proj.ExtendedAttributes[0];
Console.WriteLine("Attribute Formula: " + attr.Formula);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project();
ExtendedAttributeDefinition attribute = new ExtendedAttributeDefinition
{
FieldId = ((int) ExtendedAttributeTask.Text1).ToString(),
Formula = "[Cost]-[Actual Cost]"
};
project.ExtendedAttributes.Add(attribute);
Task task = project.RootTask.Children.Add("Task");
ExtendedAttribute extendedAttribute = attribute.CreateExtendedAttribute();
task.ExtendedAttributes.Add(extendedAttribute);
Console.WriteLine(extendedAttribute.ValueReadOnly == true ? "Value is Read only" : "Value is not read only");
extendedAttribute.Value = "Invalid";
Console.WriteLine(extendedAttribute.Value == string.Empty ? "Formula values are read-only" : "Values are not read-only");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp");
ImageSaveOptions options = new ImageSaveOptions(SaveFileFormat.TIFF);
options.HorizontalResolution = 72;
options.VerticalResolution = 72;
options.PixelFormat = PixelFormat.Format24bppRgb;
project.Save(dataDir + "RenderProjectDataToFormat24bppRgb_out.tif", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project();
GanttChartView view = new GanttChartView();
view.BottomTimescaleTier.Count = 2;
view.BottomTimescaleTier.ShowTicks = false; // Tick lines check box in MSP
view.MiddleTimescaleTier.Count = 2;
view.MiddleTimescaleTier.ShowTicks = false;
project.Views.Add(view);
// Add some test data to project
Task task1 = project.RootTask.Children.Add("Task 1");
Task task2 = project.RootTask.Children.Add("Task 2");
task1.Set(Tsk.Duration, task1.ParentProject.GetDuration(24, TimeUnitType.Hour));
task2.Set(Tsk.Duration, task1.ParentProject.GetDuration(40, TimeUnitType.Hour));
project.Save(dataDir + "SetTimeScaleCount_out.pdf", SaveFileFormat.PDF); // Result is in attached screenshot
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = CreateTestProjectWithCustomField();
ExtendedAttributeDefinition attr = project.ExtendedAttributes[0];
attr.Alias = "Task number fields";
attr.Formula = "([Outline Level] + [Priority] + [% Complete])/2";
Task task = project.RootTask.Children.GetById(1);
// (1 (Outline Level) + 500 (Priority) + 0 (% Complete) ) / 2
Console.WriteLine(task.ExtendedAttributes[0].Value);
task.Set(Tsk.PercentComplete, 50);
// (1 (Outline Level) + 500 (Priority) + 50 (% Complete) ) / 2
Console.WriteLine(task.ExtendedAttributes[0].Value);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = CreateTestProjectWithCustomField();
ExtendedAttributeDefinition attr = project.ExtendedAttributes[0];
attr.Alias = "Arithmetic Expression";
attr.Formula = "(1+3*(2+ -5)+8/2)^3";
Task task = project.RootTask.Children.GetById(1);
Console.WriteLine(task.ExtendedAttributes[0].Value);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project();
project.Set(Prj.StartDate, new DateTime(2015, 3, 6, 8, 0, 0));
ExtendedAttributeDefinition extendedAttributeDefinition = new ExtendedAttributeDefinition();
project.ExtendedAttributes.Add(extendedAttributeDefinition);
extendedAttributeDefinition.FieldId = ExtendedAttributeTask.Text1.ToString("D");
Task task = project.RootTask.Children.Add("Task");
ExtendedAttribute extendedAttribute = extendedAttributeDefinition.CreateExtendedAttribute();
task.ExtendedAttributes.Add(extendedAttribute);
Resource rsc = project.Resources.Add("Rsc");
ResourceAssignment assn = project.ResourceAssignments.Add(task, rsc);
ExtendedAttributeDefinition extendedAttributeDefinition1 = project.ExtendedAttributes[0];
extendedAttributeDefinition1.Alias = "Days from finish to deadline";
extendedAttributeDefinition1.Formula = "[Deadline] - [Finish]";
Task task1 = project.RootTask.Children.GetById(1);
task.Set(Tsk.Deadline, new DateTime(2015, 3, 20, 17, 0, 0));
project.Save(dataDir + "UsingTasksAndResourceFieldsInFormulaCalculations_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp");
project.Set(Prj.NewTasksAreManual, false);
// Create new custom field (Task Text1) with formula which will double task cost
ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition();
project.ExtendedAttributes.Add(attr);
attr.FieldId = ExtendedAttributeTask.Text1.ToString("D");
attr.Alias = "Double Costs";
attr.Formula = "[Cost]*2";
// Add a task to see the result in MSP, Set task cost and the result in the attached screenshot (result.jpg)
Task task = project.RootTask.Children.Add("Task");
task.Set(Tsk.Cost, 100);
project.Save(dataDir + "WriteFormulasInExtendedAttributesToMPPFileFormats_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp");
project.Save(dataDir + "ExportProjectDataToPrimaveraMPXFormat_out.xml", SaveFileFormat.MPX);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp");
project.Save(dataDir + "ExportProjectDataToXERFormat_out.mpp", SaveFileFormat.PrimaveraXER);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp");
project.Save(dataDir + "ExportProjectDataToXMLFormat_out.xml", SaveFileFormat.PrimaveraP6XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project("Primavera1.mpx");
ProjectFileInfo info = Project.GetProjectFileInfo("primavera1.mpx");
Console.WriteLine(info.ProjectFileFormat);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project.xml");
ProjectFileInfo info = Project.GetProjectFileInfo(dataDir + "Project.xml");
Console.WriteLine(info.ProjectFileFormat);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
DbSettings settings = new MpdSettings("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + dataDir + "MpdFileToRead.mpd", 1);
Project project = new Project(settings);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project("test.xml");
PrimaveraXmlOptions options = new PrimaveraXmlOptions();
options.SaveRootTask = false;
project.Save("test1.xml",options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Read the input Project file
Project project = new Project(dataDir + "Project2.mpp");
PrintOptions options = new PrintOptions();
options.Timescale = Timescale.ThirdsOfMonths;
if (project.GetPageCount(Timescale.ThirdsOfMonths) <= 280)
project.Print(options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Read the input Project file
Project project = new Project("ST_AV_AF_DEV_AFT_EMP.mpp");
PrintOptions options = new PrintOptions();
options.Timescale = Timescale.Months;
// Print first ten pages
PrinterSettings printerSettings = new PrinterSettings();
printerSettings.PrintRange = PrintRange.SomePages;
printerSettings.FromPage = 1;
printerSettings.ToPage = 10;
System.Drawing.Printing.PageSettings pageSettings = printerSettings.DefaultPageSettings;
pageSettings.PaperSize = new PaperSize(dataDir+ "Custom Size", 1000, 700);
project.Print(printerSettings, options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project2.mpp");
project.Set(Prj.StartDate, new DateTime(2014, 9, 22));
// By default project.DateFormat == DateFormat.Date_ddd_mm_dd_yy (Mon 09/22/14) customize DateFormat (September 22, 2014)
project.Set(Prj.DateFormat, DateFormat.DateMmmmDdYyyy);
project.Save(dataDir + "CustomizeDateFormats1_out.pdf", SaveFileFormat.PDF);
// Export to date format 19/07/2016
project.Set(Prj.DateFormat, DateFormat.DateDdMmYyyy);
project.Save(dataDir + "CustomizeDateFormats2_out.pdf", SaveFileFormat.PDF);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project5.mpp");
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFileFormat.PNG);
saveOptions.StartDate = project.Get(Prj.StartDate).AddDays(-3);
saveOptions.EndDate = project.Get(Prj.FinishDate);
saveOptions.MarkCriticalTasks = true;
saveOptions.LegendOnEachPage = false;
saveOptions.Gridlines = new List<Gridline>();
Gridline gridline = new Gridline();
gridline.GridlineType = GridlineType.GanttRow;
gridline.Color = Color.CornflowerBlue;
gridline.Pattern = LinePattern.Dashed;
saveOptions.Gridlines.Add(gridline);
// Save the whole project layout to one file
project.Save(dataDir + "CustomerFeedback1_out.png", saveOptions);
// Save project layout to separate files
saveOptions.SaveToSeparateFiles = true;
project.Save(dataDir + "CustomerFeedback2_out.png", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir+ "PrintTaskWritingException.mpp");
project.Save("project_out.MPP", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory
string dataDir = RunExamples.GetDataDir_Projects();
// Read the input Project file
Project project = new Project(dataDir + "Project2.mpp");
project.Print();
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
PrimaveraXmlReader reader = new PrimaveraXmlReader(dataDir + "Project.xml");
List<int> listOpProjectUids = reader.GetProjectUids();
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
PrimaveraXmlReadingOptions options = new PrimaveraXmlReadingOptions();
options.ProjectUid = 4557;
Project project = new Project(dataDir + "Project.xml", options); // returns project with special Uid
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project("Project1.mpp");
project.Save("project.xml", SaveFileFormat.Spreadsheet2003);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
const string connectionString = "SQLiteDatabaseConnectionString";
const int projectId = 4502;
PrimaveraDbSettings primaveraDbSettings = new PrimaveraDbSettings(connectionString, projectId);
primaveraDbSettings.ProviderInvariantName = "System.Data.SQLite";
Project project = new Project(primaveraDbSettings);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project("test.mpp");
XlsxOptions options = new XlsxOptions();
GanttChartColumn col = new GanttChartColumn("WBS", 100, delegate(Task task) { return task.Wbs; });
options.View.Columns.Add(col);
ResourceViewColumn rscCol = new ResourceViewColumn("Cost center", 100, delegate(Resource resource)
{ return resource.CostCenter; });
options.ResourceView.Columns.Add(rscCol);
AssignmentViewColumn assnCol = new AssignmentViewColumn("Notes", 200, delegate(ResourceAssignment assignment)
{ return assignment.Notes; });
options.AssignmentView.Columns.Add(assnCol);
project.Save("OpenXML.xlsx", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Spreadsheet2003SaveOptions options = new Spreadsheet2003SaveOptions();
GanttChartColumn col = new GanttChartColumn("WBS", 100, delegate(Task task) { return task.Wbs; });
options.View.Columns.Add(col);
ResourceViewColumn rscCol = new ResourceViewColumn("Cost center", 100,delegate(Resource resource)
{return resource.CostCenter;});
options.ResourceView.Columns.Add(rscCol);
AssignmentViewColumn assnCol = new AssignmentViewColumn("Notes", 200,delegate(ResourceAssignment assignment)
{return assignment.Notes;});
options.AssignmentView.Columns.Add(assnCol);
project.Save("project.xml", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Read the input Project file and get number of pages, Timescale.Months, Timescale.ThirdsOfMonths
Project project = new Project(dataDir + "GetNumberOfPages.mpp");
int iPages = project.GetPageCount();
iPages = project.GetPageCount(Timescale.Months);
iPages = project.GetPageCount(Timescale.ThirdsOfMonths);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
// Read the source Project and get number of pages, Months and ThirdsOfMonths
Project project = new Project(dataDir + "GetNumberOfPagesForViews.mpp");
Console.WriteLine(string.Format("Number of Pages = '{0}'", project.GetPageCount(PresentationFormat.ResourceUsage, Timescale.Days)));
Console.WriteLine(string.Format("Number of Pages = '{0}'", project.GetPageCount(PresentationFormat.ResourceUsage, Timescale.Months)));
Console.WriteLine(string.Format("Number of Pages = '{0}'", project.GetPageCount(PresentationFormat.ResourceUsage, Timescale.ThirdsOfMonths)));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp"); // attached test project
Console.WriteLine("Task Groups Count: " + project.TaskGroups.Count);
Group taskGroup = project.TaskGroups.ToList()[1];
Console.WriteLine("Percent Complete:", taskGroup.Name);
Console.WriteLine("Group Criteria count: " + taskGroup.GroupCriteria.Count);
Console.WriteLine("\n************* Retrieving Task Group's Criterion information *************");
GroupCriterion criterion = taskGroup.GroupCriteria.ToList()[0];
Console.WriteLine("Criterion Field: " + criterion.Field.ToString());
Console.WriteLine("Criterion GroupOn: " + criterion.GroupOn.ToString());
Console.WriteLine("Criterion Cell Color: " + criterion.CellColor);
Console.WriteLine("Criterion Pattern: " + criterion.Pattern.ToString());
if (taskGroup == criterion.ParentGroup)
Console.WriteLine("Parent Group is equval to task Group.");
Console.WriteLine("\n*********** Retreivnig Criterion's Font Information ***********");
Console.WriteLine("Font Name: " + criterion.Font.Name);
Console.WriteLine("Font Size: " + criterion.Font.Size);
Console.WriteLine("Font Style: " + criterion.Font.Style);
Console.WriteLine("Ascending/Dscending: " + criterion.Ascending);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "project.mpp");
foreach (OutlineCodeDefinition ocd in project.OutlineCodes)
{
Console.WriteLine("Alias = " + ocd.Alias);
if (ocd.AllLevelsRequired)
Console.WriteLine("It contains property: must have all levels");
else
Console.WriteLine("It does not contain property: must have all levels");
if (ocd.Enterprise)
Console.WriteLine("It is an enterprise custom outline code.");
else
Console.WriteLine("It is not an enterprise custom outline code.");
Console.WriteLine("Reference to another custom field for which this outline code definition is an alias is = " + ocd.EnterpriseOutlineCodeAlias);
Console.WriteLine("Field Id = " + ocd.FieldId);
Console.WriteLine("Field Name = " + ocd.FieldName);
Console.WriteLine("Phonetic Alias = " + ocd.PhoneticAlias);
Console.WriteLine("Guid = " + ocd.Guid);
// Display outline code masks
foreach (OutlineMask outlineMask in ocd.Masks)
{
Console.WriteLine("Level of a mask = " + outlineMask.Level);
Console.WriteLine("Mask = " + outlineMask.ToString());
}
// Display out line code values
foreach (OutlineValue outlineMask1 in ocd.Values)
{
Console.WriteLine("Description of outline value = " + outlineMask1.Description);
Console.WriteLine("Value Id = " + outlineMask1.ValueId);
Console.WriteLine("Value = " + outlineMask1.Value);
Console.WriteLine("Type = " + outlineMask1.Type);
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp"); // attached test project
GanttChartView view = project.Views.ToList()[1] as GanttChartView;
Console.WriteLine("Is Bar Rounding: " + view.BarRounding);
Console.WriteLine("Show Bar Splits? : " + view.ShowBarSplits);
Console.WriteLine("Show Drawings? : " + view.ShowDrawings);
Console.WriteLine("Roll Up Gantt Bars? " + view.RollUpGanttBars);
Console.WriteLine("Hide Rollup Bars When Summary Expanded: " + view.HideRollupBarsWhenSummaryExpanded);
Console.WriteLine("Bar Size: " + view.BarSize.ToString());
Console.WriteLine("Bar Style: " + view.BarStyles.Count);
Console.WriteLine("\n************************ RETREIVING BAR STYLES INFORMATION FROM THE VIEW *********************");
int i = 0;
foreach (GanttBarStyle barStyle in view.BarStyles)
{
Console.WriteLine("Name: " + barStyle.Name);
Console.WriteLine("ShowFor: " + barStyle.ShowFor.ToString());
Console.WriteLine("Row: " + barStyle.Row);
Console.WriteLine("From: " + barStyle.From);
Console.WriteLine("To: " + barStyle.To);
Console.WriteLine("MiddleShape: " + barStyle.MiddleShape);
Console.WriteLine("MiddleShapeColor: " + barStyle.MiddleShapeColor);
Console.WriteLine("StartShape: " + barStyle.StartShape);
Console.WriteLine("EndShape: " + barStyle.EndShape);
Console.WriteLine("EndShapeColor: " + barStyle.EndShapeColor);
i++;
}
Console.WriteLine("Grid Lines Count: " + view.Gridlines.Count);
Gridlines gridlines = view.Gridlines[0];
Console.WriteLine("\n************************ RETREIVING GRID LINES PROPERTIES *********************");
Console.WriteLine("GridLine Type: " + gridlines.Type);
Console.WriteLine("Gridlines Internval: " + gridlines.Interval);
Console.WriteLine("Gridlines Color: " + gridlines.NormalColor);
Console.WriteLine("Gridlines NormalPattern: " + gridlines.NormalPattern);
Console.WriteLine("Gridlines IntervalPattern: " + gridlines.IntervalPattern);
Console.WriteLine("Gridlines IntervalColor: " + gridlines.IntervalColor);
Console.WriteLine("\n************************ RETREIVING PROGRESS LINES PROPERTIES *********************");
Console.WriteLine("ProgressLInes.BeginAtDate: ", view.ProgressLines.BeginAtDate);
Console.WriteLine("ProgressLines.isBaselinePlan: " + view.ProgressLines.IsBaselinePlan);
Console.WriteLine("ProgressLines.DisplaySelected: " + view.ProgressLines.DisplaySelected);
Console.WriteLine("ProgressLines.SelectedDates.Count: " + view.ProgressLines.SelectedDates.Count);
Console.WriteLine("ProgressLines.SelectedDates[0]: " + view.ProgressLines.SelectedDates[0]);
Console.WriteLine("ProgressLines.SelectedDates[1]: " + view.ProgressLines.SelectedDates[1]);
Console.WriteLine("ProgressLines.SelectedDates[2]: " + view.ProgressLines.SelectedDates[2]);
Console.WriteLine("ProgressLines.DisplayAtRecurringIntervals: " + view.ProgressLines.DisplayAtRecurringIntervals);
Console.WriteLine("ProgressLines.RecurringInterval.Interval: " + Interval.Weekly, view.ProgressLines.RecurringInterval.Interval);
Console.WriteLine("ProgressLines.RecurringInterval.WeeklyDays.Count" + view.ProgressLines.RecurringInterval.WeeklyDays.Count);
Console.WriteLine("Recurring Interval.WeeklyDays: " + view.ProgressLines.RecurringInterval.WeeklyDays);
Console.WriteLine("Recurring Interval.DayType.Saturday: " + view.ProgressLines.RecurringInterval.WeeklyDays);
Console.WriteLine("Recurring Interval.DayType.Sunday: " + view.ProgressLines.RecurringInterval.WeeklyDays);
Console.WriteLine("ProgressLines.ShowDate: " + view.ProgressLines.ShowDate);
Console.WriteLine("ProgressLines.ProgressPointShape: " + view.ProgressLines.ProgressPointShape.ToString());
Console.WriteLine("ProgressLines.ProgressPointColor: " + view.ProgressLines.ProgressPointColor);
Console.WriteLine("ProgressLines.LineColor: " + Color.Red, view.ProgressLines.LineColor);
Console.WriteLine("ProgressLines.LinePattern: " + LinePattern.Solid, view.ProgressLines.LinePattern);
Console.WriteLine("ProgressLines.OtherProgressPointShape: " + view.ProgressLines.OtherProgressPointShape.ToString());
Console.WriteLine("ProgressLines.OtherProgressPointColor: " + view.ProgressLines.OtherProgressPointColor.ToString());
Console.WriteLine("ProgressLines.OtherLineColor: " + view.ProgressLines.OtherLineColor);
Console.WriteLine("\n************************ BOTTOM TIMESCALE IFORMATION ******************");
Console.WriteLine("BottomTimescaleTier.Count:" + view.BottomTimescaleTier.Count);
Console.WriteLine("BottomTimescaleTier.Unit:" + TimescaleUnit.Days, view.BottomTimescaleTier.Unit.ToString());
Console.WriteLine("BottomTimescaleTier.UsesFiscalYear: " + view.BottomTimescaleTier.UsesFiscalYear);
Console.WriteLine("BottomTimescaleTier.Alignment: " + StringAlignment.Center, view.BottomTimescaleTier.Alignment.ToString());
Console.WriteLine("BottomTimescaleTier.ShowTicks: " + view.BottomTimescaleTier.ShowTicks.ToString());
Console.WriteLine("BottomTimescaleTier.Label:" + DateLabel.Day_di, view.BottomTimescaleTier.Label);
Console.WriteLine("\n************************ MIDDLE TIMESCALE IFORMATION ******************");
Console.WriteLine("MiddleTimescaleTier.Count:" + view.MiddleTimescaleTier.Count);
Console.WriteLine("MiddleTimescaleTier.Unit:" + TimescaleUnit.Days, view.MiddleTimescaleTier.Unit.ToString());
Console.WriteLine("MiddleTimescaleTier.UsesFiscalYear: " + view.MiddleTimescaleTier.UsesFiscalYear);
Console.WriteLine("MiddleTimescaleTier.Alignment: " + StringAlignment.Center, view.MiddleTimescaleTier.Alignment.ToString());
Console.WriteLine("MiddleTimescaleTier.ShowTicks: " + view.MiddleTimescaleTier.ShowTicks.ToString());
Console.WriteLine("MiddleTimescaleTier.Label:" + DateLabel.Day_di, view.MiddleTimescaleTier.Label);
Console.WriteLine("\n************************ TOP TIMESCALE IFORMATION ******************");
Console.WriteLine("TopTimescaleTier.Unit:" + TimescaleUnit.Days, view.TopTimescaleTier.Unit.ToString());
Console.WriteLine("TopTimescaleTier.UsesFiscalYear: " + view.TopTimescaleTier.UsesFiscalYear);
Console.WriteLine("TopTimescaleTier.Alignment: " + StringAlignment.Center, view.TopTimescaleTier.Alignment.ToString());
Console.WriteLine("TopTimescaleTier.ShowTicks: " + view.TopTimescaleTier.ShowTicks.ToString());
Console.WriteLine("TopTimescaleTier.Label: ", view.TopTimescaleTier.Label.ToString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "Project1.mpp");
Table task1 = project.Tables.ToList()[0];
Console.WriteLine("Table Fields Count" + task1.TableFields.Count);
TableField tableField = task1.TableFields[0];
Console.WriteLine("Field width: " + tableField.Width);
Console.WriteLine("Field Title: " + tableField.Title);
Console.WriteLine("Field Title Alignment: " + tableField.AlignTitle.ToString());
Console.WriteLine("Field Align Data: " + tableField.AlignData.ToString());
tableField = task1.TableFields[1];
Console.WriteLine("Field width: " + tableField.Width);
Console.WriteLine("Field Title: " + tableField.Title);
Console.WriteLine("Field Title Alignment: " + tableField.AlignTitle.ToString());
Console.WriteLine("Field Align Data: " + tableField.AlignData.ToString());
tableField = task1.TableFields[2];
Console.WriteLine("Field width: " + tableField.Width);
Console.WriteLine("Field Title: " + tableField.Title);
Console.WriteLine("Field Title Alignment: " + tableField.AlignTitle.ToString());
Console.WriteLine("Field Align Data: " + tableField.AlignData.ToString());
tableField = task1.TableFields[3];
Console.WriteLine("Field width: " + tableField.Width);
Console.WriteLine("Field Title: " + tableField.Title);
Console.WriteLine("Field Title Alignment: " + tableField.AlignTitle.ToString());
Console.WriteLine("Field Align Data: " + tableField.AlignData.ToString());
tableField = task1.TableFields[4];
Console.WriteLine("Field width: " + tableField.Width);
Console.WriteLine("Field Title: " + tableField.Title);
Console.WriteLine("Field Title Alignment: " + tableField.AlignTitle.ToString());
Console.WriteLine("Field Align Data: " + tableField.AlignData.ToString());
tableField = task1.TableFields[5];
Console.WriteLine("Field width: " + tableField.Width);
Console.WriteLine("Field Title: " + tableField.Title);
Console.WriteLine("Field Title Alignment: " + tableField.AlignTitle.ToString());
Console.WriteLine("Field Align Data: " + tableField.AlignData.ToString());
tableField = task1.TableFields[6];
Console.WriteLine("Field width: " + tableField.Width);
Console.WriteLine("Field Title: " + tableField.Title);
Console.WriteLine("Field Title Alignment: " + tableField.AlignTitle.ToString());
Console.WriteLine("Field Align Data: " + tableField.AlignData.ToString());
tableField = task1.TableFields[7];
Console.WriteLine("Field width: " + tableField.Width);
Console.WriteLine("Field Title: " + tableField.Title);
Console.WriteLine("Field Title Alignment: " + tableField.AlignTitle.ToString());
Console.WriteLine("Field Align Data: " + tableField.AlignData.ToString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
using (FileStream fs = new FileStream(dataDir + "project_test.mpp", FileMode.Open))
{
// Create project instance
Project prj = new Project(fs);
// Remove an exception
Aspose.Tasks.Calendar cal = prj.Calendars.ToList()[0];
if (cal.Exceptions.Count > 1)
{
CalendarException exc = cal.Exceptions.ToList()[0];
cal.Exceptions.Remove(exc);
}
// Add an exception
CalendarException calExc = new CalendarException();
calExc.FromDate = new System.DateTime(2009, 1, 1);
calExc.ToDate = new System.DateTime(2009, 1, 3);
cal.Exceptions.Add(calExc);
// Display exceptions
foreach (CalendarException calExc1 in cal.Exceptions)
{
Console.WriteLine("From" + calExc1.FromDate.ToShortDateString());
Console.WriteLine("To" + calExc1.ToDate.ToShortDateString());
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create a project instance
Project prj = new Project();
// Define Calendar
Aspose.Tasks.Calendar cal = prj.Calendars.Add("Calendar1");
// Define week days exception for a holiday
CalendarException except = new CalendarException();
except.EnteredByOccurrences = false;
except.FromDate = new DateTime(2009, 12, 24, 0, 0, 0);
except.ToDate = new DateTime(2009, 12, 31, 23, 59, 0);
except.Type = CalendarExceptionType.Daily;
except.DayWorking = false;
cal.Exceptions.Add(except);
// Save the Project
prj.Save(dataDir + "Project_DefineWeekDayException_out.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Define exception and specify occurences
CalendarException except = new CalendarException();
except.EnteredByOccurrences = true;
except.Occurrences = 5;
except.Type = CalendarExceptionType.YearlyByDay;
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create project instance
Project project1 = new Project(dataDir + "project_RetrieveExceptions_test.mpp");
// Access calendars
foreach (Aspose.Tasks.Calendar cal in project1.Calendars)
{
// Access calendar exceptions
foreach (CalendarException calExc in cal.Exceptions)
{
Console.WriteLine("From: " + calExc.FromDate.ToShortDateString());
Console.WriteLine("To: " + calExc.ToDate.ToShortDateString());
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Load an existing project
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "CalculateWorkHours.mpp");
// Access Task By Id
Task task = project.RootTask.Children.GetById(1);
// Access Calendar and it's start and end dates
Aspose.Tasks.Calendar taskCalendar = task.Get(Tsk.Calendar);
DateTime startDate = task.Get(Tsk.Start);
DateTime endDate = task.Get(Tsk.Finish);
DateTime tempDate = startDate;
// Access resource and their calendar
Resource resource = project.Resources.GetByUid(1);
Aspose.Tasks.Calendar resourceCalendar = resource.Get(Rsc.Calendar);
TimeSpan timeSpan;
// Get Duration in Minutes
double durationInMins = 0;
while (tempDate < endDate)
{
if (taskCalendar.IsDayWorking(tempDate) && resourceCalendar.IsDayWorking(tempDate))
{
timeSpan = taskCalendar.GetWorkingHours(tempDate);
durationInMins = durationInMins + timeSpan.TotalMinutes;
}
tempDate = tempDate.AddDays(1);
}
tempDate = startDate;
// Get Duration in Hours
double durationInHours = 0;
while (tempDate < endDate)
{
if (taskCalendar.IsDayWorking(tempDate) && resourceCalendar.IsDayWorking(tempDate))
{
timeSpan = taskCalendar.GetWorkingHours(tempDate);
durationInHours = durationInHours + timeSpan.TotalHours;
}
tempDate = tempDate.AddDays(1);
}
tempDate = startDate;
// Get Duration in Days
double durationInDays = 0;
while (tempDate < endDate)
{
if (taskCalendar.IsDayWorking(tempDate) && resourceCalendar.IsDayWorking(tempDate))
{
timeSpan = taskCalendar.GetWorkingHours(tempDate);
if (timeSpan.TotalHours > 0)
durationInDays = durationInDays + timeSpan.TotalDays * (24 / (timeSpan.TotalHours));
}
tempDate = tempDate.AddDays(1);
}
Console.WriteLine("Duration in Minutes = " + durationInMins);
Console.WriteLine("Duration in Hours = " + durationInHours);
Console.WriteLine("Duration in Days = " + durationInDays);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create a project instance and define Calendar
Project project = new Project();
Aspose.Tasks.Calendar cal1 = project.Calendars.Add("New Info");
Aspose.Tasks.Calendar cal2 = project.Calendars.Add("no name");
Aspose.Tasks.Calendar cal3 = project.Calendars.Add("cal3");
// Save the Project
string dataDir = RunExamples.GetDataDir_Projects();
project.Save(dataDir + "Project.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create a project instance
Project project = new Project();
// New calendar can be added to a project's calendar collection using the collection's Add method.
Aspose.Tasks.Calendar cal1 = project.Calendars.Add("New Info");
Aspose.Tasks.Calendar cal2 = project.Calendars.Add("no name");
Aspose.Tasks.Calendar cal3 = project.Calendars.Add("cal3");
// Save the Project
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
project.Save(dataDir + "CreatingCalendar_out.Xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// This example shows how Aspose.Tasks API can be used to define a new Calendar, add week days to it and define working times for days
// Create a project instance
Project project = new Project();
// Define Calendar
Aspose.Tasks.Calendar cal = project.Calendars.Add("Calendar1");
// Add working days monday through thursday with default timings
cal.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Monday));
cal.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Tuesday));
cal.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Wednesday));
cal.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Thursday));
cal.WeekDays.Add(new WeekDay(DayType.Saturday));
cal.WeekDays.Add(new WeekDay(DayType.Sunday));
// Set friday as short working day
WeekDay myWeekDay = new WeekDay(DayType.Friday);
// Sets working time. Only time part of DateTime is important
WorkingTime wt1 = new WorkingTime();
wt1.FromTime = new DateTime(1, 1, 1, 9, 0, 0, 0);
wt1.ToTime = new DateTime(1, 1, 1, 12, 0, 0, 0);
WorkingTime wt2 = new WorkingTime();
wt2.FromTime = new DateTime(1, 1, 1, 13, 0, 0, 0);
wt2.ToTime = new DateTime(1, 1, 1, 16, 0, 0, 0);
myWeekDay.WorkingTimes.Add(wt1);
myWeekDay.WorkingTimes.Add(wt2);
myWeekDay.DayWorking = true;
cal.WeekDays.Add(myWeekDay);
// Save the Project
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
project.Save("Project_DefineCalendarWeekdays_out.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create a project instance
Project project = new Project();
// Define Calendar and make it standard
Aspose.Tasks.Calendar cal1 = project.Calendars.Add("My Cal");
Aspose.Tasks.Calendar.MakeStandardCalendar(cal1);
// Save the Project
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
project.Save(dataDir + "Project_MakeStandardCalendar_out.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "ReplaceCalendar.mpp");
// Add a new calendar to the project's calendars collection
project.Calendars.Add("New cal1", project.Get(Prj.Calendar));
// Now traverse through project calendars and replace the already added calendar with a new one
CalendarCollection calColl = project.Calendars;
foreach (Calendar c in calColl)
{
if (c.Name == "New cal1")
{
calColl.Remove(c);
calColl.Add("New cal2", project.Get(Prj.Calendar));
break;
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project
Project project = new Project(dataDir + "Project5.mpp");
// Access project calendars
CalendarCollection calColl = project.Calendars;
foreach (Calendar myCalendar in calColl)
{
if (myCalendar.Name == "TestCalendar")
{
// Remove calendar
calColl.Remove(myCalendar);
}
}
// Add new calendar
Calendar newCalendar = calColl.Add("TestCalendar");
project.Save(dataDir + "ReplaceCalendar_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
string resultFile = "result_WriteUpdatedCalendarDataToMPP_out.mpp";
string newFile = "project_update_test.mpp";
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
try
{
// Create project instance and access calendar
Project project = new Project(dataDir + newFile);
Calendar cal = project.Calendars.GetByUid(3);
// Update the calendar information
Calendar.MakeStandardCalendar(cal);
cal.Name = "Test calendar";
CalendarException exc = new CalendarException();
exc.FromDate = DateTime.Now;
exc.ToDate = DateTime.Now.AddDays(2);
exc.DayWorking = true;
WorkingTime wt1 = new WorkingTime();
wt1.FromTime = new DateTime(10, 1, 1, 9, 0, 0);
wt1.ToTime = new DateTime(10, 1, 1, 13, 0, 0);
WorkingTime wt2 = new WorkingTime();
wt2.FromTime = new DateTime(10, 1, 1, 14, 0, 0);
wt2.ToTime = new DateTime(10, 1, 1, 19, 0, 0);
WorkingTime wt3 = new WorkingTime();
wt3.FromTime = new DateTime(10, 1, 1, 20, 0, 0);
wt3.ToTime = new DateTime(10, 1, 1, 21, 0, 0);
exc.WorkingTimes.Add(wt1);
exc.WorkingTimes.Add(wt2);
exc.WorkingTimes.Add(wt3);
cal.Exceptions.Add(exc);
CalendarException exc2 = new CalendarException();
exc2.FromDate = DateTime.Now.AddDays(7);
exc2.ToDate = exc2.FromDate;
exc2.DayWorking = false;
cal.Exceptions.Add(exc2);
project.Set(Prj.Calendar, cal);
// Save project
project.Save(dataDir + resultFile, SaveFileFormat.MPP);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create a project instance and define Calendar
Project project = new Project();
Aspose.Tasks.Calendar cal = project.Calendars.Add("Calendar1");
// Add working days monday through thursday with default timings
cal.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Monday));
cal.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Tuesday));
cal.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Wednesday));
cal.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Thursday));
cal.WeekDays.Add(new WeekDay(DayType.Saturday));
cal.WeekDays.Add(new WeekDay(DayType.Sunday));
// Set friday as short working day
WeekDay myWeekDay = new WeekDay(DayType.Friday);
// Sets working time. Only time part of DateTime is important
WorkingTime wt1 = new WorkingTime();
wt1.FromTime = new DateTime(1, 1, 1, 9, 0, 0, 0);
wt1.ToTime = new DateTime(1, 1, 1, 12, 0, 0, 0);
WorkingTime wt2 = new WorkingTime();
wt2.FromTime = new DateTime(1, 1, 1, 13, 0, 0, 0);
wt2.ToTime = new DateTime(1, 1, 1, 16, 0, 0, 0);
myWeekDay.WorkingTimes.Add(wt1);
myWeekDay.WorkingTimes.Add(wt2);
myWeekDay.DayWorking = true;
cal.WeekDays.Add(myWeekDay);
// Save the Project
string dataDir = RunExamples.GetDataDir_Projects();
project.Save("Project.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Load an existing project
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Project_GeneralCalendarProperties.xml");
foreach (Aspose.Tasks.Calendar cal in project.Calendars)
{
if (cal.Name != null)
{
Console.WriteLine("UID : " + cal.Uid.ToString() + " Name: " + cal.Name);
// Show if it is has a base calendar
Console.Write("Base Calendar : ");
if (cal.IsBaseCalendar)
Console.WriteLine("Self");
else
Console.WriteLine(cal.BaseCalendar.Name);
// Get Time in hours on each working day
foreach (WeekDay wd in cal.WeekDays)
{
TimeSpan ts = wd.GetWorkingTime();
Console.WriteLine("Day Type: " + wd.DayType.ToString() + " Hours: " + ts.ToString());
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create a project instance, Define Calendar and make it standard, Make this calendar as a standard calendar and save the Project
Project project = new Project();
Aspose.Tasks.Calendar cal1 = project.Calendars.Add("My Cal");
Aspose.Tasks.Calendar.MakeStandardCalendar(cal1);
string dataDir = RunExamples.GetDataDir_Projects();
project.Save("Project.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create project instance and access calendar and work weeks collection
Project project = new Project(dataDir + "ReadWorkWeeksInformation.mpp");
Calendar calendar = project.Calendars.GetByUid(3);
WorkWeekCollection collection = calendar.WorkWeeks;
foreach (WorkWeek workWeek in collection)
{
// Display work week name, from and to dates
string Name = workWeek.Name;
DateTime fromDate = workWeek.FromDate;
DateTime toDate = workWeek.ToDate;
// This data is all about "Details." button you can set special working times for special WeekDay or even make it nonworking
WeekDayCollection weekDays = workWeek.WeekDays;
foreach (WeekDay day in weekDays)
{
// You can further traverse through working times and display these
WorkingTimeCollection workingTimes = day.WorkingTimes;
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create a project instance
Project project = new Project(dataDir + "RetrieveCalendarInfo.mpp");
// Retrieve Calendars Information
CalendarCollection alCals = project.Calendars;
foreach (Calendar cal in alCals)
{
if (cal.Name != null)
{
Console.WriteLine("Calendar UID : " + cal.Uid);
Console.WriteLine("Calendar Name : " + cal.Name);
WeekDayCollection alDays = cal.WeekDays;
foreach (WeekDay wd in alDays)
{
TimeSpan ts = wd.GetWorkingTime();
if (wd.DayWorking)
{
Console.WriteLine(wd.DayType.ToString() + ":");
Console.WriteLine(ts.ToString());
}
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
string resultFile = "OutputMPP.mpp";
string newFile = "SampleMPP.mpp";
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + newFile);
Calendar cal = project.Calendars.GetByUid(3);
// Update the calendar information
Calendar.MakeStandardCalendar(cal);
cal.Name = "Test calendar";
CalendarException exc = new CalendarException();
exc.FromDate = DateTime.Now;
exc.ToDate = DateTime.Now.AddDays(2);
exc.DayWorking = true;
WorkingTime wt1 = new WorkingTime();
wt1.FromTime = new DateTime(10, 1, 1, 9, 0, 0);
wt1.ToTime = new DateTime(10, 1, 1, 13, 0, 0);
WorkingTime wt2 = new WorkingTime();
wt2.FromTime = new DateTime(10, 1, 1, 14, 0, 0);
wt2.ToTime = new DateTime(10, 1, 1, 19, 0, 0);
WorkingTime wt3 = new WorkingTime();
wt3.FromTime = new DateTime(10, 1, 1, 20, 0, 0);
wt3.ToTime = new DateTime(10, 1, 1, 21, 0, 0);
exc.WorkingTimes.Add(wt1);
exc.WorkingTimes.Add(wt2);
exc.WorkingTimes.Add(wt3);
cal.Exceptions.Add(exc);
CalendarException exc2 = new CalendarException();
exc2.FromDate = DateTime.Now.AddDays(7);
exc2.ToDate = exc2.FromDate;
exc2.DayWorking = false;
cal.Exceptions.Add(exc2);
project.Set(Prj.Calendar, cal);
project.Save(dataDir + resultFile, SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "project.mpp");
Console.WriteLine(project1.Get(Prj.CurrencyCode));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "project.mpp");
Console.WriteLine(project1.Get(Prj.CurrencyDigits));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "project.mpp");
Console.WriteLine(project1.Get(Prj.CurrencySymbol));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create new project and set currency code
Project project1 = new Project();
project1.Set(Prj.CurrencyCode, "USD");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create new project and set currency digits
Project project1 = new Project();
project1.Set(Prj.CurrencyDigits, 2);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create new project and set currency symbol
Project project1 = new Project();
project1.Set(Prj.CurrencySymbol, "$$");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create new project and extended attribute definition
Project project = new Project();
ExtendedAttributeDefinition attribute = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Cost, ExtendedAttributeTask.Cost1, "");
attribute.Formula = "[Cost]-[Actual Cost]";
project.ExtendedAttributes.Add(attribute);
// Add task
Task task = project.RootTask.Children.Add("Task");
// Create extended attribute
ExtendedAttribute extendedAttribute = attribute.CreateExtendedAttribute();
task.ExtendedAttributes.Add(extendedAttribute);
// Display if extended attributes are read only or not
Console.WriteLine(extendedAttribute.ValueReadOnly == true ? "Value is Read only" : "Value is not read only");
extendedAttribute.NumericValue = -1000000M;
Console.WriteLine(extendedAttribute.NumericValue == -1000000M ? "Formula values are read-only" : "Values are not read-only");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = CreateTestProject();
Task task = project.RootTask.Children.GetById(1);
ExtendedAttributeDefinition numberDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Number1, null);
project.ExtendedAttributes.Add(numberDefinition);
ExtendedAttribute numberAttribute = numberDefinition.CreateExtendedAttribute();
task.ExtendedAttributes.Add(numberAttribute);
// Set ProjDateDiff formula and print extended attribute value
numberDefinition.Formula = "ProjDateDiff(\"03/23/2015\",\"03/18/2015\")";
Console.WriteLine(numberAttribute.NumericValue);
numberDefinition.Formula = "ProjDateDiff(\"03/23/2015\",\"03/25/2015\")";
Console.WriteLine(numberAttribute.NumericValue);
ExtendedAttributeDefinition dateDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Date1, null);
project.ExtendedAttributes.Add(dateDefinition);
ExtendedAttribute dateAttribute = dateDefinition.CreateExtendedAttribute();
task.ExtendedAttributes.Add(dateAttribute);
// Set ProjDateSub formula and print extended attribute value
dateDefinition.Formula = "ProjDateSub(\"3/19/2015\", \"1d\")";
Console.WriteLine(dateAttribute.DateValue);
// Set ProjDurConv formula and print entended attribute value
numberDefinition.Formula = "ProjDurConv([Duration], pjHours)";
Console.WriteLine(numberAttribute.Value);
numberDefinition.Formula = "ProjDurConv([Duration], pjWeeks)";
Console.WriteLine(numberAttribute.Value);
// Set Second formula and print entended attribute value
numberDefinition.Formula = "Second(\"4/21/2015 2:53:41 AM\")";
Console.WriteLine(numberAttribute.NumericValue);
// Set Weekday formula and print entended attribute value
numberDefinition.Formula = "Weekday(\"24/3/2015\", 1)";
Console.WriteLine(numberAttribute.NumericValue);
numberDefinition.Formula = "Weekday(\"24/3/2015\", 2)";
Console.WriteLine(numberAttribute.NumericValue);
numberDefinition.Formula = "Weekday(\"24/3/2015\", 3)";
Console.WriteLine(numberAttribute.NumericValue);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
public static void EvaluateChoose()
{
Project project = CreateTestProjectWithCustomField();
// Set Formula
project.ExtendedAttributes[0].Formula = "Choose(3, \"This is a\", \"right\", \"choice\")";
// Print extended attribute value
Task task = project.RootTask.Children.GetById(1);
Console.WriteLine(task.ExtendedAttributes[0].Value);
}
public static void EvaluateIsNumeric()
{
string[] numericFormulas = { "IsNUmeric(1)", "IsNumeric(1<0)", "IsNumeric(\"1.1\")", "IsNumeric(Choose((2 + Sgn(2^-3)), 123, \"one two three\"))" };
Project project = CreateTestProjectWithCustomField();
foreach (string numericFormula in numericFormulas)
{
// Set Formula
project.ExtendedAttributes[0].Formula = numericFormula;
// Print extended attribute value
Task task = project.RootTask.Children.GetById(1);
Console.WriteLine(task.ExtendedAttributes[0].Value);
}
}
public static void EvaluateSwitch()
{
Project project = CreateTestProjectWithCustomField();
// Set Formula
project.ExtendedAttributes[0].Formula = "Switch(False, \"False predicate\", true, \"True predicate\")";
// Print extended attribute value
Task task = project.RootTask.Children.GetById(1);
Console.WriteLine(task.ExtendedAttributes[0].Value);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
public static void EvaluateSine()
{
Project project = CreateTestProjectWithCustomField();
// Set formula Sin(pi/2)
project.ExtendedAttributes[0].Formula = "Sin(3.1415926/2)";
// Print Calculated value
Task task = project.RootTask.Children.GetById(1);
Console.WriteLine("Sin(pi/2): {0}", task.ExtendedAttributes[0].NumericValue);
}
public static Project CreateTestProjectWithCustomField()
{
Project project = new Project();
ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Number, ExtendedAttributeTask.Number1, "Sine");
project.ExtendedAttributes.Add(attr);
Task task = project.RootTask.Children.Add("Task");
ExtendedAttribute a = attr.CreateExtendedAttribute();
task.ExtendedAttributes.Add(a);
return project;
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
public static void EvaluateStrConv()
{
Project project = CreateTestProjectWithCustomField();
Task task = project.RootTask.Children.GetById(1);
// Set formulas and print extended attribute value
project.ExtendedAttributes[0].Formula = "StrConv(\"sTring and sTRINg\",3)";
Console.WriteLine(task.ExtendedAttributes[0].Value);
project.ExtendedAttributes[0].Formula = "StrConv(\"sTring and sTRINg\",1)";
Console.WriteLine(task.ExtendedAttributes[0].Value);
project.ExtendedAttributes[0].Formula = "StrConv(\"sTring and sTRINg\",2)";
Console.WriteLine(task.ExtendedAttributes[0].Value);
}
public static void EvaluateStringFunction()
{
Project project = CreateTestProjectWithCustomField();
Task task = project.RootTask.Children.GetById(1);
// Set formulas and print extended attribute value
project.ExtendedAttributes[0].Formula = "String(5, 40)";
Console.WriteLine(task.ExtendedAttributes[0].Value);
project.ExtendedAttributes[0].Formula = "String(5, \"A\")";
Console.WriteLine(task.ExtendedAttributes[0].Value);
project.ExtendedAttributes[0].Formula = "String(-5, \"A\")";
// #Error
Console.WriteLine(task.ExtendedAttributes[0].Value);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = CreateTestProjectWithCustomField();
// Set formula for extended attribute
project.ExtendedAttributes[0].Formula = "[Critical]-[Marked]+4+[Active]-Not [Active]";
// Print value of extened attribute
Task task = project.RootTask.Children.GetById(1);
Console.WriteLine("Formula with boolean values: " + task.ExtendedAttributes[0].Value);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
public static void Run()
{
Project project = CreateTestProjectWithCustomFieldWithoutResource();
// Set formula
project.ExtendedAttributes[0].Formula = "\"Total tasks: \" & [Task Count] & \" Total resources: \" & [Resource Count]";
// Print if formula value is computed correctly
Task task = project.RootTask.Children.GetById(1);
Console.WriteLine("Check Total tasks: 1 Total resources: 0 - {0}", task.ExtendedAttributes[0].Value.Equals("Total tasks: 1 Total resources: 0"));
}
static Project CreateTestProjectWithCustomFieldWithoutResource()
{
Project project = new Project();
project.Set(Prj.StartDate, new DateTime(2015, 3, 6, 8, 0, 0));
ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Custom");
project.ExtendedAttributes.Add(attr);
Task task = project.RootTask.Children.Add("Task");
ExtendedAttribute a = attr.CreateExtendedAttribute();
task.ExtendedAttributes.Add(a);
return project;
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
// Create project instance
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project1 = new Project(dataDir + "ReadFormulas.mpp"); // Attached test mpp
// Read extended attribute formula
ExtendedAttributeDefinition attr = project1.ExtendedAttributes[0];
Console.WriteLine("Attribute Formula: " + attr.Formula);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = CreateTestProjectWithCustomField();
// Set arithmetic formula for extended attribute
ExtendedAttributeDefinition attr = project.ExtendedAttributes[0];
attr.Alias = "Arithmetic Expression";
attr.Formula = "(1+3*(2+ -5)+8/2)^3";
// Display extended attribute value
Task task = project.RootTask.Children.GetById(1);
Console.WriteLine(task.ExtendedAttributes[0].NumericValue);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = CreateTestProjectWithCustomField();
// Set formula
ExtendedAttributeDefinition attr = project.ExtendedAttributes[0];
attr.Alias = "Task number fields";
attr.Formula = "([Outline Level] + [Priority] + [% Complete])/2";
Task task = project.RootTask.Children.GetById(1);
// Print extended attribute value before and after updating task percent complete
Console.WriteLine(task.ExtendedAttributes[0].NumericValue);
task.Set(Tsk.PercentComplete, 50);
Console.WriteLine(task.ExtendedAttributes[0].NumericValue);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
public static void Run()
{
try
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = CreateTestProjectWithCustomField();
Task task = project.RootTask.Children.GetById(1);
// Set formula for extended attribute
ExtendedAttributeDefinition extendedAttributeDefinition1 = project.ExtendedAttributes[0];
extendedAttributeDefinition1.Alias = "Days from finish to deadline";
extendedAttributeDefinition1.Formula = "[Deadline] - [Finish]";
// Set Task Deadline and save project
Task task1 = project.RootTask.Children.GetById(1);
task.Set(Tsk.Deadline, new DateTime(2015, 3, 20, 17, 0, 0));
project.Save(dataDir + "project_UsingTasksAndResourceFields_out.mpp", SaveFileFormat.MPP);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
}
}
// Helper method to create project
private static Project CreateTestProjectWithCustomField()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create new project instance
Project project = new Project(dataDir + "Blank2010.mpp");
project.Set(Prj.StartDate, new DateTime(2015, 3, 6, 8, 0, 0));
// Add new task with extended attribute
Task task = project.RootTask.Children.Add("Task");
ExtendedAttributeDefinition extendedAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text5, "My Ext Attr");
project.ExtendedAttributes.Add(extendedAttributeDefinition);
ExtendedAttribute extendedAttribute = extendedAttributeDefinition.CreateExtendedAttribute();
task.ExtendedAttributes.Add(extendedAttribute);
// Add resource and resource assignment
Resource rsc = project.Resources.Add("Rsc");
ResourceAssignment assn = project.ResourceAssignments.Add(task, rsc);
return project;
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project instance
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Project1.mpp");
project.Set(Prj.NewTasksAreManual, false);
// Create new custom field (Task Text1) with formula which will double task cost
ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Custom");
attr.Alias = "Double Costs";
attr.Formula = "[Cost]*2";
project.ExtendedAttributes.Add(attr);
// Add a task
Task task = project.RootTask.Children.Add("Task");
// Set task cost
task.Set(Tsk.Cost, 100);
// Save project
project.Save(dataDir + "WriteFormulasInExtendedAttributesToMPP_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "AddImageToPageHeaderFooter.mpp");
project.RootTask.Children.Add("Task1");
PageInfo pageInfo = project.DefaultView.PageInfo;
using (Image image = Image.FromFile(dataDir + "Image1.png"))
{
pageInfo.Header.CenteredImage = image;
pageInfo.Legend.LeftImage = image;
pageInfo.Legend.LeftText = string.Empty;
MPPSaveOptions saveOptions = new MPPSaveOptions();
saveOptions.WriteViewData = true;
project.Save(dataDir + "AddImageToPageHeaderFooter_out.mpp", saveOptions);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create a project instance
Project newProject = new Project();
// Create a file stream
using (FileStream projectStream = new FileStream(dataDir + "EmptyProjectSaveStream_out.xml", FileMode.Create, FileAccess.Write))
{
// Write the stream into XML format
newProject.Save(projectStream, Aspose.Tasks.Saving.SaveFileFormat.XML);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create empty project
Project project = new Project();
// Save project as xml
project.Save(dataDir + "EmptyProjectSaveXML_out.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "CreateProject2.mpp");
project.Set(Prj.StartDate, new DateTime(2014, 9, 22));
// By default project.DateFormat == DateFormat.Date_ddd_mm_dd_yy (Mon 09/22/14) customize DateFormat (September 22, 2014)
project.Set(Prj.DateFormat, DateFormat.DateMmmmDdYyyy);
project.Save(dataDir + "CustomizeDateFormats1_out.pdf", SaveFileFormat.PDF);
// Export to date format 19/07/2016
project.Set(Prj.DateFormat, DateFormat.DateDdMmYyyy);
project.Save(dataDir + "CustomizeDateFormats2_out.pdf", SaveFileFormat.PDF);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create a project instance and Set default properties
Project project = new Project(dataDir + "CreateProject2.mpp");
SaveOptions options = new PdfSaveOptions();
options.PresentationFormat = PresentationFormat.ResourceSheet;
TextStyle style = new TextStyle();
style.Color = Color.OrangeRed;
style.FontStyle = FontStyle.Bold;
style.FontStyle |= FontStyle.Italic;
style.ItemType = TextItemType.OverallocatedResources;
options.TextStyles = new List<TextStyle>();
options.TextStyles.Add(style);
project.Save(dataDir + "CustomizeTextStyle_out.pdf", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "CreateProject2.mpp");
SaveOptions saveOptions = new PdfSaveOptions();
// Set the row height to fit cell content
saveOptions.FitContent = true;
saveOptions.Timescale = Timescale.Months;
saveOptions.PresentationFormat = PresentationFormat.TaskUsage;
project.Save(dataDir + "FitContentsToCellSize_out.pdf", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
public static void Run()
{
// Open modified xml stream
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(GetModifiedXml())))
{
Project project = new Project(stream, new ParseErrorCallback(CustomDurationHandler));
}
}
private static string GetModifiedXml()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
string xml;
// Open valid xml file and modify it
using (TextReader reader = new StreamReader(dataDir + "IgnoreInvalidCharacters.xml"))
xml = reader.ReadToEnd();
Regex regex = new Regex("PT(\\d+)H(\\d+)M(\\d+)S");
return regex.Replace(xml, "**$1Hrs$2Mins$3Secs**");
}
private static object CustomDurationHandler(object sender, ParseErrorArgs args)
{
Regex regex = new Regex("[*]{2}(\\d+)Hrs(\\d+)Mins(\\d+)Secs[*]{2}");
if (args.FieldType == typeof(TimeSpan))
{
Debug.Print("Object field : {0}, Invalid value : {1}", args.FieldName, args.InvalidValue);
string duration = regex.Replace(args.InvalidValue, "PT$1H$2M$3S");
TimeSpan newValue = Duration.ParseTimeSpan(duration);
Debug.Print("New value : {0}", newValue);
return newValue;
}
// Here we handle only TimeSpan instances, so rethrow original exception with other types
throw args.Exception;
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
try
{
// Create connection string
SqlConnectionStringBuilder sqlConnectionString = new SqlConnectionStringBuilder();
sqlConnectionString.DataSource = "192.168.56.2,1433";
sqlConnectionString.Encrypt = true;
sqlConnectionString.TrustServerCertificate = true;
sqlConnectionString.InitialCatalog = "ProjectServer_Published";
sqlConnectionString.NetworkLibrary = "DBMSSOCN";
sqlConnectionString.UserID = "sa";
sqlConnectionString.Password = "*****";
// Use Aspose.Tasks.Connectivity namespace
MspDbSettings settings = new MspDbSettings(sqlConnectionString.ConnectionString, new Guid("E6426C44-D6CB-4B9C-AF16-48910ACE0F54"));
settings.Schema = "dbo";
Project project = new Project(settings);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nPlease setup proper datasource (DataSource, InitialCatalog etc)");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
DbSettings settings = new MpdSettings("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + dataDir + "MpdFileToRead.mpd", 1);
Project project = new Project(settings);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "PasswordProtectedProject.mpp", "password");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read project xml into file stream
using (Stream filesStream = new FileStream(dataDir + "ReadProjectFileFromStream.xml", FileMode.Open))
{
// Create project using file stream
Project project = new Project(filesStream);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read existing project template file
Project project = new Project(dataDir + "ReadProjectFiles.mpp");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "CreateProject1.mpp");
project.Save(dataDir + "SaveProjectAsCSV_out.csv", SaveFileFormat.CSV);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read the input Project file
Project project = new Project(dataDir + "CreateProject2.mpp");
// Save the Project as PDF
project.Save(dataDir + "SaveProjectAsPDF_out.pdf", SaveFileFormat.PDF);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read the input Project file
Project project = new Project(dataDir + "CreateProject2.mpp");
// Save the Project as text
project.Save(dataDir + "SaveProjectAsText_out.txt", SaveFileFormat.TXT);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read the input Project file
Project project = new Project(dataDir + "CreateProject2.mpp");
// Save the Project as XLSX
project.Save(dataDir + "SaveProjectAsXLSX_out.xlsx", SaveFileFormat.XLSX);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "CreateProject2.mpp");
HtmlSaveOptions option = new HtmlSaveOptions();
project.Save(dataDir + "SaveProjectDataAsHTML_out.html", option);
// OR
project = new Project(dataDir + "CreateProject2.mpp");
option = new HtmlSaveOptions();
option.Pages.Add(2); // Adding only one page (page number 2)
project.Save(dataDir + "SaveProjectDataAsHTML2_out.html", option);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "CreateProject2.mpp");
project.Save(dataDir + "SaveProjectDataToSpreadsheet2003XML_out.xml", SaveFileFormat.Spreadsheet2003);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "CreateProject1.mpp");
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.SaveToSeparateFiles = true;
saveOptions.Pages = new List<int>();
saveOptions.Pages.Add(1);
saveOptions.Pages.Add(4);
project.Save(dataDir + "SaveToMultiplePDFFiles_out.pdf", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read the input Project file
Project project = new Project(dataDir + "CreateProject2.mpp");
SaveOptions saveOptions = new SvgOptions();
saveOptions.FitContent = true;
saveOptions.Timescale = Timescale.ThirdsOfMonths;
project.Save(dataDir + "UseSvgOptions_out.svg", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read the input Project file
Project project = new Project(dataDir + "CreateProject2.mpp");
SaveOptions saveOptions = new SvgOptions();
saveOptions.FitContent = true;
saveOptions.Timescale = Timescale.ThirdsOfMonths;
project.Save(dataDir + "UseSvgOptions_out.svg", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read the input Project file
Project project = new Project(dataDir + "GetNumberOfPages.mpp");
// Get number of pages, Timescale.Months, Timescale.ThirdsOfMonths
int iPages = project.GetPageCount();
iPages = project.GetPageCount(Timescale.Months);
iPages = project.GetPageCount(Timescale.ThirdsOfMonths);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read the source Project
Project project = new Project(dataDir + "GetNumberOfPagesForViews.mpp");
// Get number of pages, Months and ThirdsOfMonths
Console.WriteLine(string.Format("Number of Pages = '{0}'", project.GetPageCount(PresentationFormat.ResourceUsage, Timescale.Days)));
Console.WriteLine(string.Format("Number of Pages = '{0}'", project.GetPageCount(PresentationFormat.ResourceUsage, Timescale.Months)));
Console.WriteLine(string.Format("Number of Pages = '{0}'", project.GetPageCount(PresentationFormat.ResourceUsage, Timescale.ThirdsOfMonths)));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "GetNumberOfPages.mpp");
var options = new ImageSaveOptions(SaveFileFormat.PNG)
{
SaveToSeparateFiles = true,
PageSize = PageSize.A3,
Timescale = Timescale.Months,
StartDate = project.Get(Prj.StartDate) - TimeSpan.FromDays(10),
EndDate = project.Get(Prj.FinishDate) + TimeSpan.FromDays(30)
};
int pageCount = project.GetPageCount(
PageSize.A3,
Timescale.Months,
project.Get(Prj.StartDate) - TimeSpan.FromDays(10),
project.Get(Prj.FinishDate) + TimeSpan.FromDays(30));
Console.WriteLine(pageCount);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project1.mpp");
// Save project in desired format
project.Save(dataDir + "ExportProjectDataToPrimaveraMPXFormat_out.xml", SaveFileFormat.MPX);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project1.mpp");
// Save project in desired format
project.Save(dataDir + "ExportProjectDataToXERFormat_out.mpp", SaveFileFormat.PrimaveraXER);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project1.mpp");
// Save project in desired format
project.Save(dataDir + "ExportProjectDataToXMLFormat_out.xml", SaveFileFormat.PrimaveraP6XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Primavera1.mpx");
ProjectFileInfo info = Project.GetProjectFileInfo(dataDir + "primavera1.mpx");
Console.WriteLine(info.ProjectFileFormat);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project.xml");
ProjectFileInfo info = Project.GetProjectFileInfo(dataDir + "Project.xml");
Console.WriteLine(info.ProjectFileFormat);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder();
sb.DataSource = "192.168.56.3,1433";
sb.Encrypt = true;
sb.TrustServerCertificate = true;
sb.InitialCatalog = "PrimaveraEDB";
sb.NetworkLibrary = "DBMSSOCN";
sb.UserID = "privuser";
sb.Password = "***";
// Initialize a new instance of the PrimaveraDbSettings class with connection string and project id
PrimaveraDbSettings settings = new PrimaveraDbSettings(sb.ConnectionString, 4502);
// Initialize a new instance of the Project class
Project project = new Project(settings);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
PrimaveraXmlReader reader = new PrimaveraXmlReader(dataDir + "Project.xml");
List<int> listOpProjectUids = reader.GetProjectUids();
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
PrimaveraXmlReadingOptions options = new PrimaveraXmlReadingOptions();
options.ProjectUid = 4557;
// Returns project with special Uid
Project project = new Project(dataDir + "Project.xml", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
string connectionString = "Data Source=" + dataDir + "\\PPMDBSQLite.db";
const int projectId = 4502;
// Create Primavera DB Settings using connection string and project id
PrimaveraDbSettings primaveraDbSettings = new PrimaveraDbSettings(connectionString, projectId);
primaveraDbSettings.ProviderInvariantName = "System.Data.SQLite";
// Create new project using primavera db settings
Project project = new Project(primaveraDbSettings);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "project.xml");
// Specify xml save options
PrimaveraXmlSaveOptions options = new PrimaveraXmlSaveOptions();
options.SaveRootTask = false;
project.Save("UsingPrimaveraXMLSaveOptions_out.xml", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "CalculateCriticalPath.mpp");
project.CalculationMode = CalculationMode.Automatic;
Task subtask1 = project.RootTask.Children.Add("1");
Task subtask2 = project.RootTask.Children.Add("2");
Task subtask3 = project.RootTask.Children.Add("3");
project.TaskLinks.Add(subtask1, subtask2, TaskLinkType.FinishToStart);
// Display the critical path now
foreach (Task task in project.CriticalPath)
{
Console.WriteLine(task.Get(Tsk.Name));
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
IDictionary<string, string> fileFormatExt = new Dictionary<string, string>();
fileFormatExt.Add("RTF", "_rtfFile_out.rtf");
fileFormatExt.Add("MSWordDoc", "_wordFile_out.docx");
fileFormatExt.Add("ExcelML12", "_excelFile_out.xlsx");
Project project = new Project(dataDir + "Embedded.mpp");
foreach (OleObject oleObject in project.OleObjects)
{
if (!string.IsNullOrEmpty(oleObject.FileFormat) && fileFormatExt.ContainsKey(oleObject.FileFormat))
{
string path = dataDir + "EmbeddedContent_" + fileFormatExt[oleObject.FileFormat];
using (FileStream fileStream = new FileStream(path, FileMode.Create))
fileStream.Write(oleObject.Content, 0, oleObject.Content.Length);
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "ExtractEmbeddedObjects.mpp");
OleObject ole = project.OleObjects.ToList()[0];
// We have to check this property because it can be null if the embedded object was created inside the ms project application Or, alternatively, you can use this check: if (ole.FileFormat == "Package")
if (!string.IsNullOrEmpty(ole.FullPath))
{
using (FileStream fileStream = new FileStream(dataDir, FileMode.Create))
fileStream.Write(ole.Content, 0, ole.Content.Length);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
try
{
Project project = new Project(dataDir + "PrintTaskWritingException.mpp");
Console.Write("This example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
project.Save(dataDir + "project_out.MPP", SaveFileFormat.MPP);
}
catch (TasksWritingException ex)
{
Console.WriteLine(ex.LogText);
}
catch (NotSupportedException ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project2003.mpp");
Filter filter = project.TaskFilters.ToList()[1];
Console.WriteLine(filter.Criteria.CriteriaRows.Count);
Console.WriteLine(filter.Criteria.Operation.ToString());
FilterCriteria criteria1 = filter.Criteria.CriteriaRows[0];
Console.WriteLine(criteria1.Test.ToString());
Console.WriteLine(criteria1.Field.ToString());
Console.WriteLine(criteria1.Values[0].ToString());
FilterCriteria criteria2 = filter.Criteria.CriteriaRows[1];
Console.WriteLine(criteria2.Operation.ToString());
Console.WriteLine(criteria2.CriteriaRows.Count);
FilterCriteria criteria21 = criteria2.CriteriaRows[0];
Console.WriteLine(criteria21.Test.ToString());
Console.WriteLine(criteria21.Field.ToString());
Console.WriteLine(criteria21.Values[0].ToString());
FilterCriteria criteria22 = criteria2.CriteriaRows[1];
Console.WriteLine(criteria22.Test.ToString());
Console.WriteLine(criteria22.Field.ToString());
Console.WriteLine(criteria22.Values[0].ToString());
Console.WriteLine(filter.Criteria);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Instantiate project and access task filters
Project project = new Project(dataDir + "ReadFilterDefinitionData.mpp");
List<Filter> taskFilters = project.TaskFilters.ToList();
Console.WriteLine("Task Filters Count: " + taskFilters.Count);
Console.WriteLine("All Tasks: " + taskFilters[0].Name);
Console.WriteLine("Task Item: " + taskFilters[0].FilterType);
Console.WriteLine("Task Filters Show In Menu: " + taskFilters[0].ShowInMenu);
Console.WriteLine("Task filter ShowRelatedSummaryRows: " + taskFilters[0].ShowRelatedSummaryRows);
// Access resource filters
List<Filter> rscFilters = project.ResourceFilters.ToList();
Console.WriteLine("Project.ResourceFilters count: " + rscFilters.Count);
Console.WriteLine("Resource Filter Item Type: Item.ResourceType: " + rscFilters[0].FilterType);
Console.WriteLine("Resource filter ShowInMenu" + rscFilters[0].ShowInMenu);
Console.WriteLine("Resource filter ShowRelatedSummaryRows: " + rscFilters[0].ShowRelatedSummaryRows);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "ReadGroupDefinitionData.mpp");
Console.WriteLine("Task Groups Count: " + project.TaskGroups.Count);
Group taskGroup = project.TaskGroups.ToList()[1];
Console.WriteLine("Group Name:", taskGroup.Name);
Console.WriteLine("Group Criteria count: " + taskGroup.GroupCriteria.Count);
Console.WriteLine("\n************* Retrieving Task Group's Criterion information *************");
GroupCriterion criterion = taskGroup.GroupCriteria.ToList()[0];
Console.WriteLine("Criterion Field: " + criterion.Field.ToString());
Console.WriteLine("Criterion GroupOn: " + criterion.GroupOn.ToString());
Console.WriteLine("Criterion Cell Color: " + criterion.CellColor);
Console.WriteLine("Criterion Pattern: " + criterion.Pattern.ToString());
if (taskGroup == criterion.ParentGroup)
Console.WriteLine("Parent Group is equval to task Group.");
Console.WriteLine("\n*********** Retreivnig Criterion's Font Information ***********");
Console.WriteLine("Font Name: " + criterion.Font.Name);
Console.WriteLine("Font Size: " + criterion.Font.Size);
Console.WriteLine("Font Style: " + criterion.Font.Style);
Console.WriteLine("Ascending/Dscending: " + criterion.Ascending);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "ReadTableData.mpp");
// Access table
Table task1 = project.Tables.ToList()[0];
Console.WriteLine("Table Fields Count" + task1.TableFields.Count);
// Display all table fields information
foreach (TableField tableField in task1.TableFields)
{
Console.WriteLine("Field width: " + tableField.Width);
Console.WriteLine("Field Title: " + tableField.Title);
Console.WriteLine("Field Title Alignment: " + tableField.AlignTitle.ToString());
Console.WriteLine("Field Align Data: " + tableField.AlignData.ToString());
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read an existing project
Project project = new Project(dataDir + "MPPFileUpdate.mpp");
// Create a new task
Task task = project.RootTask.Children.Add("Task1");
task.Set(Tsk.Start, new DateTime(2012, 8, 1));
task.Set(Tsk.Finish, new DateTime(2012, 8, 5));
// Save the project as MPP project file
project.Save(dataDir + "AfterLinking_out.Mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read the input Project file
Project project = new Project(dataDir + "Project2.mpp");
PrintOptions options = new PrintOptions();
options.Timescale = Timescale.ThirdsOfMonths;
if (project.GetPageCount(Timescale.ThirdsOfMonths) <= 280)
project.Print(options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read the input Project file
Project project = new Project(dataDir + "Project2.mpp");
PrintOptions options = new PrintOptions();
options.Timescale = Timescale.Months;
// Print first two pages
PrinterSettings printerSettings = new PrinterSettings();
printerSettings.PrintRange = PrintRange.SomePages;
printerSettings.FromPage = 1;
printerSettings.ToPage = 2;
System.Drawing.Printing.PageSettings pageSettings = printerSettings.DefaultPageSettings;
pageSettings.PaperSize = new PaperSize(dataDir + "Custom Size", 1000, 700);
project.Print(printerSettings, options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "PrintProject5.mpp");
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFileFormat.PNG);
saveOptions.StartDate = project.Get(Prj.StartDate).AddDays(-3);
saveOptions.EndDate = project.Get(Prj.FinishDate);
saveOptions.MarkCriticalTasks = true;
saveOptions.LegendOnEachPage = false;
saveOptions.Gridlines = new List<Gridline>();
Gridline gridline = new Gridline();
gridline.GridlineType = GridlineType.GanttRow;
gridline.Color = Color.CornflowerBlue;
gridline.Pattern = LinePattern.Dashed;
saveOptions.Gridlines.Add(gridline);
// Save the whole project layout to one file
project.Save(dataDir + "CustomerFeedback1_out.png", saveOptions);
// Save project layout to separate files
saveOptions.SaveToSeparateFiles = true;
project.Save(dataDir + "CustomerFeedback2_out.png", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read the input Project file
Project project = new Project(dataDir + "Project2.mpp");
string printerName = "Microsoft Print to PDF";
foreach (string printer in PrinterSettings.InstalledPrinters)
{
if (printer.ToUpperInvariant().Contains(printerName.ToUpperInvariant()))
{
project.Print(printer);
break;
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read the input Project file
Project project = new Project(dataDir + "Project2.mpp");
project.Print();
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create project and project info instances
Project project = new Project(dataDir + "Blank2010.mpp");
PageInfo info = project.DefaultView.PageInfo;
Console.WriteLine("Page data cannot be null : {0} ", !info.Equals(null));
if (info != null)
{
AssertHeaderFooterCorrect(info);
AssertPageSettingsCorrect(info);
AssertPageViewSettingsCorrect(info);
AssertMarginsCorrect(info);
AssertLegendCorrect(info);
}
}
private static void AssertHeaderFooterCorrect(PageInfo info)
{
Console.WriteLine("Header left text Equals LEFT HEADER : {0} ", info.Header.LeftText.Equals("LEFT HEADER"));
Console.WriteLine("Header center text Equals CENTER HEADER : {0} ", info.Header.CenteredText.Equals("CENTER HEADER"));
Console.WriteLine("Header right text Equals RIGHT HEADER : {0} ", info.Header.RightText.Equals("RIGHT HEADER"));
Console.WriteLine("Footer left text Equals LEFT FOOTER : {0} ", info.Footer.LeftText.Equals("LEFT FOOTER"));
Console.WriteLine("Footer center text Equals CENTER FOOTER : {0} ", info.Footer.CenteredText.Equals("CENTER FOOTER"));
Console.WriteLine("Footer right text Equals RIGHT FOOTER : {0} ", info.Footer.RightText.Equals("RIGHT FOOTER"));
}
private static void AssertPageSettingsCorrect(PageInfo info)
{
Console.WriteLine("Portrait Orientation is Portrait : {0} ", info.PageSettings.IsPortrait.Equals(true));
Console.WriteLine("AdjustToPercentOfNormalSize is enabled : {0} ", info.PageSettings.AdjustToPercentOfNormalSize.Equals(true));
Console.WriteLine("PercentOfNormalSize Equals 150 : {0} ", info.PageSettings.PercentOfNormalSize.Equals(150));
Console.WriteLine("PagesInWidth Equals 3 : {0} ", info.PageSettings.PagesInWidth.Equals(3));
Console.WriteLine("PagesInHeight Equals 7 : {0} ", info.PageSettings.PagesInHeight.Equals(7));
Console.WriteLine("PaperSize Equals PaperA4 : {0} ", info.PageSettings.PaperSize.Equals(PrinterPaperSize.PaperA4));
Console.WriteLine("FirstPageNumber : {0} ", info.PageSettings.FirstPageNumber);
}
private static void AssertPageViewSettingsCorrect(PageInfo info)
{
Console.WriteLine("PrintAllSheetColumns is set to false : {0} ", info.PageViewSettings.PrintAllSheetColumns.Equals(false));
Console.WriteLine("PrintFirstColumnsCountOnAllPages is set to true : {0} ", info.PageViewSettings.PrintFirstColumnsCountOnAllPages.Equals(true));
Console.WriteLine("FirstColumnsCount Equals 3 : {0} ", info.PageViewSettings.FirstColumnsCount.Equals(3));
Console.WriteLine("PrintNotes is set to true : {0} ", info.PageViewSettings.PrintNotes.Equals(true));
Console.WriteLine("PrintBlankPages is set to false : {0} ", info.PageViewSettings.PrintBlankPages.Equals(false));
Console.WriteLine("FitTimescaleToEndOfPage is set to true : {0} ", info.PageViewSettings.FitTimescaleToEndOfPage.Equals(true));
}
private static void AssertMarginsCorrect(PageInfo info)
{
Console.WriteLine("Margins.Left Equals 1 : {0} ", (info.Margins.Left - 1 <= 1e-5) ? true : false);
Console.WriteLine("Margins.Top Equals 1.1 : {0} ", (info.Margins.Top - 1.1 <= 1e-5) ? true : false);
Console.WriteLine("Margins.Right Equals 1.2 : {0} ", (info.Margins.Right - 1.2 <= 1e-5) ? true : false);
Console.WriteLine("Margins.Bottom Equals 1.2 : {0} ", (info.Margins.Bottom - 1.3 <= 1e-5) ? true : false);
Console.WriteLine("Margin.Borders Equals Border.AroundEveryPage : {0} ",info.Margins.Borders.Equals(Border.AroundEveryPage));
}
private static void AssertLegendCorrect(PageInfo info)
{
Console.WriteLine("Legend left text Equals LEFT LEGEND : {0} ", info.Legend.LeftText.Equals("LEFT LEGEND"));
Console.WriteLine("Legend center text Equals CENTER LEGEND : {0} ", info.Legend.CenteredText.Equals("CENTER LEGEND"));
Console.WriteLine("Legend right text Equals RIGHT LEGEND : {0} ", info.Legend.RightText.Equals("RIGHT LEGEND"));
Console.WriteLine("LegendOn Equals Legend.OnEveryPage : {0} ", info.Legend.LegendOn.Equals(Legend.OnEveryPage));
Console.WriteLine("Legend Width Equals 5 : {0} ", (info.Legend.Width - 5 <= 1e-5) ? true : false);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "OutlineCodes.mpp");
foreach (OutlineCodeDefinition ocd in project.OutlineCodes)
{
Console.WriteLine("Alias = " + ocd.Alias);
if (ocd.AllLevelsRequired)
Console.WriteLine("It contains property: must have all levels");
else
Console.WriteLine("It does not contain property: must have all levels");
if (ocd.Enterprise)
Console.WriteLine("It is an enterprise custom outline code.");
else
Console.WriteLine("It is not an enterprise custom outline code.");
Console.WriteLine("Reference to another custom field for which this outline code definition is an alias is = " + ocd.EnterpriseOutlineCodeAlias);
Console.WriteLine("Field Id = " + ocd.FieldId);
Console.WriteLine("Field Name = " + ocd.FieldName);
Console.WriteLine("Phonetic Alias = " + ocd.PhoneticAlias);
Console.WriteLine("Guid = " + ocd.Guid);
// Display outline code masks
foreach (OutlineMask outlineMask in ocd.Masks)
{
Console.WriteLine("Level of a mask = " + outlineMask.Level);
Console.WriteLine("Mask = " + outlineMask.ToString());
}
// Display out line code values
foreach (OutlineValue outlineMask1 in ocd.Values)
{
Console.WriteLine("Description of outline value = " + outlineMask1.Description);
Console.WriteLine("Value Id = " + outlineMask1.ValueId);
Console.WriteLine("Value = " + outlineMask1.Value);
Console.WriteLine("Type = " + outlineMask1.Type);
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
using (Stream filesStream = new FileStream(dataDir + "Project.xml", FileMode.Open))
{
Project project = new Project(filesStream);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir + "ReadProjectFiles.mpp");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "TestProject1.mpp");
ImageSaveOptions options = new ImageSaveOptions(SaveFileFormat.TIFF);
options.HorizontalResolution = 72;
options.VerticalResolution = 72;
options.PixelFormat = PixelFormat.Format24bppRgb;
project.Save(dataDir + "RenderProjectDataToFormat24bppRgb_out.tif", options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project(dataDir+ "ReplaceCalendar.mpp");
// Add a new calendar to the project's calendars collection and traverse through project calendars and replace the already added calendar with a new one
project.Calendars.Add("New cal1", project.Get(Prj.Calendar));
CalendarCollection calColl = project.Calendars;
foreach (Calendar c in calColl)
{
if (c.Name == "New cal1")
{
calColl.Remove(c);
calColl.Add("New cal2", project.Get(Prj.Calendar));
break;
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Project2.mpp");
project.Set(Prj.ScheduleFromStart, false);
project.Set(Prj.FinishDate, new DateTime(2020, 1, 1));
// Now all tasks dates (Start, Finish, EarlyStart, EarlyFinish, LateStart, LateFinish) are calculated. To get the critical path we need to calculate slacks (can be invoked in separate thread, but only after calculation of all early/late dates)
project.Recalculate();
TaskCollection criticalPath = project.CriticalPath;
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Project2.mpp");
project.Set(Prj.ScheduleFromStart, true);
project.Set(Prj.StartDate, new DateTime(2014, 1, 1));
// Now all tasks dates (Start, Finish, EarlyStart, EarlyFinish, LateStart, LateFinish) are calculated. To get the critical path we need to calculate slacks (can be invoked in separate thread, but only after calculation of all early/late dates)
project.Recalculate();
TaskCollection criticalPath = project.CriticalPath;
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Project2.mpp");
project.Set(Prj.ScheduleFromStart, false);
project.Set(Prj.FinishDate, new DateTime(2020, 1, 1));
// Now all tasks dates (Start, Finish, EarlyStart, EarlyFinish, LateStart, LateFinish) are calculated. To get the critical path we need to calculate slacks (can be invoked in separate thread, but only after calculation of all early/late dates)
project.Recalculate();
TaskCollection criticalPath = project.CriticalPath;
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create a new project and set start date
Project project = new Project();
project.Set(Prj.StartDate, new DateTime(2014, 1, 27, 8, 0, 0));
// Add new tasks
Task task1 = project.RootTask.Children.Add("Task 1");
Task task2 = project.RootTask.Children.Add("Task 2");
task2.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
Task task3 = project.RootTask.Children.Add("Task 3");
task3.Set(Tsk.Duration, task2.ParentProject.GetDuration(24, TimeUnitType.Hour));
Task task4 = project.RootTask.Children.Add("Task 4");
task4.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
Task task5 = project.RootTask.Children.Add("Task 5");
task5.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
// Add links between tasks
TaskLink link12 = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
TaskLink link23 = project.TaskLinks.Add(task2, task3, TaskLinkType.FinishToStart);
// One day lag
link23.LinkLag = 4800;
TaskLink link34 = project.TaskLinks.Add(task3, task4, TaskLinkType.FinishToStart);
TaskLink link45 = project.TaskLinks.Add(task4, task5, TaskLinkType.FinishToStart);
// Add new tasks
Task task6 = project.RootTask.Children.Add("Task 6");
Task task7 = project.RootTask.Children.Add("Task 7");
task7.Set(Tsk.Duration, task7.ParentProject.GetDuration(24, TimeUnitType.Hour));
Task task8 = project.RootTask.Children.Add("Task 8");
task8.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
Task task9 = project.RootTask.Children.Add("Task 9");
task9.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
Task task10 = project.RootTask.Children.Add("Task 10");
// Add links between tasks
TaskLink link67 = project.TaskLinks.Add(task6, task7, TaskLinkType.FinishToStart);
TaskLink link78 = project.TaskLinks.Add(task7, task8, TaskLinkType.FinishToStart);
TaskLink link89 = project.TaskLinks.Add(task8, task9, TaskLinkType.FinishToStart);
TaskLink link910 = project.TaskLinks.Add(task9, task10, TaskLinkType.FinishToStart);
task6.Set(Tsk.IsManual, true);
task7.Set(Tsk.IsManual, true);
task8.Set(Tsk.IsManual, true);
task9.Set(Tsk.IsManual, true);
task10.Set(Tsk.IsManual, true);
// Save project before and after updating work as completed
project.Save(dataDir + "RescheduleUncompletedWork_not updated_out.xml", SaveFileFormat.XML);
project.UpdateProjectWorkAsComplete(new DateTime(2014, 1, 28, 17, 0, 0), false);
project.Save(dataDir + "RescheduleUncompletedWork_updated_out.xml", SaveFileFormat.XML);
// Save project after rescheduling uncompleted work
project.RescheduleUncompletedWorkToStartAfter(new DateTime(2014, 2, 7, 8, 0, 0));
project.Save(dataDir + "RescheduleUncompletedWork_rescheduled_out.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Project2.mpp");
HtmlSaveOptions option = new HtmlSaveOptions();
project.Save(dataDir + "SaveProjectDataAsHTML_out.html", option);
// OR
option.Pages.Add(2); // Adding only one page (page number 2)
project.Save(dataDir + "SaveProjectDataAsHTML2_out.html", option);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project();
Console.WriteLine(project.Get(Prj.StartDate));
Console.WriteLine(project.CalculationMode.ToString());
project.CalculationMode = CalculationMode.None;
Console.WriteLine(project.CalculationMode.ToString());
Task task = project.RootTask.Children.Add("Task1");
task.Set(Tsk.Start, new DateTime(2012, 8, 1));
task.Set(Tsk.Finish, new DateTime(2012, 8, 5));
Console.WriteLine("*************** Before Recalculate *****************");
Console.WriteLine(task.Get(Tsk.Start));
Console.WriteLine(task.Get(Tsk.Finish));
project.Recalculate();
Console.WriteLine("*************** After Recalculate *****************");
Console.WriteLine(task.Get(Tsk.Start));
Console.WriteLine(task.Get(Tsk.Finish));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Projects();
Project project = new Project();
project.Set(Prj.StartDate, new DateTime(2014, 1, 27, 8, 0, 0));
Task task1 = project.RootTask.Children.Add("Task 1");
Task task2 = project.RootTask.Children.Add("Task 2");
task2.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
Task task3 = project.RootTask.Children.Add("Task 3");
task3.Set(Tsk.Duration, task2.ParentProject.GetDuration(24, TimeUnitType.Hour));
Task task4 = project.RootTask.Children.Add("Task 4");
task4.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
Task task5 = project.RootTask.Children.Add("Task 5");
task5.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
TaskLink link12 = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
TaskLink link23 = project.TaskLinks.Add(task2, task3, TaskLinkType.FinishToStart);
link23.LinkLag = 4800; // one day lag
TaskLink link34 = project.TaskLinks.Add(task3, task4, TaskLinkType.FinishToStart);
TaskLink link45 = project.TaskLinks.Add(task4, task5, TaskLinkType.FinishToStart);
Task task6 = project.RootTask.Children.Add("Task 6");
Task task7 = project.RootTask.Children.Add("Task 7");
task7.Set(Tsk.Duration, task7.ParentProject.GetDuration(24, TimeUnitType.Hour));
Task task8 = project.RootTask.Children.Add("Task 8");
task8.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
Task task9 = project.RootTask.Children.Add("Task 9");
task9.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
Task task10 = project.RootTask.Children.Add("Task 10");
TaskLink link67 = project.TaskLinks.Add(task6, task7, TaskLinkType.FinishToStart);
TaskLink link78 = project.TaskLinks.Add(task7, task8, TaskLinkType.FinishToStart);
TaskLink link89 = project.TaskLinks.Add(task8, task9, TaskLinkType.FinishToStart);
TaskLink link910 = project.TaskLinks.Add(task9, task10, TaskLinkType.FinishToStart);
task6.Set(Tsk.IsManual, true);
task7.Set(Tsk.IsManual, true);
task8.Set(Tsk.IsManual, true);
task9.Set(Tsk.IsManual, true);
task10.Set(Tsk.IsManual, true);
project.Save(dataDir + "not updated.xml", SaveFileFormat.XML);
project.UpdateProjectWorkAsComplete(new DateTime(2014, 1, 28, 17, 0, 0), false);
project.Save(dataDir + "updated_out.xml", SaveFileFormat.XML);
project.RescheduleUncompletedWorkToStartAfter(new DateTime(2014, 2, 7, 8, 0, 0));
project.Save(dataDir + "rescheduled_out.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project1 = new Project(dataDir + "Blank2010.mpp");
ExtendedAttributeDefinition myTextAttributeDefinition = project1.ExtendedAttributes.GetById((int)ExtendedAttributeTask.Text1);
// If the Custom field doesn't exist in Project, create it
if (myTextAttributeDefinition == null)
{
myTextAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, "My text field");
project1.ExtendedAttributes.Add(myTextAttributeDefinition);
}
// Generate Extended Attribute from definition
ExtendedAttribute text1TaskAttribute = myTextAttributeDefinition.CreateExtendedAttribute();
text1TaskAttribute.TextValue = "Text attribute value";
// Add extended attribute to task
Task tsk = project1.RootTask.Children.Add("Task 1");
tsk.ExtendedAttributes.Add(text1TaskAttribute);
project1.Save(dataDir + "CreateExtendedAttributes_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "ExtendedAttributes.mpp");
// Create extended attribute definition
ExtendedAttributeDefinition attributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Start, ExtendedAttributeTask.Start7, "Start 7");
project.ExtendedAttributes.Add(attributeDefinition);
// Get zero index task
Task task = project.RootTask.Children.GetById(1);
// Add extended attribute
ExtendedAttribute attribute = attributeDefinition.CreateExtendedAttribute();
attribute.DateValue = DateTime.Now;
// Also the following short syntax can be used: ExtendedAttribute attribute = attributeDefinition.CreateExtendedAttribute(DateTime.Now);
task.ExtendedAttributes.Add(attribute);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "WriteUpdatedExtendedAttributeDefinitions.mpp");
#region task attributes
// Add new text3 extended attribute with lookup and one lookup value
ExtendedAttributeDefinition taskTextAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Text3, "New text3 attribute");
taskTextAttributeDefinition.ElementType = ElementType.Task;
project.ExtendedAttributes.Add(taskTextAttributeDefinition);
Value textVal = new Value();
textVal.Id = 1;
textVal.Description = "Text value descr";
textVal.Val = "Text value1";
taskTextAttributeDefinition.AddLookupValue(textVal);
// Add new cost1 extended attribute with lookup and two cost values
ExtendedAttributeDefinition taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Cost1, "New cost1 attribute");
project.ExtendedAttributes.Add(taskCostAttributeDefinition);
Value costVal1 = new Value();
costVal1.Id = 2;
costVal1.Description = "Cost value 1 descr";
costVal1.Val = "99900";
Value costVal2 = new Value();
costVal2.Id = 3;
costVal2.Description = "Cost value 2 descr";
costVal2.Val = "11100";
taskCostAttributeDefinition.AddLookupValue(costVal1);
taskCostAttributeDefinition.AddLookupValue(costVal2);
// Add new task and assign attribute lookup value.
Task task = project.RootTask.Children.Add("New task");
ExtendedAttribute taskAttr = taskCostAttributeDefinition.CreateExtendedAttribute(costVal1);
task.ExtendedAttributes.Add(taskAttr);
ExtendedAttributeDefinition taskStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Start7, "New start 7 attribute");
Value startVal = new Value();
startVal.Id = 4;
startVal.DateTimeValue = DateTime.Now;
startVal.Description = "Start 7 value description";
taskStartAttributeDefinition.AddLookupValue(startVal);
project.ExtendedAttributes.Add(taskStartAttributeDefinition);
ExtendedAttributeDefinition taskFinishAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Finish4, "New finish 4 attribute");
Value finishVal = new Value();
finishVal.Id = 5;
finishVal.DateTimeValue = DateTime.Now;
finishVal.Description = "Finish 4 value description";
taskFinishAttributeDefinition.ValueList.Add(finishVal);
project.ExtendedAttributes.Add(taskFinishAttributeDefinition);
ExtendedAttributeDefinition numberAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Number20, "New number attribute");
Value val1 = new Value();
val1.Id = 6;
val1.Val = "1";
val1.Description = "Number 1 value";
Value val2 = new Value();
val2.Id = 7;
val2.Val = "2";
val2.Description = "Number 2 value";
Value val3 = new Value();
val2.Id = 8;
val3.Val = "3";
val3.Description = "Number 3 value";
numberAttributeDefinition.AddLookupValue(val1);
numberAttributeDefinition.AddLookupValue(val2);
numberAttributeDefinition.AddLookupValue(val3);
project.ExtendedAttributes.Add(numberAttributeDefinition);
#endregion
ExtendedAttributeDefinition rscStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupResourceDefinition(ExtendedAttributeResource.Start5, "New start5 attribute");
Value startVal2 = new Value();
startVal2.Id = 9;
startVal2.DateTimeValue = DateTime.Now;
startVal2.Description = "this is start5 value descr";
rscStartAttributeDefinition.AddLookupValue(startVal2);
project.ExtendedAttributes.Add(rscStartAttributeDefinition);
// Define a duration attribute without lookup.
ExtendedAttributeDefinition taskDurationAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Duration1, "New Duration");
project.ExtendedAttributes.Add(taskDurationAttributeDefinition);
// Add new task and assign duration value to the previously defined duration attribute.
Task timeTask = project.RootTask.Children.Add("New task");
ExtendedAttribute durationExtendedAttribute = taskDurationAttributeDefinition.CreateExtendedAttribute();
durationExtendedAttribute.DurationValue = project.GetDuration(3.0, TimeUnitType.Hour);
timeTask.ExtendedAttributes.Add(durationExtendedAttribute);
MPPSaveOptions mppSaveOptions = new MPPSaveOptions();
mppSaveOptions.WriteViewData = true;
// Save the project as MPP project file
project.Save(dataDir + "WriteUpdatedExtendedAttributeDefinitions_out.mpp", mppSaveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create empty project and set calculation mode to Automatic
Project project = new Project();
project.CalculationMode = CalculationMode.Automatic;
// Set project start date and add new tasks
project.Set(Prj.StartDate, new DateTime(2015, 4, 15));
Task task1 = project.RootTask.Children.Add("Task 1");
Task task2 = project.RootTask.Children.Add("Task 2");
// Link tasks
TaskLink link = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
// Verify dates have been recalculated
Console.WriteLine("Task1 Start + 1 Equals Task2 Start : {0} ", task1.Get(Tsk.Start).AddDays(1).Equals(task2.Get(Tsk.Start)));
Console.WriteLine("Task1 Finish + 1 Equals Task2 Finish : {0} ", task1.Get(Tsk.Finish).AddDays(1).Equals(task2.Get(Tsk.Finish)));
Console.WriteLine("RootTask Finish Equals Task2 Finish : {0} ", task2.Get(Tsk.Finish).Equals(project.RootTask.Get(Tsk.Finish)));
Console.WriteLine("Project Finish Date Equals Task2 Finish : {0} ", task2.Get(Tsk.Finish).Equals(project.Get(Prj.FinishDate)));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create empty project and set calculation mode to Manual
Project project = new Project();
project.CalculationMode = CalculationMode.Manual;
// Set project start date and add new tasks
project.Set(Prj.StartDate, new DateTime(2015, 4, 15));
Task task1 = project.RootTask.Children.Add("Task 1");
Task task2 = project.RootTask.Children.Add("Task 2");
// The necessary properties are set in manual mode
Console.WriteLine("Task1.Id Equals 1 : {0} ", task1.Get(Tsk.Id).Equals(1));
Console.WriteLine("Task1 OutlineLevel Equals 1 : {0} ", task1.Get(Tsk.OutlineLevel).Equals(1));
Console.WriteLine("Task1 Start Equals 15/04/2015 08:00 AM : {0} ", task1.Get(Tsk.Start).Equals(new DateTime(2015, 4, 15, 8, 0, 0)));
Console.WriteLine("Task1 Finish Equals 15/04/2015 05:00 PM : {0} ", task1.Get(Tsk.Finish).Equals(new DateTime(2015, 4, 15, 17, 0, 0)));
Console.WriteLine("Task1 Duration Equals 1 day : {0} ", task1.Get(Tsk.Duration).ToString().Equals("1 day"));
Console.WriteLine("Task2 Start Equals 15/04/2015 08:00 AM : {0} ", task2.Get(Tsk.Start).Equals(new DateTime(2015, 4, 15, 8, 0, 0)));
Console.WriteLine("Task2 Finish Equals 15/04/2015 05:00 PM : {0} ", task2.Get(Tsk.Finish).Equals(new DateTime(2015, 4, 15, 17, 0, 0)));
Console.WriteLine("Task2 Duration Equals 1 day : {0} ", task2.Get(Tsk.Duration).ToString().Equals("1 day"));
// When we link two tasks together their dates are not recalculated in manual mode
TaskLink link = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
// Task 2 Start has not been changed
Console.WriteLine("Task1 Start Equals Task2 Start : {0} ", task1.Get(Tsk.Start).Equals(task2.Get(Tsk.Start)));
Console.WriteLine("Task1 Finish Equals Task2 Finish : {0} ", task1.Get(Tsk.Finish).Equals(task2.Get(Tsk.Finish)));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create empty project and set calculation mode to None
Project project = new Project();
project.CalculationMode = CalculationMode.None;
// Add a new task
Task task = project.RootTask.Children.Add("Task");
// Note that even ids were not calculated
Console.WriteLine("Task.Id Equals 0 : {0} ", task.Get(Tsk.Id).Equals(0));
Console.WriteLine("Task.OutlineLevel Equals 0 : {0} ", task.Get(Tsk.OutlineLevel).Equals(0));
Console.WriteLine("Task Start Equals DateTime.MinValue : {0} ", task.Get(Tsk.Start).Equals(DateTime.MinValue));
Console.WriteLine("Task Finish Equals DateTime.MinValue : {0} ", task.Get(Tsk.Finish).Equals(DateTime.MinValue));
Console.WriteLine("Task Duration Equals 0 mins : {0} ", task.Get(Tsk.Duration).ToString().Equals("0 mins"));
// Set duration property
task.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));
Console.WriteLine("Task Duration Equals 2 days : {0} ", task.Get(Tsk.Duration).ToString().Equals("2 days"));
Console.WriteLine("Task Start Equals DateTime.MinValue : {0} ", task.Get(Tsk.Start).Equals(DateTime.MinValue));
Console.WriteLine("Task Finish Equals DateTime.MinValue : {0} ", task.Get(Tsk.Finish).Equals(DateTime.MinValue));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Read project from template file
Project project = new Project(dataDir + "DetermineProjectVersion.mpp");
// Display project version
Console.WriteLine("Project Version : " + project.Get(Prj.SaveVersion).ToString());
Console.WriteLine("Last Saved : " + project.Get(Prj.LastSaved).ToShortDateString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create project instance
Project project = new Project(dataDir + "ReadCurrencyProperties.mpp");
// Display currency properties
Console.WriteLine("Currency Code : " + project.Get(Prj.CurrencyCode).ToString());
Console.WriteLine("<br>Currency Digits : " + project.Get(Prj.CurrencyDigits).ToString());
Console.WriteLine("<br>Currency Symbol : " + project.Get(Prj.CurrencySymbol).ToString());
Console.WriteLine("Currency Symbol Position" + project.Get(Prj.CurrencySymbolPosition).ToString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create project
Project project = new Project(dataDir + "DefaultProperties.mpp");
// Display default properties
Console.WriteLine("New Task Default Start: " + project.Get(Prj.DefaultStartTime).ToShortDateString());
Console.WriteLine("New Task Default Type: " + project.Get(Prj.DefaultTaskType));
Console.WriteLine("Resouce Default Standard Rate: " + project.Get(Prj.DefaultStandardRate).ToString());
Console.WriteLine("Resource Default Overtime Rate: " + project.Get(Prj.DefaultOvertimeRate).ToString());
Console.WriteLine("Default Task EV Method: " + project.Get(Prj.DefaultTaskEVMethod).ToString());
Console.WriteLine("Default Cost Accrual: " + project.Get(Prj.DefaultFixedCostAccrual).ToString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create a project instance
Project project = new Project(dataDir + "ReadFiscalYearProperties.mpp");
// Display fiscal year properties
Console.WriteLine("Fiscal Year Start Date : " + project.Get(Prj.FyStartDate).ToString());
Console.WriteLine("Fiscal Year Numbering : " + project.Get(Prj.FiscalYearStart).ToString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create a project reader instance
Project project = new Project(dataDir + "ReadProjectInfo.mpp");
// Display project information
if (project.Get(Prj.ScheduleFromStart))
Console.WriteLine("Project Finish Date : " + project.Get(Prj.StartDate).ToShortDateString());
else
Console.WriteLine("Project Finish Date : " + project.Get(Prj.FinishDate).ToShortDateString());
Console.WriteLine(project.Get(Prj.Author));
Console.WriteLine(project.Get(Prj.LastAuthor));
Console.WriteLine(project.Get(Prj.Revision));
Console.WriteLine(project.Get(Prj.Keywords));
Console.WriteLine(project.Get(Prj.Comments));
Console.WriteLine("The program has run successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create project instance
Project project = new Project(dataDir + "ReadWeekdayProperties.mpp");
// Display week days properties
Console.WriteLine("Week Start Date : " + project.Get(Prj.WeekStartDay).ToString());
Console.WriteLine("Days Per Month : " + project.Get(Prj.DaysPerMonth).ToString());
Console.WriteLine("Minutes Per Day : " + project.Get(Prj.MinutesPerDay).ToString());
Console.WriteLine("Minutes Per Week : " + project.Get(Prj.MinutesPerWeek).ToString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create a project instance Set new task property and Save the project as XML project file
Project project = new Project();
project.Set(Prj.NewTaskStartDate, TaskStartDateType.CurrentDate);
project.Save(dataDir + "SetAttributesForNewTasks_out.xml", SaveFileFormat.XML);
// Display Status.
Console.WriteLine("New Task created with start date successfully.");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create a project instance
Project project = new Project(dataDir + "WriteCurrencyProperties.mpp");
// Set currency properties
project.Set(Prj.CurrencyCode, "AUD");
project.Set(Prj.CurrencyDigits, 2);
project.Set(Prj.CurrencySymbol, "$");
project.Set(Prj.CurrencySymbolPosition, CurrencySymbolPositionType.After);
// Save the project as XML project file
project.Save(dataDir + "WriteCurrencyProperties_out.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create a project instance and Set default properties
Project project = new Project();
project.Set(Prj.ScheduleFromStart, true);
project.Set(Prj.StartDate, DateTime.Now);
project.Set(Prj.DefaultStartTime, project.Get(Prj.StartDate));
project.Set(Prj.DefaultTaskType, TaskType.FixedDuration);
project.Set(Prj.DefaultStandardRate, 15);
project.Set(Prj.DefaultOvertimeRate, 12);
project.Set(Prj.DefaultTaskEVMethod, EarnedValueMethodType.PercentComplete);
project.Set(Prj.DefaultFixedCostAccrual, CostAccrualType.Prorated);
// Save the project to XML format
project.Save(dataDir + "WriteDefaultProperties_out.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create a project instance
Project project = new Project(dataDir + "WriteFiscalYearProperties.mpp");
// Set fiscal year properties
project.Set(Prj.FyStartDate, Month.July);
project.Set(Prj.FiscalYearStart, true);
project.Save(dataDir + "WriteFiscalYearProperties_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Instantiate Project class
Project project = new Project(dataDir + "WriteMPPProjectSummary.mpp");
// Set project summary
project.Set(Prj.Author, "Author");
project.Set(Prj.LastAuthor, "Last Author");
project.Set(Prj.Revision, 15);
project.Set(Prj.Keywords, "MSP Aspose");
project.Set(Prj.Comments, "Comments");
project.Save(dataDir + "WriteMPPProjectSummary_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
try
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create project from template file
Project project = new Project(dataDir + "WriteProjectInfo.mpp");
// Set project information
project.Set(Prj.Author, "Author");
project.Set(Prj.LastAuthor, "Last Author");
project.Set(Prj.Revision, 15);
project.Set(Prj.Keywords, "MSP Aspose");
project.Set(Prj.Comments, "Comments");
project.Save(dataDir + "WriteProjectInfo_out.mpp", SaveFileFormat.MPP);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// Create a project instance
Project project = new Project(dataDir+ "WriteWeekdayProperties.mpp");
// Set week days properties
project.Set(Prj.WeekStartDay, DayType.Monday);
project.Set(Prj.DaysPerMonth, 24);
project.Set(Prj.MinutesPerDay, 540);
project.Set(Prj.MinutesPerWeek, 3240);
project.Save(dataDir + "WriteWeekdayProperties_out.xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Project5.mpp"); // Create a new project task
Task task = project.RootTask.Children.Add("New Activity");
// Define new custom attribute
ExtendedAttributeDefinition text1Definition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, null);
project.ExtendedAttributes.Add(text1Definition);
// Add custom text attribute to created task.
task.ExtendedAttributes.Add(text1Definition.CreateExtendedAttribute("Activity attribute"));
// Customize table by adding text attribute field
TableField attrField = new TableField();
attrField.Field = Field.TaskText1;
attrField.Width = 20;
attrField.Title = "Custom attribute";
attrField.AlignTitle = StringAlignment.Center;
attrField.AlignData = StringAlignment.Center;
Table table = project.Tables.ToList()[0];
table.TableFields.Insert(3, attrField);
project.Save(dataDir + "ConfigureGantChart_out.mpp", new MPPSaveOptions() { WriteViewData = true });
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project5.mpp");
// Create a new project task
Task task = project.RootTask.Children.Add("New Activity");
// Define new custom attribute
ExtendedAttributeDefinition text1Definition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, null);
project.ExtendedAttributes.Add(text1Definition);
// Add custom text attribute to created task.
task.ExtendedAttributes.Add(text1Definition.CreateExtendedAttribute("Activity attribute"));
// Customize table by adding text attribute field
TableField attrField = new TableField();
attrField.Field = Field.TaskText1;
attrField.Width = 20;
attrField.Title = "Custom attribute";
attrField.AlignTitle = StringAlignment.Center;
attrField.AlignData = StringAlignment.Center;
Table table = project.Tables.ToList()[0];
table.TableFields.Insert(3, attrField);
// Save project as MPP
project.Save(dataDir + "ConfigureTheGantChartViewShowSelectedColumnFields_out.mpp", new MPPSaveOptions() { WriteViewData = true });
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "Project5.mpp");
// Add task links
project.TaskLinks.Add(project.RootTask.Children.Add("Task 1"), project.RootTask.Children.Add("Task 2"));
GanttChartView view = (GanttChartView)project.DefaultView;
// This code is added for better visualization
view.MiddleTimescaleTier.Unit = TimescaleUnit.Months;
project.Set(Prj.TimescaleStart, new DateTime(2012, 8, 6));
// Customize middle tier dates
view.MiddleTimescaleTier.DateTimeConverter =
date => new[] { "Янв.", "Фев.", "Мар.", "Апр.", "Май", "Июнь", "Июль", "Авг.", "Сен.", "Окт.", "Ноя.", "Дек." }[date.Month - 1];
project.Save(dataDir + "CustomizeTimescaleTierLabels_out.pdf", SaveFileFormat.PDF);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "ReadSpecificGantChartViewData.mpp");
GanttChartView view = project.Views.ToList()[0] as GanttChartView;
Console.WriteLine("Is Bar Rounding: " + view.BarRounding);
Console.WriteLine("Show Bar Splits? : " + view.ShowBarSplits);
Console.WriteLine("Show Drawings? : " + view.ShowDrawings);
Console.WriteLine("Roll Up Gantt Bars? " + view.RollUpGanttBars);
Console.WriteLine("Hide Rollup Bars When Summary Expa0nded: " + view.HideRollupBarsWhenSummaryExpanded);
Console.WriteLine("Bar Size: " + view.BarSize.ToString());
Console.WriteLine("Bar Style: " + view.BarStyles.Count);
Console.WriteLine("\n************************ RETREIVING BAR STYLES INFORMATION FROM THE VIEW *********************");
int i = 0;
foreach (GanttBarStyle barStyle in view.BarStyles)
{
Console.WriteLine("Name: " + barStyle.Name);
Console.WriteLine("ShowFor: " + barStyle.ShowFor.ToString());
Console.WriteLine("Row: " + barStyle.Row);
Console.WriteLine("From: " + barStyle.From);
Console.WriteLine("To: " + barStyle.To);
Console.WriteLine("MiddleShape: " + barStyle.MiddleShape);
Console.WriteLine("MiddleShapeColor: " + barStyle.MiddleShapeColor);
Console.WriteLine("StartShape: " + barStyle.StartShape);
Console.WriteLine("EndShape: " + barStyle.EndShape);
Console.WriteLine("EndShapeColor: " + barStyle.EndShapeColor);
i++;
}
Console.WriteLine("Grid Lines Count: " + view.Gridlines.Count);
Gridlines gridlines = view.Gridlines[0];
Console.WriteLine("\n************************ RETREIVING GRID LINES PROPERTIES *********************");
Console.WriteLine("GridLine Type: " + gridlines.Type);
Console.WriteLine("Gridlines Internval: " + gridlines.Interval);
Console.WriteLine("Gridlines Color: " + gridlines.NormalColor);
Console.WriteLine("Gridlines NormalPattern: " + gridlines.NormalPattern);
Console.WriteLine("Gridlines IntervalPattern: " + gridlines.IntervalPattern);
Console.WriteLine("Gridlines IntervalColor: " + gridlines.IntervalColor);
Console.WriteLine("\n************************ RETREIVING PROGRESS LINES PROPERTIES *********************");
Console.WriteLine("ProgressLInes.BeginAtDate: ", view.ProgressLines.BeginAtDate);
Console.WriteLine("ProgressLines.isBaselinePlan: " + view.ProgressLines.IsBaselinePlan);
Console.WriteLine("ProgressLines.DisplaySelected: " + view.ProgressLines.DisplaySelected);
Console.WriteLine("ProgressLines.SelectedDates.Count: " + view.ProgressLines.SelectedDates.Count);
Console.WriteLine("ProgressLines.SelectedDates[0]: " + view.ProgressLines.SelectedDates[0]);
Console.WriteLine("ProgressLines.SelectedDates[1]: " + view.ProgressLines.SelectedDates[1]);
Console.WriteLine("ProgressLines.SelectedDates[2]: " + view.ProgressLines.SelectedDates[2]);
Console.WriteLine("ProgressLines.DisplayAtRecurringIntervals: " + view.ProgressLines.DisplayAtRecurringIntervals);
Console.WriteLine("ProgressLines.RecurringInterval.Interval: " + Interval.Weekly, view.ProgressLines.RecurringInterval.Interval);
Console.WriteLine("ProgressLines.RecurringInterval.WeeklyDays.Count" + view.ProgressLines.RecurringInterval.WeeklyDays.Count);
Console.WriteLine("Recurring Interval.WeeklyDays: " + view.ProgressLines.RecurringInterval.WeeklyDays);
Console.WriteLine("Recurring Interval.DayType.Saturday: " + view.ProgressLines.RecurringInterval.WeeklyDays);
Console.WriteLine("Recurring Interval.DayType.Sunday: " + view.ProgressLines.RecurringInterval.WeeklyDays);
Console.WriteLine("ProgressLines.ShowDate: " + view.ProgressLines.ShowDate);
Console.WriteLine("ProgressLines.ProgressPointShape: " + view.ProgressLines.ProgressPointShape.ToString());
Console.WriteLine("ProgressLines.ProgressPointColor: " + view.ProgressLines.ProgressPointColor);
Console.WriteLine("ProgressLines.LineColor: " + Color.Red, view.ProgressLines.LineColor);
Console.WriteLine("ProgressLines.LinePattern: " + LinePattern.Solid, view.ProgressLines.LinePattern);
Console.WriteLine("ProgressLines.OtherProgressPointShape: " + view.ProgressLines.OtherProgressPointShape.ToString());
Console.WriteLine("ProgressLines.OtherProgressPointColor: " + view.ProgressLines.OtherProgressPointColor.ToString());
Console.WriteLine("ProgressLines.OtherLineColor: " + view.ProgressLines.OtherLineColor);
Console.WriteLine("\n************************ BOTTOM TIMESCALE IFORMATION ******************");
Console.WriteLine("BottomTimescaleTier.Count:" + view.BottomTimescaleTier.Count);
Console.WriteLine("BottomTimescaleTier.Unit:" + TimescaleUnit.Days, view.BottomTimescaleTier.Unit.ToString());
Console.WriteLine("BottomTimescaleTier.UsesFiscalYear: " + view.BottomTimescaleTier.UsesFiscalYear);
Console.WriteLine("BottomTimescaleTier.Alignment: " + StringAlignment.Center, view.BottomTimescaleTier.Alignment.ToString());
Console.WriteLine("BottomTimescaleTier.ShowTicks: " + view.BottomTimescaleTier.ShowTicks.ToString());
Console.WriteLine("BottomTimescaleTier.Label:" + DateLabel.DayDi, view.BottomTimescaleTier.Label);
Console.WriteLine("\n************************ MIDDLE TIMESCALE IFORMATION ******************");
Console.WriteLine("MiddleTimescaleTier.Count:" + view.MiddleTimescaleTier.Count);
Console.WriteLine("MiddleTimescaleTier.Unit:" + TimescaleUnit.Days, view.MiddleTimescaleTier.Unit.ToString());
Console.WriteLine("MiddleTimescaleTier.UsesFiscalYear: " + view.MiddleTimescaleTier.UsesFiscalYear);
Console.WriteLine("MiddleTimescaleTier.Alignment: " + StringAlignment.Center, view.MiddleTimescaleTier.Alignment.ToString());
Console.WriteLine("MiddleTimescaleTier.ShowTicks: " + view.MiddleTimescaleTier.ShowTicks.ToString());
Console.WriteLine("MiddleTimescaleTier.Label:" + DateLabel.DayDi, view.MiddleTimescaleTier.Label);
Console.WriteLine("\n************************ TOP TIMESCALE IFORMATION ******************");
Console.WriteLine("TopTimescaleTier.Unit:" + TimescaleUnit.Days, view.TopTimescaleTier.Unit.ToString());
Console.WriteLine("TopTimescaleTier.UsesFiscalYear: " + view.TopTimescaleTier.UsesFiscalYear);
Console.WriteLine("TopTimescaleTier.Alignment: " + StringAlignment.Center, view.TopTimescaleTier.Alignment.ToString());
Console.WriteLine("TopTimescaleTier.ShowTicks: " + view.TopTimescaleTier.ShowTicks.ToString());
Console.WriteLine("TopTimescaleTier.Label: ", view.TopTimescaleTier.Label.ToString());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project();
// Init Gantt Chart View
GanttChartView view = new GanttChartView();
// Set Time Scale count
view.BottomTimescaleTier.Count = 2;
view.BottomTimescaleTier.ShowTicks = false;
view.MiddleTimescaleTier.Count = 2;
view.MiddleTimescaleTier.ShowTicks = false;
// Add Gantt Chart View to project
project.Views.Add(view);
// Add some test data to project
Task task1 = project.RootTask.Children.Add("Task 1");
Task task2 = project.RootTask.Children.Add("Task 2");
task1.Set(Tsk.Duration, task1.ParentProject.GetDuration(24, TimeUnitType.Hour));
task2.Set(Tsk.Duration, task1.ParentProject.GetDuration(40, TimeUnitType.Hour));
project.Save(dataDir + "SetTimeScaleCount_out.pdf", SaveFileFormat.PDF);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Project5.mpp"); // Create a new project task
var ganttChartView = project.Views.ToList()[0] as GanttChartView;
if (ganttChartView != null)
{
ganttChartView.TableTextStyles.Clear();
ganttChartView.TableTextStyles.Add(new TableTextStyle(1) { Color = Color.Red, Field = Field.TaskName });
ganttChartView.TableTextStyles.Add(new TableTextStyle(1) { Color = Color.Gray, Field = Field.TaskDurationText });
ganttChartView.TableTextStyles.Add(new TableTextStyle(2) { Color = Color.Blue, FontStyle = FontStyle.Bold | FontStyle.Italic | FontStyle.Underline });
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create new project
Project project = new Project(dataDir + "Blank2010.mpp");
// Assign resource "1 TRG: Trade Group" to the "TASK 1" by creating a ResourceAssignment object.
Resource resource = project.Resources.GetById(1);
Task task = project.RootTask.Children.GetById(1);
ResourceAssignment assignment = project.ResourceAssignments.Add(task, resource);
// Create custom attribute definition with lookup.
ExtendedAttributeDefinition resCostAttr = ExtendedAttributeDefinition.CreateLookupResourceDefinition(
CustomFieldType.Cost,
ExtendedAttributeResource.Cost5,
"My lookup resource cost");
project.ExtendedAttributes.Add(resCostAttr);
var value1 = new Value { NumberValue = 1500, Description = "Val 1", Id = 1, Val = "1500" };
resCostAttr.AddLookupValue(value1);
resCostAttr.AddLookupValue(new Value { NumberValue = 2500, Description = "Val 2", Id = 2 });
// This value can be seen in "Resource usage" view of MS Project.
var attributeValue = resCostAttr.CreateExtendedAttribute(value1);
assignment.ExtendedAttributes.Add(attributeValue);
// Create custom attribute definition with lookup.
ExtendedAttributeDefinition taskCostAttr = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
ExtendedAttributeTask.Cost4,
"My lookup task cost");
project.ExtendedAttributes.Add(taskCostAttr);
var taskLookupValue1 = new Value { NumberValue = 18, Description = "Task val 1", Id = 3, Val = "18" };
taskCostAttr.AddLookupValue(taskLookupValue1);
resCostAttr.AddLookupValue(new Value { NumberValue = 30, Description = "Task val 2", Id = 4 });
// This value can be seen in "Task usage" view of MS Project.
assignment.ExtendedAttributes.Add(taskCostAttr.CreateExtendedAttribute(taskLookupValue1));
project.Save(dataDir + "AddExtendedAttributesToRAWithLookUp_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create new project
Project project = new Project(dataDir + "Blank2010.mpp");
// Add new task and resource
Task task1 = project.RootTask.Children.Add("Task");
Resource rsc1 = project.Resources.Add("Rsc");
// Assign the resource to the desired task
ResourceAssignment assignment = project.ResourceAssignments.Add(task1, rsc1);
// Custom attributes which is visible in "Resource Usage" view can be created with ExtendedAttributeDefinition.CreateResourceDefinition method.
{
ExtendedAttributeDefinition resCostAttributeDefinition = ExtendedAttributeDefinition.CreateResourceDefinition(
CustomFieldType.Cost,
ExtendedAttributeResource.Cost5,
"My cost");
project.ExtendedAttributes.Add(resCostAttributeDefinition);
var value = resCostAttributeDefinition.CreateExtendedAttribute();
// The type of the attribute is "Cost", so we need to use "NumericValue" property.
value.NumericValue = 1500;
assignment.ExtendedAttributes.Add(value);
}
// Custom attributes which is visible in "Task Usage" view can be created with ExtendedAttributeDefinition.CreateTaskDefinition method
{
ExtendedAttributeDefinition taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(
CustomFieldType.Cost,
ExtendedAttributeTask.Cost5,
"My cost for task");
project.ExtendedAttributes.Add(taskCostAttributeDefinition);
var value = taskCostAttributeDefinition.CreateExtendedAttribute();
// The type of the attribute is "Cost", so we need to use "NumericValue" property.
value.NumericValue = 2300;
assignment.ExtendedAttributes.Add(value);
}
project.Save(dataDir + "AddExtendedAttributesToResourceAssignment_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create empty project
Project project1 = new Project();
// Add new task and resource
Task task1 = project1.RootTask.Children.Add("Task");
Resource rsc1 = project1.Resources.Add("Rsc");
// Assign the resource desired task
ResourceAssignment assn = project1.ResourceAssignments.Add(task1, rsc1);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project instance
Project project1 = new Project(dataDir + "ResourceAssignmentTimephasedData.mpp");
// Get the first task of the Project
Task task = project1.RootTask.Children.GetById(1);
// Get the First Resource Assignment of the Project
ResourceAssignment firstRA = project1.ResourceAssignments.ToList()[0];
// Flat contour is default contour
Console.WriteLine("Flat contour");
var tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
foreach (TimephasedData td in tdList)
{
Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
}
// Change contour
firstRA.Set(Asn.WorkContour, WorkContourType.Turtle);
Console.WriteLine("Turtle contour");
tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
foreach (TimephasedData td in tdList)
{
Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
}
// Change contour
firstRA.Set(Asn.WorkContour, WorkContourType.BackLoaded);
Console.WriteLine("BackLoaded contour");
tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
foreach (TimephasedData td in tdList)
{
Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
}
// Change contour
firstRA.Set(Asn.WorkContour, WorkContourType.FrontLoaded);
Console.WriteLine("FrontLoaded contour");
tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
foreach (TimephasedData td in tdList)
{
Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
}
// Change contour
firstRA.Set(Asn.WorkContour, WorkContourType.Bell);
Console.WriteLine("Bell contour");
tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
foreach (TimephasedData td in tdList)
{
Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
}
// Change contour
firstRA.Set(Asn.WorkContour, WorkContourType.EarlyPeak);
Console.WriteLine("EarlyPeak contour");
tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
foreach (TimephasedData td in tdList)
{
Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
}
// Change contour
firstRA.Set(Asn.WorkContour, WorkContourType.LatePeak);
Console.WriteLine("LatePeak contour");
tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
foreach (TimephasedData td in tdList)
{
Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
}
// Change contour
firstRA.Set(Asn.WorkContour, WorkContourType.DoublePeak);
Console.WriteLine("DoublePeak contour");
tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
foreach (TimephasedData td in tdList)
{
Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project instance
Project project1 = new Project(dataDir + "GetGeneralResourceAssignmentProperties.mpp");
// Print general resource assignment properties
foreach (ResourceAssignment ra in project1.ResourceAssignments)
{
Console.WriteLine(ra.Get(Asn.Uid));
Console.WriteLine(ra.Get(Asn.Start).ToShortDateString());
Console.WriteLine(ra.Get(Asn.Finish).ToShortDateString());
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project instance
Project project1 = new Project(dataDir + "ResourceAssignmentBudget.mpp");
// Print assignment budget cost and budget work
foreach (ResourceAssignment ra in project1.ResourceAssignments)
{
Console.WriteLine(ra.Get(Asn.BudgetCost));
Console.WriteLine(ra.Get(Asn.BudgetWork).ToString());
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project instance
Project project1 = new Project(dataDir + "ResourceAssignmentCosts.mpp");
// Print resource assignment costs
foreach (ResourceAssignment ra in project1.ResourceAssignments)
{
Console.WriteLine(ra.Get(Asn.Cost));
Console.WriteLine(ra.Get(Asn.ACWP));
Console.WriteLine(ra.Get(Asn.BCWP));
Console.WriteLine(ra.Get(Asn.BCWS));
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project instance
Project project1 = new Project(dataDir + "ResourceAssignmentOvertimes.mpp");
// Print assignment overtimes
foreach (ResourceAssignment ra in project1.ResourceAssignments)
{
Console.WriteLine(ra.Get(Asn.OvertimeCost));
Console.WriteLine(ra.Get(Asn.OvertimeWork).ToString());
Console.WriteLine(ra.Get(Asn.RemainingCost));
Console.WriteLine(ra.Get(Asn.RemainingOvertimeCost));
Console.WriteLine(ra.Get(Asn.RemainingOvertimeWork).ToString());
Console.WriteLine(ra.Get(Asn.RemainingOvertimeWork).ToString());
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project instance
Project project1 = new Project(dataDir + "ResourceAssignmentPercentWorkComplete.mpp");
// Print assignment percent completion
foreach (ResourceAssignment ra in project1.ResourceAssignments)
{
Console.WriteLine(ra.Get(Asn.PercentWorkComplete).ToString());
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project instance
Project project1 = new Project(dataDir + "ResourceAssignmentStopResumeDates.mpp");
// Print resource assignment's stop and resume dates
foreach (ResourceAssignment ra in project1.ResourceAssignments)
{
if (ra.Get(Asn.Stop).ToShortDateString() == "1/1/2000")
Console.WriteLine("NA");
else
Console.WriteLine(ra.Get(Asn.Stop).ToShortDateString());
if (ra.Get(Asn.Resume).ToShortDateString() == "1/1/2000")
Console.WriteLine("NA");
else
Console.WriteLine(ra.Get(Asn.Resume).ToShortDateString());
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project instance
Project project1 = new Project(dataDir + "ResourceAssignmentVariance.mpp");
// Print assignment variances
foreach (ResourceAssignment ra in project1.ResourceAssignments)
{
Console.WriteLine(ra.Get(Asn.WorkVariance));
Console.WriteLine(ra.Get(Asn.CostVariance));
Console.WriteLine(ra.Get(Asn.StartVariance));
Console.WriteLine(ra.Get(Asn.FinishVariance));
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
Project project = new Project(dataDir + "New project 2013.mpp");
var task = project.RootTask.Children.Add("t1");
var materialResource = project.Resources.Add("materialResource");
materialResource.Set(Rsc.Type, ResourceType.Material);
var nonMaterialResource = project.Resources.Add("nonMaterialResource");
nonMaterialResource.Set(Rsc.Type, ResourceType.Work);
var materialResourceAssignment = project.ResourceAssignments.Add(task, materialResource);
materialResourceAssignment.Set(Asn.RateScale, RateScaleType.Week);
var nonMaterialResourceAssignment = project.ResourceAssignments.Add(task, nonMaterialResource);
nonMaterialResourceAssignment.Set(Asn.RateScale, RateScaleType.Week);
project.Save("output.mpp", SaveFileFormat.MPP);
var resavedProject = new Project("output.mpp");
var resavedMaterialResourceAssignment = resavedProject.ResourceAssignments.GetByUid(1);
Console.WriteLine(resavedMaterialResourceAssignment.Get(Asn.RateScale));
// only material resource assignments can have non-zero rate scale value.
var resavedNonMaterialResourceAssignment = resavedProject.ResourceAssignments.GetByUid(2);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create empty project
Project project1 = new Project();
// Add new task and resource
Task task1 = project1.RootTask.Children.Add("Task");
Resource rsc1 = project1.Resources.Add("Rsc");
rsc1.Set(Rsc.StandardRate, 10);
rsc1.Set(Rsc.OvertimeRate, 15);
// Assign the resource desired task
ResourceAssignment assn = project1.ResourceAssignments.Add(task1, rsc1);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project instance and access first task and resource
Project project1 = new Project(dataDir + "UpdateResourceAssignment.mpp");
Task task = project1.RootTask.Children.GetById(1);
Resource rsc = project1.Resources.GetById(1);
// Create resource assignment
ResourceAssignment assn = project1.ResourceAssignments.Add(task, rsc);
assn.Set(Asn.Notes, "Newly added assignment");
// Save project as MPP
project1.Save(dataDir + "UpdateResourceAssignment_out.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Add resources
Resource rsc1 = project.Resources.Add("Rsc");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-.NET
// Create project instance
Project project1 = new Project(dataDir + "ResourceCalendar.mpp");
// Display base calendar name for all resources
foreach (Resource res in project1.Resources)
{
if (res.Get(Rsc.Name) != null)
{
Console.WriteLine(res.Get(Rsc.Calendar).BaseCalendar.Name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment