SharePoint 压缩打包文件代码分享
前言
最近碰到这样一个需求,用户需要批量打包下载sharepoint文档库中的文档,所以,就需要开发一个打包下载的服务。
然后,把打包的代码分享给大家,也许会有需要的人。
static void Main(string[] args)
{
string filesPath = "/DC/T1.txt;/DC/T2.txt";
CreateZipFile(filesPath, @"C:\Temp\", "http://localhost");
} /// <summary>
/// 创建压缩包
/// </summary>
/// <param name="filesPath"></param>
/// <param name="zipFilePath"></param>
private static void CreateZipFile(string filesPath, string zipFilePath, string siteUrl)
{
string[] filenames = filesPath.Split(';');
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.OpenWeb())
{
string tempName = Guid.NewGuid().ToString().Replace("-", "") + ".zip";
zipFilePath = zipFilePath + tempName;
Stream sr = File.Create(zipFilePath);
using (ZipOutputStream s = new ZipOutputStream(sr))
{
s.SetLevel();// 压缩级别 0-9
byte[] buffer = null;
foreach (string file in filenames)
{
ZipEntry entry = new ZipEntry(GetFileName(file));
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
string filename = web.Url + file;
SPFile ff = web.GetFile(filename);
buffer = ff.OpenBinary();
int sourceBytes = buffer.Length;
s.Write(buffer, , sourceBytes);
}
s.Finish();
s.Close();
sr.Close();
FileStream fs = File.Open(zipFilePath, FileMode.OpenOrCreate);
web.Lists["Temp"].RootFolder.Files.Add(web.ServerRelativeUrl + web.Lists["Temp"].RootFolder.Url + "/" + tempName, fs, true);
fs.Close();
File.Delete(zipFilePath);
}
}
}
return;
} public static string GetFileName(string filePath)
{
string fileName = filePath.Substring(filePath.LastIndexOf('/') + , filePath.Length - filePath.LastIndexOf('/') - );
return fileName;
}
SharePoint 压缩打包文件代码分享的更多相关文章
- java.util.zip压缩打包文件总结一:压缩文件及文件下面的文件夹
一.简述 zip用于压缩和解压文件.使用到的类有:ZipEntry ZipOutputStream 二.具体实现代码 package com.joyplus.test; import java.io ...
- [转]C#压缩打包文件
/// <summary> /// 压缩和解压文件 /// </summary> public class ZipClass { /// <summary> /// ...
- asp.net C#压缩打包文件例子
/// <summary> /// 压缩和解压文件 /// </summary> public class ZipClass { /// <summary> /// ...
- C#压缩打包文件
该控件是使用csharp写的,因此可以直接在dotnet环境中引用,不需要注册. 利用 SharpZipLib方便地压缩和解压缩文件最新版本的SharpZipLib(0.84)增加了很多新的功能,其中 ...
- java.util.zip压缩打包文件总结二: ZIP解压技术
一.简述 解压技术和压缩技术正好相反,解压技术要用到的类:由ZipInputStream通过read方法对数据解压,同时需要通过CheckedInputStream设置冗余校验码,如: Checked ...
- Linux系统下压缩文件时过滤指定的文件 |Linux系统压缩指定文件代码
进入要压缩的目录: [root@iZ25c748tjqZ wechat]# cd /alidata1/htdocs/wechat/ 查看目录: [root@iZ25c748tjqZ wechat]# ...
- C#强力粉碎文件代码分享,升级中用到
360的文件粉碎机还是很强大的,在我们客户端winform升级的时候,必须将有些文件进行强力删除后下载更新,如果删除失败很有可能整个 程序就无法更新到最新的版本,所以这里参考了网上的资料整理了一个文件 ...
- linux文件压缩与文件夹压缩(打包)
目录 一:linux文件压缩 1.linux常见的压缩包有哪些? 2.bzip压缩(文件) 二:打包(文件夹压缩) 1.打包命令 2.参数 3.参数解析(实战) 4.注意事项 简介: win中的压缩包 ...
- C# 压缩打包文件下载
C# 压缩打包文件下载 public class MyNameTransfom : ICSharpCode.SharpZipLib.Core.INameTransform { #region INam ...
随机推荐
- WebApi帮助类
public class HttpClientBase { /// <summary> /// HttpClient实现Post请求 /// </summary> protec ...
- Error:Makefile:452: target 'config' given more than once in the same rule
在解压的 linux2.6.15 文件夹下 make menuconfig 的时候出现下面的错误: Makefile:452: target 'config' given more than once ...
- 下载vc++运行库
之前下载vc++运行库都是百度,从中关村.当下等软件网站下载,但是最近这些网站涉及到安全问题,所以从官网下载比较合适 微软官网-中文 在搜索中 搜索vc++2010/2015等,搜索结果中找到xxxx ...
- Codeforces 508E Arthur and Brackets 区间dp
Arthur and Brackets 区间dp, dp[ i ][ j ]表示第 i 个括号到第 j 个括号之间的所有括号能不能形成一个合法方案. 然后dp就完事了. #include<bit ...
- ubuntu下spark安装配置
一.安装vmware虚拟机 二.在虚拟机上安装ubuntu12.04操作系统 三.安装jdk1.8.0_25 http://www.oracle.com/technetwork/java/javase ...
- 纯css滚动视差
1.何为滚动视差 视差滚动(Parallax Scrolling)是指让多层背景以不同的速度移动,形成立体的运动效果,带来非常出色的视觉体验. 作为网页设计的热点趋势,越来越多的网站应用了这项技术.效 ...
- 以管理员身份运行CMD
To complete these procedures, you must be a member of the Administrators group. To start a command p ...
- Linux shell 脚本小记2
.从文件读取 while read line do echo "line=$line" done < file.txt .将字符串转换为数组,并进行遍历 str=" ...
- 使用Automation将Azure SQL DB容灾到本地
前段时间有个客户有如下需求,将Azure SQL Database数据库容灾到本地(备份频率1小时/次). 那么对于这样的需求,我们可以使用Azure Automation来实现自动化备份到本地. 大 ...
- 使用 IntraWeb (17) - 基本控件之 TIWRadioButton、TIWRadioGroup、TIWCheckBox
TIWRadioButton //单选 TIWRadioGroup //单选组 TIWCheckBox //复选 TIWRadioButton 所在单元及继承链: IWCompRadioButton. ...