[英]How to way extract format .gz/.zip/.rar/.tar.gz in .net core mvc c#
I have issue when action open file follow format.gz/.tar.gz This is image error当操作打开文件遵循 format.gz/.tar.gz 时出现问题 这是图像错误
This is code:这是代码:
public void Check(string path)
{
foreach (var fileName in Directory.GetFiles(path))
{
if (Path.GetExtension(fileName) == ".gz" && Path.GetFileNameWithoutExtension(fileName).Contains("tar"))
{
Console.WriteLine(fileName);
ExtractTGZ(fileName, Path.GetDirectoryName(fileName) + @"\" + Path.GetFileNameWithoutExtension(fileName));
System.IO.File.Delete(fileName);
}
}
}
The System.IO.Compression namespace contains the following types for compressing and decompressing files and streams. System.IO.Compression 命名空间包含以下用于压缩和解压缩文件和流的类型。 You can also use these types to read and modify the contents of a compressed file.
您还可以使用这些类型来读取和修改压缩文件的内容。
string fileName = Guid.NewGuid() + ifile.FileName;
string path = Path.Combine(FilesTempPath, fileName);
using (var fileStream = new FileStream(path, FileMode.Create))
{
ifile.CopyTo(fileStream);
}
var FileZipPath = FilesTempPath + "\\" + fileName;
ZipFile.ExtractToDirectory(FileZipPath, FilesTempPath);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.