Thực thi 1 file với chương trình mặc định
Đôi lúc ta cần mở 1 tập tin với chương trình đã được associate trong máy và gặp trục trặc. đoan code sau giải quyết triệt để vấn đề này.
public class MyExcecutive { public void ExecuteWithAssociatedProgram(String FilePath) { String commands=“cmd /c start ”+ FilePath ; try { Runtime rt = Runtime.getRuntime(); Process child = rt.exec(commands); } catch(Exception ioe){ ioe.printStackTrace(); } } } |
Ví dụ ta muốn mở file C:\help.chm ta gọi như sau
| …
new MyExcecutive().ExecuteWithAssociatedProgram(C:/help.chm); … |
Chúc thành công!
Chính said
Anh Hải ơi cho em hỏi trong C# để gọi một ứng dụng trong win thì làm thế nào hả anh.
Anh hướng dẫn cho em với nhé(nếu được gửi qua Email cho em nhé, email: chinhquoc60@yahoo.com.vn)
vovanhai said
System.Diagnostics.Process x = new System.Diagnostics.Process();System.Diagnostics.ProcessStartInfo si =
new System.Diagnostics.ProcessStartInfo("excel");//file to execute-trong trường hợp này chạy excel thử
x.StartInfo = si;
x.Start();