先创建压缩包,然后往压缩包里面写数据
用Path.Combine方法拼接path,然后创建压缩包
c# Path.Combine - 大海的泡沫 - 博客园 Path.Combine详解
path = Path.Combine("c:/user", "0001", "123456");
我们会得到一个c:/0001/123456 的文件夹路径
然后创建文件夹,因为是多级的,所以用Directory.CreateDirectory。
try
{
DirectoryInfo temp = Directory.GetParent(path);
if (!temp.Exists)
{
Directory.CreateDirectory(dir.FullName);
}
}
catch (Exception)
{
path = Directory.GetCurrentDirectory();
}
创建文件:
要创建的文件名:name="XXX.zip";
FileInfo file = new FileInfo(Path.Combine(path,name));
判断一下原来有没有这个文件,如果有这个文件,就删除它
if (file.Exists)
{
file.Delete();
}
现在可以链接DB了,把结果集(多条)查出来,然后来一个循环,把数据处理一下
先用zipArchive类把我们做的路径指定为当前的工作路径
ZipFile.Open 方法 (System.IO.Compression) | Microsoft Docs 详解
using (ZipArchive archive = ZipFile.Open(Path.Combine(path, name), ZipArchiveMode.Update)){
// 网上查来的
// archive.CreateEntryFromFile(newFile, "NewEntry.txt");
// archive.ExtractToDirectory(extractPath);
// 我们想做的
foreach (dataTables oneRecord in 查询的结果集){
// 写真数据取得,使用byte接收
byte[] b = oneRecord.写真数据;
var s = archive.CreateEntry("任意我们想设定的写真名");
using (var e = s.Open()){
es.Write(b,0,b.length);
}
}
}
这样就完成了
一般这种时候都希望把图片返回到控制台上去,下面是把图片返回到控制台上去
下面是将查询到的结果以json形式返回去,下一篇