none
urgent : Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH)) RRS feed

  • Question

  • i m trying to display word file stored in sql on browser ,plz help me, where i m wrong..

    public

    partial class _Default : System.Web.UI.Page

    {

    protected object readOnly = false;

     

    protected object isVisible = false;

     

    object fltformat = 10;

     

    protected object missing = System.Reflection.Missing.Value;

     

    protected void Page_Load(object sender, EventArgs e)

    {

     

     

    // Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();

     

    SqlConnection objMyConnection = new SqlConnection("Data Source=USER59-PC;initial catalog=master;User ID=sa;Password=shekhar;");

     

    //OleDbCommand objMyCommand = new OleDbCommand();

     

    string strSQL = "Select Top 1 QuesDesc,ItemCode From OMT ";

     

    SqlDataAdapter objMyAdapter = new SqlDataAdapter(strSQL, objMyConnection);

     

    DataSet dsMyDataSet = new DataSet();

     

    try

    {

    objMyConnection.Open();

    objMyAdapter.Fill(dsMyDataSet,

    "OMT");

     

    DataRow objMyRow = default(DataRow);

    objMyRow = dsMyDataSet.Tables[

    "OMT"].Rows[0];

     

    object objMyData = null;

    objMyData = objMyRow[

    "QuesDesc"];

     

    //objMyData="D:\\ShekharDocuments\\Projects\\oleobjectsaveasfile\\oleobjectsaveasfile\\shashishekharresume.doc";

     

     

    //string itemcode = dsMyDataSet.Tables["OMT"].Columns[1].ToString();

    Word.

    ApplicationClass word = new Word.ApplicationClass();

    // error occurs here
    Word.

    Document doc = word.Documents.Open(ref objMyData, ref missing,

     

    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,

     

    ref missing, ref missing, ref missing);// Error Occurs here

    Word.

    Document doc1 = word.ActiveDocument;

     

    string m_content = doc1.Content.Text;

    Response.Write(m_content);

     

    //doc.Activate();

     

    int attachmentsCount = doc.InlineShapes.Count;

     

     

    for (int i = 0; i < attachmentsCount; i++)

     

     

    foreach (Word.InlineShape inline in doc.InlineShapes)

    {

     

    if (inline.OLEFormat.ProgID != null)

    {

     

    switch (inline.OLEFormat.ProgID)

    {

     

    case "Word.Document 12":

    Word.

    Document document = new Word.Document();

     

    object filename = @"C:\\shashi123";

     

    //object missing = null;

    document.SaveAs(

    ref filename, ref fltformat, ref missing, ref missing, ref missing, ref missing, ref missing,

     

    ref missing, ref missing, ref missing, ref missing);

     

    break;

     

    default:

     

    break;

    }

     

    }

    }

     

    objMyConnection.Close();

    objMyAdapter.Dispose();

    dsMyDataSet.Dispose();

    }

     

    catch (SqlException sqEx)

    {

    Response.Write(

    "SQL Error Occured : " + sqEx.ToString());

    }

    }

    }

    Friday, July 31, 2009 5:10 AM

Answers

  • It is not a string, it has to be a string to keep Word happy.

    Hans Passant.
    • Marked as answer by eryang Friday, August 7, 2009 1:14 AM
    Friday, July 31, 2009 10:28 AM
    Moderator
  • The first parameter of method word.Documents.Open() must be a string (runtime type), standing for a file name.
    You may try something like this:
        objMyData = objMyRow["QuesDesc"] as string;

    Thanks,
    Eric


    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    • Edited by eryang Friday, August 7, 2009 2:46 AM
    • Marked as answer by eryang Friday, August 7, 2009 2:47 AM
    Thursday, August 6, 2009 10:00 AM

All replies

  • It is not a string, it has to be a string to keep Word happy.

    Hans Passant.
    • Marked as answer by eryang Friday, August 7, 2009 1:14 AM
    Friday, July 31, 2009 10:28 AM
    Moderator
  • The first parameter of method word.Documents.Open() must be a string (runtime type), standing for a file name.
    You may try something like this:
        objMyData = objMyRow["QuesDesc"] as string;

    Thanks,
    Eric


    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    • Edited by eryang Friday, August 7, 2009 2:46 AM
    • Marked as answer by eryang Friday, August 7, 2009 2:47 AM
    Thursday, August 6, 2009 10:00 AM