没有试过,学习!!顶!!!!!

解决方案 »

  1.   

    myProcess.StartInfo.FileNameProcess.StartInfo 属性请参见
    获取或设置要传递给 Process 的 Start 方法的属性。
    这时设置的例子,获取方法同
    [C#] 
    using System;
    using System.Diagnostics;
    using System.ComponentModel;namespace MyProcessSample
    {
        /// <summary>
        /// Shell for the sample.
        /// </summary>
        public 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>
            public 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.   

    楼上的大哥:你的方法是建立在知道路径的基础上的,在已知路径上验证是否存在文件,实际是我根本不知道文件路径,我不可能用遍历的方法把整个硬盘查一遍。并且虽然在菜单“开始”—〉“文档”(不是“我的文档”)中有最近使用的文档列表,但实际上它们都是快捷文件而已。请问你还有更好的方法吗?谢谢!!