简体   繁体   English

向用户显示创建文件的最佳方法是什么?

[英]What is the best way to show a created file to the user?

I have this code for creating a ZIP file: 我有这个用于创建ZIP文件的代码:

void Compress(string contentDirectory, string zippedFileDirectory)
{
    … // locate 7z.dll and invoke SevenZipExtractor.SetLibraryPath
    SevenZipCompressor compressor = new SevenZipCompressor()
                                    {
                                        ArchiveFormat = OutArchiveFormat.Zip,
                                        CompressionMode = CompressionMode.Create,
                                        TempFolderPath = Path.GetTempPath()
                                    };
    string source = contentDirectory;
    string output = zippedFileDirectory;
    string zipFileName = "Diagnosis_Files.zip";
    string t = Path.Combine(output, zipFileName);
    compressor.CompressDirectory(source, t);
}

Right after compressor.CompressDirectory has finished creating the ZIP file, I want to show the ZIP file to the user so they can easily copy it or just see which directory it was created in. compressor.CompressDirectory完成创建ZIP文件之后,我想向用户显示ZIP文件,以便他们可以轻松复制它或只看到它在哪个目录中创建。

How can I do this? 我怎样才能做到这一点?

Process.Start("explorer", String.Format("/select,{0}", zipFileName));

Explorer [/n] [/e] [(,)/root,<object>] [/select,<object>]

/n                Opens a new single-pane window for the default
                  selection. This is usually the root of the drive Windows
                   is installed on. If the window is already open, a
                  duplicate opens.

/e                Opens Windows Explorer in its default view.

/root,<object>    Opens a window view of the specified object.


/select,<object>  Opens a window view with the specified folder, file or
                  application selected.

Examples:

   Example 1:     Explorer /select,C:\TestDir\TestApp.exe

      Opens a window view with TestApp selected.

   Example 2:  Explorer /e,/root,C:\TestDir\TestApp.exe

      This opens Explorer with C: expanded and TestApp selected.

   Example 3:  Explorer /root,\\TestSvr\TestShare

      Opens a window view of the specified share.

   Example 4:  Explorer /root,\\TestSvr\TestShare,select,TestApp.exe

      Opens a window view of the specified share with TestApp selected.

Run the "explorer.exe" process, providing the directory as its command line argument. 运行“explorer.exe”进程,提供该目录作为其命令行参数。 Not sure however how to do this in a portable manner, so it would work also on Mono. 但是不确定如何以便携方式执行此操作,因此它也适用于Mono。

放在方法末尾的以下行将打开包含文件夹:

Process.Start("explorer.exe", output);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM