private byte[] GetItemDocument(string id)
        {
            WordHelper wordHelper = new WordHelper();

            ItemType itemType = Functions.GetItemType(id);

            byte[] binWordFile = null;

            if (itemType == ItemType.Schema)
            {
                SchemaDocumentData schemaData = SchemaHelper.GetSchemaData(Functions.Client, id);
                if (schemaData == null)
                {
                    throw new Exception("Schema is null");
                }
                binWordFile = wordHelper.CreateSchemaDocument(schemaData, System.IO.Path.Combine(".", "schema.docx"));
            }
            if (itemType == ItemType.PageTemplate)
            {
                PageTemplateDocumentData ptData = PageTemplateHelper.GetPageTemplateData(Functions.Client, id);
                if (ptData == null)
                {
                    throw new Exception("Page Template is null");
                }
                binWordFile = wordHelper.CreatePageTemplateDocument(ptData, System.IO.Path.Combine(".", "pt.docx"));
            }
            if (itemType == ItemType.ComponentTemplate)
            {
                ComponentTemplateDocumentData ctData = ComponentTemplateHelper.GetComponentTemplateData(Functions.Client, id);
                if (ctData == null)
                {
                    throw new Exception("Component Template is null");
                }
                binWordFile = wordHelper.CreateComponentTemplateDocument(ctData, System.IO.Path.Combine(".", "ct.docx"));
            }
            if (itemType == ItemType.TemplateBuildingBlock)
            {
                TbbDocumentData tbbData = TBBHelper.GetTBBData(Functions.Client, id);
                if (tbbData == null)
                {
                    throw new Exception("TBB is null");
                }
                binWordFile = wordHelper.CreateTbbDocument(tbbData, System.IO.Path.Combine(".", "tbb.docx"));
            }

            return binWordFile;
        }
        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string resultFileName = System.IO.Path.Combine(this.txtFolder.Text, "Item_" + this.TridionObject.TcmId.GetId() + ".docx");

                if (this.chkDependencies.IsChecked == true)
                {
                    List<string> chainIds = new List<string>();
                    FillUsingChain(this.TridionObject.TcmId, chainIds);
                    chainIds = chainIds.Distinct().ToList();

                    List<byte[]> chainFiles = new List<byte[]>();
                    chainFiles.AddRange(chainIds.Select(GetItemDocument));

                    WordHelper wordHelper = new WordHelper();
                    wordHelper.JoinDocuments(chainFiles, resultFileName);
                }
                else
                {
                    byte[] resultFile = GetItemDocument(this.TridionObject.TcmId);
                    System.IO.File.WriteAllBytes(resultFileName, resultFile);
                }

                Process.Start(resultFileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }