ComponentOne GanttView for WinForms
Working with GanttView / Save and Load
In This Topic
    Save and Load
    In This Topic

    This topic discusses how you can save the content of the C1GanttView project as an XML file and how to load an existing C1GanttView project from an xml file.

    Save as XML File

    GanttView allows you to save the grid in XML format. You can use SaveXml method of the C1GanttView class which serializes the grid content into Xml document. This method serializes the content stored in the cells along with its properties and styles. Other than that, you can also save your file as Xml document at run time.

    To save the content of C1GanttView as xml file programmatically, add the below code.

    C#
    Copy Code
    //Save file as xml document
    using (SaveFileDialog dlg = new SaveFileDialog())
        {
            dlg.DefaultExt = ".xml";
            dlg.FileName = "gantt";
            dlg.Filter = "XML files|*.xml|All files|*.*";
            dlg.Title = "Save Gantt View As Xml File";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                c1GanttView1.SaveXml(dlg.FileName);
            }
        }
    

    To save the content of C1GanttView as xml file at run time, follow the steps below:

    1. Click the Save as XML File button from the C1GanttView toolbar button.
      The Save As Xml File dialog box appears.
    2. Browse to the location you wish to save the .xml file.
    3. Click Save in the Save As Xml File dialog box.

    Load from XML File

    You can de-serialize the grid content from an existing XML file by using the LoadXml method of the C1GanttView class which takes the path of the XML document as a parameter.

    Use the code below to load contents for the GanttView control from an existing XML document.

    C#
    Copy Code
    //Load the content from an existing XML document
    using (OpenFileDialog dlg = new OpenFileDialog())
        {
            dlg.DefaultExt = ".xml";
            dlg.Filter = "XML files|*.xml|All files|*.*";
            dlg.Title = "Load Gantt View From Xml File";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    c1GanttView1.LoadXml(dlg.FileName);
                }
                catch
                {
                    MessageBox.Show("Bad C1GanttView XML.", dlg.Title);
                }
            }
        }
    

    To load the content of C1GanttView from an XML file at run time, follow the steps below:

    1. Click the Load From XML File icon in the C1GanttView toolbar.
      The Load From Xml File dialog box appears.
    2. Browse to the location you wish to load the xml file.
    3. Click Open in the Load From Xml File dialog box.