Process to open a document

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan T

    Process to open a document

    I have created a mail merged document at run time.
    However, I cannot open the document everytime, sometime it did not get
    opened, sometimes it can.
    The document may be Word or text file.

    public static void OpenDocument(st ring aFilename)

    {

    IntPtr result;

    Process convertProcess = new Process();

    try

    {

    convertProcess. StartInfo.Domai n = "";

    convertProcess. StartInfo.FileN ame = aFilename;

    convertProcess. StartInfo.Creat eNoWindow = true;

    convertProcess. StartInfo.Windo wStyle =
    System.Diagnost ics.ProcessWind owStyle.Maximiz ed;

    convertProcess. StartInfo.Stand ardErrorEncodin g = null;

    convertProcess. StartInfo.Stand ardOutputEncodi ng = null;

    convertProcess. StartInfo.UseSh ellExecute = true;

    convertProcess. StartInfo.LoadU serProfile = false;

    convertProcess. StartInfo.Passw ord = null;

    convertProcess. StartInfo.UserN ame = "";

    convertProcess. Start();

    convertProcess. Dispose();

    }

    catch (Exception e)

    {

    try

    {

    convertProcess. Dispose();

    }

    catch

    {

    }

    }


    }


  • Chan Ming Man

    #2
    Re: Process to open a document

    Text file? Text file sure cannot run macro. You are using VSTO or just VBA?

    chanmm

    "Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
    news:u1qSogPGHH A.4652@TK2MSFTN GP04.phx.gbl...
    >I have created a mail merged document at run time.
    However, I cannot open the document everytime, sometime it did not get
    opened, sometimes it can.
    The document may be Word or text file.
    >
    public static void OpenDocument(st ring aFilename)
    >
    {
    >
    IntPtr result;
    >
    Process convertProcess = new Process();
    >
    try
    >
    {
    >
    convertProcess. StartInfo.Domai n = "";
    >
    convertProcess. StartInfo.FileN ame = aFilename;
    >
    convertProcess. StartInfo.Creat eNoWindow = true;
    >
    convertProcess. StartInfo.Windo wStyle =
    System.Diagnost ics.ProcessWind owStyle.Maximiz ed;
    >
    convertProcess. StartInfo.Stand ardErrorEncodin g = null;
    >
    convertProcess. StartInfo.Stand ardOutputEncodi ng = null;
    >
    convertProcess. StartInfo.UseSh ellExecute = true;
    >
    convertProcess. StartInfo.LoadU serProfile = false;
    >
    convertProcess. StartInfo.Passw ord = null;
    >
    convertProcess. StartInfo.UserN ame = "";
    >
    convertProcess. Start();
    >
    convertProcess. Dispose();
    >
    }
    >
    catch (Exception e)
    >
    {
    >
    try
    >
    {
    >
    convertProcess. Dispose();
    >
    }
    >
    catch
    >
    {
    >
    }
    >
    }
    >
    >
    }
    >
    >

    Comment

    • Alan T

      #3
      Re: Process to open a document

      Hi,

      The method I stated was written by C#, the parameter aFilename is the full
      path file name.

      "Chan Ming Man" <chanmmn@hotmai l.comwrote in message
      news:F9305FA8-7DD4-41F2-A2F3-50DADBD25B92@mi crosoft.com...
      Text file? Text file sure cannot run macro. You are using VSTO or just
      VBA?
      >
      chanmm
      >
      "Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
      news:u1qSogPGHH A.4652@TK2MSFTN GP04.phx.gbl...
      >>I have created a mail merged document at run time.
      >However, I cannot open the document everytime, sometime it did not get
      >opened, sometimes it can.
      >The document may be Word or text file.
      >>
      >public static void OpenDocument(st ring aFilename)
      >>
      >{
      >>
      > IntPtr result;
      >>
      > Process convertProcess = new Process();
      >>
      > try
      >>
      > {
      >>
      > convertProcess. StartInfo.Domai n = "";
      >>
      > convertProcess. StartInfo.FileN ame = aFilename;
      >>
      > convertProcess. StartInfo.Creat eNoWindow = true;
      >>
      > convertProcess. StartInfo.Windo wStyle =
      >System.Diagnos tics.ProcessWin dowStyle.Maximi zed;
      >>
      > convertProcess. StartInfo.Stand ardErrorEncodin g = null;
      >>
      > convertProcess. StartInfo.Stand ardOutputEncodi ng = null;
      >>
      > convertProcess. StartInfo.UseSh ellExecute = true;
      >>
      > convertProcess. StartInfo.LoadU serProfile = false;
      >>
      > convertProcess. StartInfo.Passw ord = null;
      >>
      > convertProcess. StartInfo.UserN ame = "";
      >>
      > convertProcess. Start();
      >>
      > convertProcess. Dispose();
      >>
      > }
      >>
      > catch (Exception e)
      >>
      > {
      >>
      > try
      >>
      > {
      >>
      > convertProcess. Dispose();
      >>
      > }
      >>
      > catch
      >>
      > {
      >>
      > }
      >>
      >}
      >>
      >>
      >}
      >>
      >>
      >

      Comment

      • Chan Ming Man

        #4
        Re: Process to open a document

        Did you check the process? Can it be the program is running but the Word is
        not appearing?

        chanmm

        "Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
        news:OA4f14YGHH A.1468@TK2MSFTN GP04.phx.gbl...
        Hi,
        >
        The method I stated was written by C#, the parameter aFilename is the full
        path file name.
        >
        "Chan Ming Man" <chanmmn@hotmai l.comwrote in message
        news:F9305FA8-7DD4-41F2-A2F3-50DADBD25B92@mi crosoft.com...
        >Text file? Text file sure cannot run macro. You are using VSTO or just
        >VBA?
        >>
        >chanmm
        >>
        >"Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
        >news:u1qSogPGH HA.4652@TK2MSFT NGP04.phx.gbl.. .
        >>>I have created a mail merged document at run time.
        >>However, I cannot open the document everytime, sometime it did not get
        >>opened, sometimes it can.
        >>The document may be Word or text file.
        >>>
        >>public static void OpenDocument(st ring aFilename)
        >>>
        >>{
        >>>
        >> IntPtr result;
        >>>
        >> Process convertProcess = new Process();
        >>>
        >> try
        >>>
        >> {
        >>>
        >> convertProcess. StartInfo.Domai n = "";
        >>>
        >> convertProcess. StartInfo.FileN ame = aFilename;
        >>>
        >> convertProcess. StartInfo.Creat eNoWindow = true;
        >>>
        >> convertProcess. StartInfo.Windo wStyle =
        >>System.Diagno stics.ProcessWi ndowStyle.Maxim ized;
        >>>
        >> convertProcess. StartInfo.Stand ardErrorEncodin g = null;
        >>>
        >> convertProcess. StartInfo.Stand ardOutputEncodi ng = null;
        >>>
        >> convertProcess. StartInfo.UseSh ellExecute = true;
        >>>
        >> convertProcess. StartInfo.LoadU serProfile = false;
        >>>
        >> convertProcess. StartInfo.Passw ord = null;
        >>>
        >> convertProcess. StartInfo.UserN ame = "";
        >>>
        >> convertProcess. Start();
        >>>
        >> convertProcess. Dispose();
        >>>
        >> }
        >>>
        >> catch (Exception e)
        >>>
        >> {
        >>>
        >> try
        >>>
        >> {
        >>>
        >> convertProcess. Dispose();
        >>>
        >> }
        >>>
        >> catch
        >>>
        >> {
        >>>
        >> }
        >>>
        >>}
        >>>
        >>>
        >>}
        >>>
        >>>
        >>
        >
        >

        Comment

        • Alan T

          #5
          Re: Process to open a document

          The document did not get opened and also the MS Word did not run.

          "Chan Ming Man" <chanmmn@hotmai l.comwrote in message
          news:3B9BDDAD-69D7-4BC4-B30B-27F5E6EFAE48@mi crosoft.com...
          Did you check the process? Can it be the program is running but the Word
          is not appearing?
          >
          chanmm
          >
          "Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
          news:OA4f14YGHH A.1468@TK2MSFTN GP04.phx.gbl...
          >Hi,
          >>
          >The method I stated was written by C#, the parameter aFilename is the
          >full path file name.
          >>
          >"Chan Ming Man" <chanmmn@hotmai l.comwrote in message
          >news:F9305FA 8-7DD4-41F2-A2F3-50DADBD25B92@mi crosoft.com...
          >>Text file? Text file sure cannot run macro. You are using VSTO or just
          >>VBA?
          >>>
          >>chanmm
          >>>
          >>"Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
          >>news:u1qSogPG HHA.4652@TK2MSF TNGP04.phx.gbl. ..
          >>>>I have created a mail merged document at run time.
          >>>However, I cannot open the document everytime, sometime it did not get
          >>>opened, sometimes it can.
          >>>The document may be Word or text file.
          >>>>
          >>>public static void OpenDocument(st ring aFilename)
          >>>>
          >>>{
          >>>>
          >>> IntPtr result;
          >>>>
          >>> Process convertProcess = new Process();
          >>>>
          >>> try
          >>>>
          >>> {
          >>>>
          >>> convertProcess. StartInfo.Domai n = "";
          >>>>
          >>> convertProcess. StartInfo.FileN ame = aFilename;
          >>>>
          >>> convertProcess. StartInfo.Creat eNoWindow = true;
          >>>>
          >>> convertProcess. StartInfo.Windo wStyle =
          >>>System.Diagn ostics.ProcessW indowStyle.Maxi mized;
          >>>>
          >>> convertProcess. StartInfo.Stand ardErrorEncodin g = null;
          >>>>
          >>> convertProcess. StartInfo.Stand ardOutputEncodi ng = null;
          >>>>
          >>> convertProcess. StartInfo.UseSh ellExecute = true;
          >>>>
          >>> convertProcess. StartInfo.LoadU serProfile = false;
          >>>>
          >>> convertProcess. StartInfo.Passw ord = null;
          >>>>
          >>> convertProcess. StartInfo.UserN ame = "";
          >>>>
          >>> convertProcess. Start();
          >>>>
          >>> convertProcess. Dispose();
          >>>>
          >>> }
          >>>>
          >>> catch (Exception e)
          >>>>
          >>> {
          >>>>
          >>> try
          >>>>
          >>> {
          >>>>
          >>> convertProcess. Dispose();
          >>>>
          >>> }
          >>>>
          >>> catch
          >>>>
          >>> {
          >>>>
          >>> }
          >>>>
          >>>}
          >>>>
          >>>>
          >>>}
          >>>>
          >>>>
          >>>
          >>
          >>
          >

          Comment

          • Samik R.

            #6
            Re: Process to open a document

            Why are you calling the Dispose() method immediately after Start()? Can
            it be that the process is starting and then closing immediately?
            -Samik

            On 12/7/2006 4:23 PM, Alan T wrote:
            The document did not get opened and also the MS Word did not run.
            >
            "Chan Ming Man" <chanmmn@hotmai l.comwrote in message
            news:3B9BDDAD-69D7-4BC4-B30B-27F5E6EFAE48@mi crosoft.com...
            >Did you check the process? Can it be the program is running but the Word
            >is not appearing?
            >>
            >chanmm
            >>
            >"Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
            >news:OA4f14YGH HA.1468@TK2MSFT NGP04.phx.gbl.. .
            >>Hi,
            >>>
            >>The method I stated was written by C#, the parameter aFilename is the
            >>full path file name.
            >>>
            >>"Chan Ming Man" <chanmmn@hotmai l.comwrote in message
            >>news:F9305F A8-7DD4-41F2-A2F3-50DADBD25B92@mi crosoft.com...
            >>>Text file? Text file sure cannot run macro. You are using VSTO or just
            >>>VBA?
            >>>>
            >>>chanmm
            >>>>
            >>>"Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
            >>>news:u1qSogP GHHA.4652@TK2MS FTNGP04.phx.gbl ...
            >>>>I have created a mail merged document at run time.
            >>>>However, I cannot open the document everytime, sometime it did not get
            >>>>opened, sometimes it can.
            >>>>The document may be Word or text file.
            >>>>>
            >>>>public static void OpenDocument(st ring aFilename)
            >>>>>
            >>>>{
            >>>>>
            >>>> IntPtr result;
            >>>>>
            >>>> Process convertProcess = new Process();
            >>>>>
            >>>> try
            >>>>>
            >>>> {
            >>>>>
            >>>> convertProcess. StartInfo.Domai n = "";
            >>>>>
            >>>> convertProcess. StartInfo.FileN ame = aFilename;
            >>>>>
            >>>> convertProcess. StartInfo.Creat eNoWindow = true;
            >>>>>
            >>>> convertProcess. StartInfo.Windo wStyle =
            >>>>System.Diag nostics.Process WindowStyle.Max imized;
            >>>>>
            >>>> convertProcess. StartInfo.Stand ardErrorEncodin g = null;
            >>>>>
            >>>> convertProcess. StartInfo.Stand ardOutputEncodi ng = null;
            >>>>>
            >>>> convertProcess. StartInfo.UseSh ellExecute = true;
            >>>>>
            >>>> convertProcess. StartInfo.LoadU serProfile = false;
            >>>>>
            >>>> convertProcess. StartInfo.Passw ord = null;
            >>>>>
            >>>> convertProcess. StartInfo.UserN ame = "";
            >>>>>
            >>>> convertProcess. Start();
            >>>>>
            >>>> convertProcess. Dispose();
            >>>>>
            >>>> }
            >>>>>
            >>>> catch (Exception e)
            >>>>>
            >>>> {
            >>>>>
            >>>> try
            >>>>>
            >>>> {
            >>>>>
            >>>> convertProcess. Dispose();
            >>>>>
            >>>> }
            >>>>>
            >>>> catch
            >>>>>
            >>>> {
            >>>>>
            >>>> }
            >>>>>
            >>>>}
            >>>>>
            >>>>>
            >>>>}
            >>>>>
            >>>>>
            >>>
            >
            >

            Comment

            Working...