C# 使用.NET c压缩后,使用Windows资源管理器打开.zip

C# 使用.NET c压缩后,使用Windows资源管理器打开.zip,c#,.net,ftp,zip,windows-explorer,C#,.net,Ftp,Zip,Windows Explorer,嘿,我有一个小问题,我正在用C压缩内存中的文件,并将它们上传到Ftp服务器。这工作做得很好 destinyPath=product/test/zip.zip; sourcePath=@C:\devtest private String UploadToFtp(String destinyPath, String sourcePath, ref FtpClient client) { String error = "success"; try

嘿,我有一个小问题,我正在用C压缩内存中的文件,并将它们上传到Ftp服务器。这工作做得很好

destinyPath=product/test/zip.zip; sourcePath=@C:\devtest

    private String UploadToFtp(String destinyPath, String sourcePath, ref FtpClient client)
    {
        String error = "success";
        try
        {
            // Stream im Arbeitsspeicher erstellen
            using (Stream memoryStream = new MemoryStream())

            // Ziparchive anhand des verweißes auf den memoryStream erstellen
            using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
            {
                // Dateien im gezippten Ordner bestimmen
                foreach (string path in Directory.EnumerateFiles(sourcePath))
                {
                    ZipArchiveEntry entry;
                    if (path.Length > 248)
                    {
                        // Bestimmte Dateien ins Ziparchive erstellen mit langen Pfad
                        entry = archive.CreateEntry(ZlpPathHelper.GetFileNameFromFilePath(path));
                    }
                    else
                    {
                        // Bestimmte Dateien ins Ziparchive erstellen mit kurzem Pfad
                        entry = archive.CreateEntry(Delimon.Win32.IO.Path.GetFileName(path));
                    }

                    // Original Daten (entryStream) in Ziparchivedateien (fileStream) schreiben
                    using (Stream entryStream = entry.Open())

                    using (Stream fileStream = Delimon.Win32.IO.File.OpenRead(path))
                    {
                        fileStream.CopyTo(entryStream);
                    }
                }
                //memoryStream curser auf anfang setzen
            memoryStream.Seek(0, SeekOrigin.Begin);

                //Stream auf den FtpServer laden
            client.RetryAttempts = 3;
                client.Upload(memoryStream, destinyPath);
            }
        }
        catch (Exception ex)
        {
            error = ex.ToString();
        }
        return error;
    }
但现在我的问题来了。如果我在下载后尝试用双击打开它们,我总是从Windows获得相同的选择:无法打开目录。Zip目录“C:*”无效。但是,如果我右键单击7-zip->open->*,7-zip->open->或7-zip->open->:e它就可以工作了

属性:使用Windows资源管理器打开


是的,我一次又一次地尝试下载.zip。我在谷歌上搜索,发现了类似“找不到文件结尾,但没有解决方法”的内容。

我找到了我的密码。它与ZlpPathHelper或Delimon程序集无关

这就是密码巫师的工作。我把using}{放错地方了。Ftp上传不应该在存档流的using块中

这会导致.zip存档文件在完全创建存档文件之前上载。=>所有文件都在存档文件中,但如果我尝试打开它,则会出现错误

    private String UploadToFtp(String destinyPath, String sourcePath, ref FtpClient client)
    {
        String error = "success";
        try
        {
            // Stream im Arbeitsspeicher erstellen
            using (Stream memoryStream = new MemoryStream())
            {
                // Ziparchive anhand des verweißes auf den memoryStream erstellen
                using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                {
                    // Dateien im gezippten Ordner bestimmen
                    foreach (string path in Directory.EnumerateFiles(sourcePath))
                    {
                        ZipArchiveEntry entry;
                        if (path.Length > 248)
                        {
                            // Bestimmte Dateien ins Ziparchive erstellen mit langen Pfad
                            entry = archive.CreateEntry(ZlpPathHelper.GetFileNameFromFilePath(path));
                        }
                        else
                        {
                            // Bestimmte Dateien ins Ziparchive erstellen mit kurzem Pfad
                            entry = archive.CreateEntry(Path.GetFileName(path));
                        }

                        // Original Daten (entryStream) in Ziparchivedateien (fileStream) schreiben
                        using (Stream entryStream = entry.Open())
                        {
                            using (Stream fileStream = Delimon.Win32.IO.File.OpenRead(path))
                            {
                                fileStream.CopyTo(entryStream);
                            }
                        }
                    }
                }
                //memoryStream curser auf anfang setzen
                memoryStream.Seek(0, SeekOrigin.Begin);

                //Stream auf den FtpServer laden
                client.RetryAttempts = 3;
                client.Upload(memoryStream, destinyPath);
            }
        }
        catch (Exception ex)
        {
            error = ex.ToString();
        }
        return error;
    }

你能在问题中包含此方法的示例输入参数吗?那么你的问题与FTP有关吗?如果你将ZIP文件流式传输到本地文件而不是FTP,你能打开它吗?如果你只使用本机.NET类,你会遇到同样的问题吗?即没有ZLPATHhelper或Delimon.Win32.IO.file。我们需要。