Hi,
I have a code here that use a listbox to view all the sources in the current list now my problem is that I don't know how to insert the citaiton if I choose one of the source in the listbox and then click the button "Insert Citation" but I tried to do it but I'm having a problem and I still doubt for the code in inserting a citation ,I'm sure it's wrong.
by the way here's my code
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Microsoft.Office.Tools.Ribbon; using Microsoft.Office.Interop.Word; using Word = Microsoft.Office.Interop.Word; namespace WordAddIn5 { public partial class Form1 : Form { Application wordApplication = null; Document wordDocument = null; object paramMissing = Type.Missing; object paramWdUnits = WdUnits.wdStory; object paramWdMovementType = WdMovementType.wdMove; object paramWdFieldTypeCitation = WdFieldType.wdFieldCitation; object paramWdFieldTypeBiblio = WdFieldType.wdFieldBibliography; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { BindListBox(GetCurrentList()); } private string[] GetCurrentList() { Word.Application App = Globals.ThisAddIn.Application; Word.Document doc = App.ActiveDocument; Word.Sources sour = doc.Bibliography.Sources; string[] strItems = new string[sour.Count]; for (int i = 1; i <= sour.Count; i++) { Word.Source ssour = sour[i]; strItems[i - 1] = ssour.Field["Author"] + "; " + ssour.Field["Title"] + " (" + ssour.Field["Year"] + ")" +ssour.Field["Publisher"]; } return strItems; } private void BindListBox(string[] strItems) { listBox1.Items.Clear(); for (int i = 0; i < strItems.Length; i++) { listBox1.Items.Add(strItems[i]); } } private void button2_Click(object sender, EventArgs 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, listBox1.SelectedItems.ToString/*ref paramBiblioSourceTag*/, ref paramMissing); // Insert a page break after the citation added previously and then // add a bibliography to the document. wordApplication.Selection.EndKey(ref paramWdUnits, ref paramWdMovementType); wordApplication.Selection.InsertBreak(WdBreakType.wdLineBreak); wordApplication.Selection.InsertBreak(WdBreakType.wdLineBreak); wordApplication.Selection.InsertBreak(WdBreakType.wdLineBreak); 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); } } } }
here's the error I get running that coce
Error1'Application' is an ambiguous reference between 'System.Windows.Forms.Application' and 'Microsoft.Office.Interop.Word.Application'and I thnk my code in inserting a citaiton is wrong ,please try to run my code
Thank you in advacne
More Power
God Bless