Process.Start không thể tìm thấy tệp hiện có
- Tôi có đường dẫn của tệp thi hành (
C:\Test\n4.TestConsole.exe
). File.Exists(path)
trả vềtrue
.File.OpenRead(path)
mang lại cho tôi luồng của nó mà không có vấn đề gì.Process.Start(path)
ném mộtSystem.ComponentModel.Win32Exception
với tin nhắn này:Hệ thống không thể tìm thấy các tập tin cụ thể.
Windows 8 Professional x64 - .NET Framework 4,5
Edit: Đây là mã.
public partial class Form1 : Form
{
public string Path { get; set; }
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// I put a breakpoint here and verify the Path's value is
// C:\Test\n4.TestConsole.exe.
// File.Exists returns true.
MessageBox.Show(File.Exists(Path));
// File.OpenRead doesn't throw an exception.
using (var stream = File.OpenRead(Path)) { }
// This throws the exception.
Process.Start(Path);
}
}
loại của tập tin bạn đang cố gắng để thực hiện là gì? Có 'thực thi' không? Bạn có thể hiển thị giá trị của đường dẫn không? –
@WouterdeKort: Ứng dụng bảng điều khiển. Nó mở ra và chờ đợi một đầu vào khi tôi nhấp đúp vào nó. Đường dẫn là: 'C: \ Test \ n4.TestConsole.exe' –
Giá trị của đường dẫn là gì? Bạn cần sử dụng đường dẫn tệp đầy đủ nếu tệp không nằm trong System32 –