Hi I am creating Spell Checker for my c# application. I am using using Microsoft.Office.Interop.Word; dlls but having error.
I have tested my code in VB.Net and it is working fi9 but now I have to c# and having errors in my code
private void SpellOrGrammarCheck(bool blnSpellOnly)
{
try
{
object objWord;
object objTempDoc;
IDataObject iData;
if (TextBox1.Text == "")
{
return;
}
objWord = new Microsoft.Office.Interop.Word.Application();
objTempDoc = objWord.Documents.Add();
objWord.Visible = false;
objWord.WindowState = 0;
objWord.Top = - 3000;
Clipboard.SetDataObject(TextBox1.Text);
objTempDoc.Content.Paste();
objTempDoc.Activate();
if (blnSpellOnly)
{
objTempDoc.CheckSpelling();
}
else
{
objTempDoc.CheckGrammar();
}
objTempDoc.Content.Copy();
iData = Clipboard.GetDataObject();
if (iData.GetDataPresent(DataFormats.Text))
{
TextBox1.Text = System.Convert.ToString(iData.GetData(DataFormats.Text, System.Convert.ToBoolean(null)));
}
objTempDoc.Saved = true;
objTempDoc.Close();
objWord.Quit();
MessageBox.Show("The spelling check is complete.", "Spell Checker", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Runtime.InteropServices.COMException)
{
MessageBox.Show("Microsoft Word must be installed for Spell/Grammar Check " + "to run.", "Spell Checker");
}
catch (Exception)
{
MessageBox.Show("An error has occurred.", "Spell Checker");
}
}