将c:\1.xml换成.jpg  .exe. .doc .xsl都行,就是xml格式会导致提前退出啊!

解决方案 »

  1.   

    从联机帮助考过来的
    using System;
    using System.Diagnostics;
    using System.ComponentModel;namespace MyProcessSample
    {
    /// <summary>
    /// Shell for the sample.
    /// </summary>
    class MyProcess
    {
    // These are the Win32 error code for file not found or access denied.
    const int ERROR_FILE_NOT_FOUND =2;
    const int ERROR_ACCESS_DENIED = 5; /// <summary>
    /// Prints a file with a .doc extension.
    /// </summary>
    void PrintDoc()
    {
    Process myProcess = new Process();

    try
    {
    // Get the path that stores user documents.
    string myDocumentsPath = 
    Environment.GetFolderPath(Environment.SpecialFolder.Personal); myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc"; 
    myProcess.StartInfo.Verb = "Print";
    myProcess.StartInfo.CreateNoWindow = true;
    myProcess.Start();
    }
    catch (Win32Exception e)
    {
    if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
    {
    Console.WriteLine(e.Message + ". Check the path.");
    }  else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
    {
    // Note that if your word processor might generate exceptions
    // such as this, which are handled first.
    Console.WriteLine(e.Message + 
    ". You do not have permission to print this file.");
    }
    }
    }
    public static void Main()
    {
    MyProcess myProcess = new MyProcess();
    myProcess.PrintDoc();
    }
    }
      

  2.   

    就是这样做的,只是使用xml格式就会提前触发exit()事件
      

  3.   

    因为xml是在其他的进程中打开的,如ie里面等,你要为它开一个新的进程的话,你可以选择打开方式->记事本 始终选择此种打开方式即可。
      

  4.   

    用记事本打开不符合程序要求啊。我打开xml是通过microsoft infopath,是有界面进行编辑的啊。
      

  5.   

    我写在上面是个简版,我完成按照msdn的示例原码写了一遍,如果是xml就不行,但如果是其他的大部分文件都行。
      

  6.   

    是不是xml和html之类的需要浏览器的文件都不可以啊?
      

  7.   

    我成功了,博客园的朋友解答的
     static public void PrintDoc(string fileName)
            {
                myProcess.StartInfo.FileName = @"infopath";
                myProcess.StartInfo.Arguments = @"c:\1.xml";
                myProcess.EnableRaisingEvents = true;
                myProcess.Exited += new EventHandler(myProcess_Exited);
                myProcess.Start();
            } 
    成功!
    其实一开始程序就是通过infopath打开的。但是由于xml由默认IE先打开。导致过程是这样的:
    1.调用IE异步启动(但不打开文件,由于我默认是由infopath打开),导致process退出。
    2.然后再用infopath打开文件,这时process以为它已经退出了。
    现在通过程序改完后,就跳过IE那一关了!