这段代码只能获取在项目文件中的默认的bin文件夹下的debug文件夹里的文件我想问的是如何获取 比如C盘或D盘里的QQ文件夹下的QQ.EXE启动文件或别的文件夹下的文件呢...这段代码只能在项目中默认文件夹下使用,当用别的文件夹下的文件时会提示没有此文件或此文件不存在System.Diagnostics.Process.Start("用户手册.txt");请高手们看看呢该如何修改....

解决方案 »

  1.   


    System.Diagnostics.Process.Start("C:\\用户手册.txt");
      

  2.   

    再问下如何获取路径呢...假如我这有个软件是在别人的电脑上用的,其中软件界面上有个button按钮就是用来打开某个文件的,假设某个文件就是QQ.EXE,如果我就是在我自己写的软件里的button按钮里写了个单击事件其中代码就是
    System.Diagnostics.Process.Start("QQ.EXE");,前面的路径我没有写,请问该如何加入路径,又该如何获取路径呢...
      

  3.   

    2种方法:
    1.用openfiledialog来让用户自己找启动路径
    2.遍历所有盘中的文件找到名称为“QQ.exe”的再获取路径启动,这个会费时间就比较多些了
      

  4.   

    xhueducls
    的答案是正确 合理 的
      

  5.   

    qq安装后会在注册表中添加安装路径的
    获取路径后直接System.Diagnostics.Process.Start(@"获取的路径"+"\QQ.exe");
      

  6.   


    那如果是绿色版呢?所以还得是使用OpenFileDialog
      

  7.   

            private void button1_Click(object sender, EventArgs e)
            {
                string fullname = "C:\\QQ.EXE";
                if(File.Exists(fullname))
                {
                
                }
                else//如果不存在则查找  
                {
                    FolderBrowserDialog fbd=new FolderBrowserDialog();
                    fbd.ShowDialog();                string RootPath = fbd.SelectedPath;
                    
                    if(Directory.Exists(RootPath))
                    {
                        DirectoryInfo d = new DirectoryInfo(RootPath);                    FileInfo[] FileList = d.GetFiles("QQ.exe", SearchOption.AllDirectories);                    if (FileList.Length > 0)
                        {
                            fullname = FileList[0].FullName;
                        }
                        else 
                        {
                            MessageBox.Show("不存在此文件");
                        }
                    }
                }
                MessageBox.Show("QQ.exe的FullName为" + fullname);
            }
      

  8.   

    1.用openfiledialog来让用户自己找启动路径
    2.遍历所有盘中的文件找到名称为“QQ.exe”的再获取路径启动,这个会费时间就比较多些了
      

  9.   


            private void button5_Click(object sender, EventArgs e)
            {
                string fullname = "C:\\QQ.exe";
                if(File.Exists(fullname))
                {
                
                }
                else//如果不存在则查找  
                  {
                    FolderBrowserDialog fbd=new FolderBrowserDialog();
                    fbd.ShowDialog();                string RootPath = fbd.SelectedPath;
                    
                    if(Directory.Exists(RootPath))
                    {
                        DirectoryInfo d = new DirectoryInfo(RootPath);
                        try
                        {
                            FileInfo[] FileList = d.GetFiles("QQ.exe", SearchOption.AllDirectories);
                            if (FileList.Length > 0)
                            {
                                fullname = FileList[0].FullName;
                                MessageBox.Show("QQ.exe的FullName为" + fullname);
                            }
                            else
                            {
                                MessageBox.Show("不存在此文件");
                            }
                        }
                        catch (UnauthorizedAccessException ex)
                        {
                            MessageBox.Show("请确保您具有足够的特权来访问此资源");
                        }
                        finally
                        {
                            this.Close();
                        }
                        
                    }
                }
                
            }