Process.Start() not starting

Discussion in 'ASP .Net' started by xzzy, Jan 8, 2007.

  1. xzzy

    xzzy Guest

    In the follwoing code, myProcess.StartInfo.FileName is set to a valid path:
    c:\\hello.doc

    The code produces the following error message: "%1 is not a valid Win32
    application"

    For c:\\hello.doc, I would expect the following code to open a Word document
    in a normal window.


    //code++++++++++++++++++++++++++++++++
    Process myProcess = new Process();

    try
    {
    LinkButton btnClicked = (LinkButton)sender;
    int myID = 1;
    myClass.GetByID(myID);
    myProcess.StartInfo.FileName = myClass.myDirectory + myClass.myFileName;
    myProcess.StartInfo.UseShellExecute = false;
    myProcess.StartInfo.WindowStyle =
    System.Diagnostics.ProcessWindowStyle.Normal;
    myProcess.StartInfo.CreateNoWindow = false;
    myProcess.Start();
    }

    catch (Exception ex)
    {

    //end code++++++++++++++++++++++++++++++++

    Thank you,

    John
     
    xzzy, Jan 8, 2007
    #1
    1. Advertising

  2. Take a close look at what "myClass.myDirectory + myClass.myFileName;" returns.

    I bet you're not getting a valid filename or directory path out of it.



    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ===================================
    "xzzy" <> wrote in message
    news:...
    >
    > In the follwoing code, myProcess.StartInfo.FileName is set to a valid path: c:\\hello.doc
    >
    > The code produces the following error message: "%1 is not a valid Win32 application"
    >
    > For c:\\hello.doc, I would expect the following code to open a Word document in a normal window.
    >
    >
    > //code++++++++++++++++++++++++++++++++
    > Process myProcess = new Process();
    >
    > try
    > {
    > LinkButton btnClicked = (LinkButton)sender;
    > int myID = 1;
    > myClass.GetByID(myID);
    > myProcess.StartInfo.FileName = myClass.myDirectory + myClass.myFileName;
    > myProcess.StartInfo.UseShellExecute = false;
    > myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
    > myProcess.StartInfo.CreateNoWindow = false;
    > myProcess.Start();
    > }
    >
    > catch (Exception ex)
    > {
    >
    > //end code++++++++++++++++++++++++++++++++
    >
    > Thank you,
    >
    > John
    >
     
    Juan T. Llibre, Jan 9, 2007
    #2
    1. Advertising

  3. xzzy

    bruce barker Guest

    asp.net because its a service and does not have access to the desktop,
    can not start a window app only a command line.

    if you want to start word (which is not recommanded), you need to use
    the automation api.

    -- bruce (sqlwork.com)

    xzzy wrote:
    > In the follwoing code, myProcess.StartInfo.FileName is set to a valid path:
    > c:\\hello.doc
    >
    > The code produces the following error message: "%1 is not a valid Win32
    > application"
    >
    > For c:\\hello.doc, I would expect the following code to open a Word document
    > in a normal window.
    >
    >
    > //code++++++++++++++++++++++++++++++++
    > Process myProcess = new Process();
    >
    > try
    > {
    > LinkButton btnClicked = (LinkButton)sender;
    > int myID = 1;
    > myClass.GetByID(myID);
    > myProcess.StartInfo.FileName = myClass.myDirectory + myClass.myFileName;
    > myProcess.StartInfo.UseShellExecute = false;
    > myProcess.StartInfo.WindowStyle =
    > System.Diagnostics.ProcessWindowStyle.Normal;
    > myProcess.StartInfo.CreateNoWindow = false;
    > myProcess.Start();
    > }
    >
    > catch (Exception ex)
    > {
    >
    > //end code++++++++++++++++++++++++++++++++
    >
    > Thank you,
    >
    > John
    >
    >
     
    bruce barker, Jan 9, 2007
    #3
  4. Are you trying to open a Word document on the user's computer?
    If so, you're going about it the wrong way.
    There are several ways to open a Word doc on the client, the simplest would
    be this:
    Response.Redirect("/PublicDir/MyWordDoc.doc")

    Here's more info:
    http://msdn.microsoft.com/library/d...SystemWebHttpResponseClassWriteFileTopic1.asp
    http://SteveOrr.net/articles/ExportPanel.aspx
    http://SteveOrr.net/reviews/AsposeWord.aspx

    --
    I hope this helps,
    Steve C. Orr,
    MCSD, MVP, CSM, ASPInsider
    http://SteveOrr.net


    "xzzy" <> wrote in message
    news:...
    >
    > In the follwoing code, myProcess.StartInfo.FileName is set to a valid
    > path: c:\\hello.doc
    >
    > The code produces the following error message: "%1 is not a valid Win32
    > application"
    >
    > For c:\\hello.doc, I would expect the following code to open a Word
    > document in a normal window.
    >
    >
    > //code++++++++++++++++++++++++++++++++
    > Process myProcess = new Process();
    >
    > try
    > {
    > LinkButton btnClicked = (LinkButton)sender;
    > int myID = 1;
    > myClass.GetByID(myID);
    > myProcess.StartInfo.FileName = myClass.myDirectory +
    > myClass.myFileName;
    > myProcess.StartInfo.UseShellExecute = false;
    > myProcess.StartInfo.WindowStyle =
    > System.Diagnostics.ProcessWindowStyle.Normal;
    > myProcess.StartInfo.CreateNoWindow = false;
    > myProcess.Start();
    > }
    >
    > catch (Exception ex)
    > {
    >
    > //end code++++++++++++++++++++++++++++++++
    >
    > Thank you,
    >
    > John
    >
     
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider], Jan 9, 2007
    #4
  5. xzzy

    Mark Rae Guest

    "xzzy" <> wrote in message
    news:...

    > In the follwoing code, myProcess.StartInfo.FileName is set to a valid
    > path: c:\\hello.doc
    >
    > The code produces the following error message: "%1 is not a valid Win32
    > application"
    >
    > For c:\\hello.doc, I would expect the following code to open a Word
    > document in a normal window.


    But how could it possibly do that...?

    ASP.NET runs on the server, not on the client...

    ASP.NET (principally) receives HttpRequests from web browsers and responds
    by streaming HTML back down to the web browser...

    Your code will do the following:

    1) create a new Process object on the webserver

    2) look for the installed application which corresponds to the supplied
    filename's extension - in this case, .doc

    3) try to instantiate that application and run it in the Process object - on
    the server, not on the client.

    ASP.NET can't open browser windows - it needs to create client-side markup
    (hyperlinks or JavaScript) to do that...
     
    Mark Rae, Jan 9, 2007
    #5
  6. xzzy

    xzzy Guest

    the value of

    myClass.myDirectory + myClass.myFileName

    is

    c:\\hello.doc

    which is a file located on the server upon which asp.net is being served
    from ( in other words, it's not on the client )


    "Juan T. Llibre" <> wrote in message
    news:%...
    > Take a close look at what "myClass.myDirectory + myClass.myFileName;"
    > returns.
    >
    > I bet you're not getting a valid filename or directory path out of it.
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ===================================
    > "xzzy" <> wrote in message
    > news:...
    >>
    >> In the follwoing code, myProcess.StartInfo.FileName is set to a valid
    >> path: c:\\hello.doc
    >>
    >> The code produces the following error message: "%1 is not a valid Win32
    >> application"
    >>
    >> For c:\\hello.doc, I would expect the following code to open a Word
    >> document in a normal window.
    >>
    >>
    >> //code++++++++++++++++++++++++++++++++
    >> Process myProcess = new Process();
    >>
    >> try
    >> {
    >> LinkButton btnClicked = (LinkButton)sender;
    >> int myID = 1;
    >> myClass.GetByID(myID);
    >> myProcess.StartInfo.FileName = myClass.myDirectory +
    >> myClass.myFileName;
    >> myProcess.StartInfo.UseShellExecute = false;
    >> myProcess.StartInfo.WindowStyle =
    >> System.Diagnostics.ProcessWindowStyle.Normal;
    >> myProcess.StartInfo.CreateNoWindow = false;
    >> myProcess.Start();
    >> }
    >>
    >> catch (Exception ex)
    >> {
    >>
    >> //end code++++++++++++++++++++++++++++++++
    >>
    >> Thank you,
    >>
    >> John
    >>

    >
    >
     
    xzzy, Jan 9, 2007
    #6
  7. On Mon, 08 Jan 2007 17:38:02 -0800, bruce barker wrote:

    > asp.net because its a service and does not have access to the desktop,
    > can not start a window app only a command line.
    >


    Actually you can -- only it won't be visible. Give it a shot. Try and start
    notepad then check in task manager

    --
    Bits.Bytes
    http://bytes.thinkersroom.com
     
    Rad [Visual C# MVP], Jan 10, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lucas Tam
    Replies:
    0
    Views:
    521
    Lucas Tam
    Jun 17, 2005
  2. abcd
    Replies:
    1
    Views:
    756
    EShames
    Feb 17, 2006
  3. Tim Golden
    Replies:
    1
    Views:
    745
  4. Replies:
    1
    Views:
    434
    Fredrik Lundh
    Jun 7, 2006
  5. jpock76
    Replies:
    0
    Views:
    626
    jpock76
    Aug 23, 2010
Loading...

Share This Page