Ejemplo n.º 1
0
 /// <summary>
 /// 制作压缩文件
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="file"></param>
 /// <param name="folder"></param>
 private static void AddFile(ZipFileBuilder builder, SPFile file, string folder)
 {
     using (Stream fileStream = file.OpenBinaryStream())
     {
         builder.Add(folder + "\\" + file.Name, fileStream);
         fileStream.Close();
     }
 }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string fullDocLibSourceUrl = Request.Params["sourceUrl"];
            if (string.IsNullOrEmpty(fullDocLibSourceUrl)) return;

            string docLibUrl = fullDocLibSourceUrl.Replace(SPContext.Current.Site.Url, "");

            SPList list = SPContext.Current.Web.GetList(docLibUrl);
            if (!list.IsDocumentLibrary()) return;

            string pItemIds = Request.Params["itemIDs"];
            if (string.IsNullOrEmpty(pItemIds)) return;

            SPDocumentLibrary library = (SPDocumentLibrary)list;

            string[] sItemIds = pItemIds.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            int[] itemsIDs = new int[sItemIds.Length];
            for (int i = 0; i < sItemIds.Length; i++)
            {
                itemsIDs[i] = Convert.ToInt32(sItemIds[i]);
            }

            if (itemsIDs.Length > 0)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    using (ZipFileBuilder builder = new ZipFileBuilder(ms))
                    {
                        foreach (int id in itemsIDs)
                        {
                            SPListItem item = library.GetItemById(id);
                            if (item.IsFolder())
                                AddFolder(builder, item.Folder, string.Empty);
                            else
                                AddFile(builder, item.File, string.Empty);
                        }

                        builder.Finish();
                        WriteStreamToResponse(ms);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 制作压缩文件夹
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="folder"></param>
        /// <param name="parentFolder"></param>
        private static void AddFolder(ZipFileBuilder builder, SPFolder folder, string parentFolder)
        {
            string folderPath = parentFolder == string.Empty ? folder.Name : parentFolder + "\\" + folder.Name;
            builder.AddDirectory(folderPath);

            foreach (SPFile file in folder.Files)
            {
                AddFile(builder, file, folderPath);
            }

            foreach (SPFolder subFolder in folder.SubFolders)
            {
                AddFolder(builder, subFolder, folderPath);
            }
        }