标签: sharpziplib

使用SharpZipLib解压缩特定文件?

我正在尝试使用SharpZipLib从zip存档中提取指定的文件.我见过的所有例子总是希望你能解压缩整个拉链,并按照以下方式做一些事情:

       FileStream fileStreamIn = new FileStream (sourcePath, FileMode.Open, FileAccess.Read);

        ZipInputStream zipInStream = new ZipInputStream(fileStreamIn);
        ZipEntry entry;

        while (entry = zipInStream.GetNextEntry() != null)
        {
            // Unzip file
        }
Run Code Online (Sandbox Code Playgroud)

我想做的是:

ZipEntry entry = zipInStream.SeekToFile("FileName");
Run Code Online (Sandbox Code Playgroud)

因为我的需求涉及使用zip作为包,只根据需要将文件抓取到内存中.

有人熟悉SharpZipLib吗?有没有人知道我是否可以手动完成整个拉链?

.net compression sharpziplib

34
推荐指数
3
解决办法
4万
查看次数

如何使用C#正确准备"HTTP重定向绑定"SAML请求

我需要使用HTTP重定向绑定方法创建SP启动的SAML 2.0身份验证事务.事实证明这很容易.只需获取IdP URI并连接单个查询字符串参数即可 SAMLRequest.param是xml的编码块,用于描述SAML请求.到现在为止还挺好.

将SAML转换为查询字符串参数时出现问题.我相信这个准备过程应该是:

  1. 构建SAML字符串
  2. 压缩此字符串
  3. Base64编码字符串
  4. UrlEncode字符串.

SAML请求

<samlp:AuthnRequest
    xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
    xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
    ID="{0}"
    Version="2.0"
    AssertionConsumerServiceIndex="0"
    AttributeConsumingServiceIndex="0">
    <saml:Issuer>URN:xx-xx-xx</saml:Issuer>
    <samlp:NameIDPolicy
        AllowCreate="true"
        Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"/>
</samlp:AuthnRequest>
Run Code Online (Sandbox Code Playgroud)

代码

private string GetSAMLHttpRedirectUri(string idpUri)
{
    var saml = string.Format(SAMLRequest, Guid.NewGuid());
    var bytes = Encoding.UTF8.GetBytes(saml);
    using (var output = new MemoryStream())
    {
        using (var zip = new DeflaterOutputStream(output))
        {
            zip.Write(bytes, 0, bytes.Length);
        }
        var base64 = Convert.ToBase64String(output.ToArray());
        var urlEncode = HttpUtility.UrlEncode(base64);
        return string.Concat(idpUri, "?SAMLRequest=", urlEncode);
    }
}
Run Code Online (Sandbox Code Playgroud)

我怀疑压缩是某种程度上的责任.我正在使用SharpZipLibDeflaterOutputStream类,它应该实现一个行业标准的deflate算法,所以也许这里有一些设置我错了?

可以使用此SAML2.0调试器(其有用的在线转换工具)测试编码输出.当我使用这个工具解码我的输出时,它是无意义的.

因此,问题是:您是否知道如何将SAML字符串转换为正确放气和编码的SAMLRequest查询参数?

谢谢 …

c# sharpziplib saml-2.0

19
推荐指数
2
解决办法
2万
查看次数

无法加载文件或程序集ICSharpCode.SharpZipLib ...使用nuGet包时ExcelDataReader

错误:

无法加载文件或程序集'ICSharpCode.SharpZipLib,Version = 0.85.5.452,Culture = neutral,PublicKeyToken = 1b03e6acf1164f73'或其依赖项之一.系统找不到指定的文件

堆:

[FileNotFoundException:无法加载文件或程序集'ICSharpCode.SharpZipLib,Version = 0.85.5.452,Culture = neutral,PublicKeyToken = 1b03e6acf1164f73'或其依赖项之一.系统找不到指定的文件.]
Excel.Core.ZipWorker.Extract(Stream fileStream)+0
Excel.ExcelOpenXmlReader.Initialize(Stream fileStream)+78

[Asp.Net Mvc3 C#]

使用NuGet包ExcelDataReader我试图打开一个保存在文件系统上的.xlsx文件.这是使用的代码:

string filePath = HttpContext.Server.MapPath("~/blank3.xlsx");
FileStream stream = System.IO.File.Open(filePath, FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
Run Code Online (Sandbox Code Playgroud)

这是nuget包的网站:http://exceldatareader.codeplex.com/

是什么赋予了?这应该没有任何障碍.

c# sharpziplib nuget asp.net-mvc-3 exceldatareader

15
推荐指数
2
解决办法
3万
查看次数

DLL版本控制错误

我有一个偶尔会抛出以下错误的网站:

'/'应用程序中的服务器错误.

无法加载文件或程序集'ICSharpCode.SharpZipLib,Version = 0.85.3.365,Culture = neutral,PublicKeyToken = 1b03e6acf1164f73'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)

现在我知道我确实依赖于这个DLL,但我的系统上有0.85.5版本.我已经从服务器系统地删除了每个旧版本的DLL,重新编译了所有内容并重新发布.但无论我做什么,似乎每次重新发布后,有人访问该网站的前一两次,他们都会收到此错误.然后刷新一次或两次后,错误消失,网站正常运行.

让我更奇怪的是,如果我查看引发错误的代码行:

URLRewriter.ProcessRewritingResult(status, excludedEnum, siteName, viewMode, relativePath);
Run Code Online (Sandbox Code Playgroud)

URLRewriter是来自第三方软件包的类(Kentico CMS - CMS.URLRewritingEngine.dll).我在该DLL上运行了Dependency Walker,并且在ICSharpCode.SharpZipLib上找不到任何依赖项.

任何想法如何解决这一问题?

编辑:在@ JeremyThompson的建议下,我运行了Process Monitor来捕获错误.这是一个屏幕转储,突出显示相关部分(出于隐私原因,一个文件夹名称被隐藏).您可以通过右键单击它来查看它的完整大小等...

在此输入图像描述

编辑:这是错误的负载跟踪.这有帮助吗?

===预绑定状态信息===

日志:用户= MY-SERVER-12 \管理员

日志:DisplayName = ICSharpCode.SharpZipLib,版本= 0.85.3.365,文化=中立,PublicKeyToken = 1b03e6acf1164f73(完全指定)

日志:Appbase = file:/// C:/ inetpub/wwwroot/MySite /

日志:初始PrivatePath = C:\ inetpub\wwwroot\MySite\bin

调用程序集:CMS.WebAnalytics,Version = 6.0.4377.2467,Culture = neutral,PublicKeyToken = 834b12a258f213f9.

===

日志:此绑定在默认加载上下文中启动.

日志:使用应用程序配置文件:C:\ inetpub\wwwroot\MySite\web.config

日志:使用主机配置文件:C:\ Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config

日志:使用C:\ Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config中的计算机配置文件.

日志:政策后参考:ICSharpCode.SharpZipLib,Version = 0.85.3.365,Culture = neutral,PublicKeyToken = 1b03e6acf1164f73

日志:尝试下载新的URL文件:/// C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/9760eb69/275bb3db/ICSharpCode.SharpZipLib.DLL.

日志:尝试下载新的URL文件:/// C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary …

c# asp.net iis dll sharpziplib

15
推荐指数
2
解决办法
1万
查看次数

C#.net识别zip文件

我目前正在使用SharpZip api处理我的zip文件条目.它适用于压缩和解压缩.但是,我无法确定文件是否为zip文件.我需要知道是否有办法检测文件流是否可以解压缩.原来我用过

FileStream lFileStreamIn = File.OpenRead(mSourceFile);
lZipFile = new ZipFile(lFileStreamIn);
ZipInputStream lZipStreamTester = new ZipInputStream(lFileStreamIn, mBufferSize);// not working
lZipStreamTester.Read(lBuffer, 0, 0);
if (lZipStreamTester.CanDecompressEntry)
{
Run Code Online (Sandbox Code Playgroud)

LZipStreamTester每次都变为null,if语句失败.我尝试使用/不使用缓冲区.任何人都可以提供任何有关原因的见解吗?我知道我可以检查文件扩展名.我需要的东西比那更明确.我也知道zip有一个神奇的#(PK的东西),但它不能保证它永远存在,因为它不是格式的要求.

另外我读到.net 4.5有本机zip支持,所以我的项目可能会迁移到而不是sharpzip,但我仍然需要没有看到类似于CanDecompressEntry的方法/参数:http://msdn.microsoft.com/en-我们/库/ 3z72378a%28V = vs.110 29%

我的最后一招是使用try catch并尝试解压缩文件.

c# zip sharpziplib .net-4.5

15
推荐指数
3
解决办法
2万
查看次数

SharpLibZip:添加没有路径的文件

我正在使用以下代码,使用SharpZipLib库将文件添加到.zip文件中,但每个文件都以其完整路径存储.我只需要将文件存储在.zip文件的"root"中.

string[] files = Directory.GetFiles(folderPath);
using (ZipFile zipFile = ZipFile.Create(zipFilePath))
{
     zipFile.BeginUpdate();
     foreach (string file in files)
     {
          zipFile.Add(file);
     }
     zipFile.CommitUpdate();
}
Run Code Online (Sandbox Code Playgroud)

在提供的文档中,我找不到任何关于此选项的信息.由于这是一个非常受欢迎的图书馆,我希望有人读这篇文章可能会有所了解.

compression sharpziplib

14
推荐指数
2
解决办法
8132
查看次数

使用SharpZipLib将文件添加到没有路径的ZIP

我需要将3个文件合并为1个zip文件,并为用户下载.除了一件事,我能够实现我的要求:它将文件压缩到子文件夹中.

例如,我的文件位置如下:

C:\TTCG\WebSites\Health\ABC.CSV
C:\TTCG\WebSites\Health\XYZ.CSV
C:\TTCG\WebSites\Health\123.CSV
Run Code Online (Sandbox Code Playgroud)

但是在zip文件中,它使用"TTCG\WebSites\Health \"作为路径压缩文件夹中的文件.请参阅附件.

例

我不想要路径中的文件夹.我只想在没有文件夹的zip文件中有3个文件.我怎样才能做到这一点?

我生成zip文件的代码如下:

ZipFile z = ZipFile.Create(Server.MapPath("~" + @"\Accident.zip"));

//initialize the file so that it can accept updates
z.BeginUpdate();

//add the file to the zip file        
z.Add(Server.MapPath("~" + @"\ABC.csv"));
z.Add(Server.MapPath("~" + @"\XYZ.csv"));
z.Add(Server.MapPath("~" + @"\123.csv"));        

//commit the update once we are done
z.CommitUpdate();
//close the file
z.Close();
Run Code Online (Sandbox Code Playgroud)

c# zip sharpziplib

14
推荐指数
1
解决办法
3万
查看次数

如何实现SharpZipLib.Portable所需的VirtualFileSystem?

我想将SharpZipLib.Portable库添加到我的Xamarin.FormsPCL项目中.我的目标是Android和iOS.该文档提到您必须实现一个VirtualFileSystem才能使用该库,但我不知道该怎么做,我无法找到有关该主题的更多信息.

有没有人使用这个库可以指导我使用它所需的步骤?

c# sharpziplib portable-class-library xamarin.forms

11
推荐指数
1
解决办法
2928
查看次数

如何实时压缩并实时流式传输到Response.Output?

我试图使用以下代码:我得到一个损坏的zip文件.为什么?文件名似乎没问题.也许他们不是相对的名字,这就是问题所在?

      private void trySharpZipLib(ArrayList filesToInclude)
    {
        // Response header
        Response.Clear();
        Response.ClearHeaders();
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.StatusCode = 200; // http://community.icsharpcode.net/forums/p/6946/20138.aspx
        long zipSize = calculateZipSize(filesToInclude);
        string contentValue = 
            string.Format("attachment; filename=moshe.zip;"
                          ); // + " size={0}", zipSize);
        Response.ContentType = "application/octet-stream"; //"application/zip"; 
        Response.AddHeader("Content-Disposition", contentValue);
        Response.Flush();

        using (ZipOutputStream zipOutputStream = new ZipOutputStream(Response.OutputStream) ) 
        {
            zipOutputStream.SetLevel(0);

            foreach (string f in filesToInclude)
            {
                string filename = Path.Combine(Server.MapPath("."), f);
                using (FileStream fs = File.OpenRead(filename))
                {
                    ZipEntry entry =
                        new ZipEntry(ZipEntry.CleanName(filename))
                            {
                                DateTime = File.GetCreationTime(filename),
                                CompressionMethod = CompressionMethod.Stored,
                                Size = fs.Length …
Run Code Online (Sandbox Code Playgroud)

asp.net zip outputstream real-time sharpziplib

10
推荐指数
2
解决办法
2万
查看次数

ICSharpCode.SharpZipLib.Zip.FastZip不压缩文件名中包含特殊字符的文件

ICSharpCode.SharpZipLib.Zip.FastZip用来压缩文件,但我遇到了问题:

当我尝试压缩文件名中包含特殊字符的文件时,它不起作用.当文件名中没有特殊字符时,它可以工作.

.net c# sharpziplib

9
推荐指数
3
解决办法
4343
查看次数