/// <summary> /// Generate control file /// </summary> private void GenerateControlFile() { string strPageID; string strDefaultLayout; string strPageLayout; string strPageType; ArrayList objPages = new ArrayList(); //1. Get the required data strDefaultLayout = lstDefaultLayout.SelectedValue; foreach (DataGridItem dgrItem in dgrPages.Items) { ListBox lstLayout = (ListBox)dgrItem.FindControl("lstPageLayout"); Literal litPageID = (Literal)dgrItem.FindControl("litPageID"); Literal litPageType = (Literal)dgrItem.FindControl("litPageType"); // Get the page layout value strPageLayout = lstLayout.SelectedValue; strPageID = litPageID.Text; strPageType = litPageType.Text; // If layout contains the '-- Use Default--' stlye entry then use the page level entry if (strPageLayout == cm_strDefault) { strPageLayout = strDefaultLayout; } objPages.Add(new ControlFilePage(strPageID, strPageLayout, strPageType)); } //2. Populate the control file ControlFile objControlFile = new ControlFile(objPages); objControlFile.DefaultLayout = strDefaultLayout; objControlFile.Style = lstStyle.SelectedValue; //3. Serialize the control class to Xml file XmlSerializer objSer = new XmlSerializer(objControlFile.GetType()); FileStream fsControlFile = new FileStream(lblGeneratePath.Text + "\\Control.xml", FileMode.Create, FileAccess.Write, FileShare.ReadWrite); objSer.Serialize(fsControlFile, objControlFile); // Flush close and quit fsControlFile.Flush(); fsControlFile.Close(); }