我想设计一个ac#程序,可以运行程序第三个exe应用程序,如WinRAR.程序将浏览文件,然后当用户单击按钮时,创建存档的过程将开始..!
我知道使用System.Diagnostics.Process.Start方法可以执行.exe文件.例如.
Process.Start(@"C:\path\to\file.zip");
GetFile("文件名","打开winrar来执行文件")我需要这样的东西.我想将文件名传递给第3个应用程序,而无需打开winrar.可能吗?我该怎么开始?任何参考/指导/解决方案都非常感谢.
非常感谢你.
//更新
下面是打开WinRAR.exe程序的代码,否则会出现错误消息.我在button_click中点击它并使用browse从txtDest.text接受文件.所以从这里开始,我想直接压缩,而不是打开文件.我尝试更改"RAR.exe"或"UNRAR.exe",但它没有工作.这是正确的?
谢谢.
ProcessStartInfo startInfo = new ProcessStartInfo("WinRAR.exe");
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
startInfo.Arguments = txtDest.Text;
try
{
// Start the process with the info we specified.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
MessageBox.Show("Error Open");
}
}
为此你可能想使用unrar.dll,它是由RarLabs分发的库,即制作Winrar的人.它包含作为COM接口公开的WinRAR的所有功能.我最近在一个项目中使用它,它非常好,公开了打开和浏览档案的方法,以及压缩和解压缩.
http://www.rarlab.com/rar_add.htm向下滚动到"UnRAR.dll UnRAR动态库,适用于Windows软件开发人员".
它附带了一组非常好的示例,包括浏览存档和API文档.
是的,我在这里复活了一个完全死的问题,但我还没有看到有人提出你(直到 20 分钟前我也是)想要的确切答案,所以让我把 2 和 2 放在一起:
命令行用法:rar.exe a <target .rar file> <file to rar> {<more files>}
您可以通过在名称周围加上引号来创建更复杂的名称,例如包含空格的名称。您可能想要的程序是这样的:
string targetArchiveName = "archive.rar",
targetFile = "testFile.txt";
ProcessStartInfo startInfo = new ProcessStartInfo("WinRAR.exe");
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
startInfo.Arguments = string.Format("a \"{0}\" \"{1}\"",
targetArchiveName, targetFile);
try
{
// Start the process with the info we specified.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
{
MessageBox.Show("Error Open");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20216 次 |
| 最近记录: |