从嵌入式资源获取zip文件中包含的文件列表? (不从资源中提取zip文件)

时间:2019-02-23 13:01:23

标签: c# zip

  

您好,我实际上是在寻找如何获取文件列表   包含在保存在嵌入式资源中的zip文件中,没有提取   该zip文件来自资源

    static List<String> ZipFileContent()
    {
        List<String> ZipFileContentList = new List<String>();

        using (ZipArchive ClientZipArchive = ZipFile.OpenRead("Application1.Resources.File1.zip")) //Trying to declare the embedded resource path here
        {
            foreach (ZipArchiveEntry ClientZipArchiveEntry in ClientZipArchive.Entries)
            {
                ZipFileContentList.Add(ClientZipArchiveEntry.FullName);
            }

            return ZipFileContentList;
        }
    }
  

其他想法:使用Stream从以下位置获取zip文件缓冲区   资源,最后获得此zip文件的内容列表:

    static byte[] GetBuffer(string ResourcePath)
    {
        Assembly TargetAssembly = Assembly.GetExecutingAssembly();

        using (Stream ClientStream = TargetAssembly.GetManifestResourceStream(TargetAssembly.GetName().Name + "." + ResourcePath))
        {
            if (ClientStream != null)
            {
                byte[] Buffer = new byte[ClientStream.Length];

                return Buffer;
            }
            else
            {
                return null;
            }
        }
    }

    static void InterpretBuffer()
    {
        byte[] ZipFileBuffer = GetBuffer("Resources.File1.zip");

        //Do something with ZipFileBuffer to know the list of file contained in the zip file
    }

感谢前进

0 个答案:

没有答案