Quantcast
Channel: Word for Developers forum
Viewing all articles
Browse latest Browse all 4350

How to Insert the Citation with the corresponding Bibliography using c#

$
0
0

Hi,

I want to know how to insert the citation with the corresponding bibliography in the active document,I  code and tried to make what I want but no luck, I still can't insert the citation with the corresponding bibliography.

I have code here I hope someone can help me solve my problem.

private void InsertCitation_Click(object sender, RibbonControlEventArgs e)
        {
            // Insert a citation after the text just inserted to the bibliography
            // source added previously.
            Application wordApplication = Globals.ThisAddIn.Application;
            //wordApplication.Selection.EndKey(ref paramWdUnits,ref paramWdMovementType);
            wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
               ref paramWdFieldTypeCitation, dropDown1.SelectedItem.Label,//ref paramBiblioSourceTag,
                ref paramMissing);
           // wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,

                   // ref paramWdFieldTypeCitation,
              //   ref paramBiblioSourceTag,ref paramMissing);
           
            
            // Insert a page break after the citation added previously and then
            // add a bibliography to the document.
            Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
            Word.Range rng = doc.Content;
            object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
            rng.Collapse(ref oCollapseEnd);
            wordApplication.Selection.EndKey(ref paramWdUnits, ref paramWdMovementType);
            wordApplication.Selection.InsertBreak(WdBreakType.wdLineBreak);

            //If find the Bibliography field in the document then update the field
            //otherwise insert a Bibliography field 
            bool isFoundFieldBibliography = false;
            foreach (Field field in wordApplication.ActiveDocument.Range().Fields)
            {
                if (field.Type == WdFieldType.wdFieldBibliography)
                {
                    isFoundFieldBibliography = true;
                    //update BibliographyField
                    field.Update();
                }
            }
            if (!isFoundFieldBibliography)
            {
                wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                ref paramWdFieldTypeBiblio, ref paramMissing, ref paramMissing);

            }
        }private void RefreshBibliography_Click(object sender, RibbonControlEventArgs e)
        {
            Refresh_Bibliography();
        }
        private void Refresh_Bibliography()
        {
            this.dropDown1.Items.Clear();
            foreach (Source source in Globals.ThisAddIn.Application.ActiveDocument.Bibliography.Sources)
            {
                RibbonDropDownItem item = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
                item.Label = source.Tag;
                this.dropDown1.Items.Add(item);
            }
        }

what happen in this code is when I press Insert Citation the Citation is being Inserted and the Bibliography , the problem is after the Citation Inserted all Bibliography is being insert too and what I want is only the corresponding bibliography of the inserted citation will be insert in the active document.

please help me.

Thank you in advance

More Power

God Bless


Viewing all articles
Browse latest Browse all 4350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>