SharePoint备份文件

 

stp文件:SharePoint的.stp文件

 

在做一个和SharePoint有关的项目时,由于对SharePoint的unfamiliar,所以客户发了几个后缀为.stp的文件将我纳闷了半天,不知为何物。 

按常理,只知道.stp文件是3D 的一个标准交换文件,需要用AutoCAD、PRO/E或SW等三维处理软件来打开,但看客户给我的文件大小非常小,应该不可能是3D文件啊。后来Avrin告诉我stp文件是Sharepoint里的Template file时我才恍然大悟,孤陋寡闻,惭愧啊.... 

这里的stp文件果然是SharePoint里的模板文件,用于将SharePoint里的List或site等结构保存下来以便移植到别的SharePoint上。实际上这个stp文件是个Cab文件,可以强行更改其后缀为.cab,直接打开或解压缩后可以看到里面的文件,其中有个manifest.xml的XML文件。关于这个的具体描述在另外一篇文章《SharePoint Customization: Using WSS List Templates in SPS Areas》里说得很详细,可以参考。 

一、导出stp文件 

1、打开SharePoint里的网站,在"Site Actions"下选择"Site Settings",然后选择Look and Feel栏下的"Save site as template"即可; 

2、在SharePoint里打开一个List,点击"Settings"下的"List Settings",在“Permissions and Management”下点击"Save List as template"即可。 

二、导入stp文件创建Site及List 

打开SharePoint的Home页,点击Site Actions —> Site Settings —> Modify All Site Settings,在Galleries下选择Site templates或List templates进入Site Template Gallery页或List Template Gallery页,将相应的Site stp文件或List stp文件上传到Gallery。然后在新建网站或新建List时就可以选择上传的木板进行创建。

 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.IO;

using Microsoft.SharePoint;
using CodeArt.SharePoint;
using CodeArt.SharePoint.CamlQuery;

namespace BackFile
{
    class Program
    {
        static void Main(string[] args)
        {

            string SPSiteUrl = ConfigurationManager.AppSettings["SPSiteUrl"];
            string SPWebUrl = ConfigurationManager.AppSettings["SPWebUrl"];
            string SPDocumentLibraryName = ConfigurationManager.AppSettings["SPDocumentLibrary"];
            string BackupPath = ConfigurationManager.AppSettings["BackupPath"];

            SPSite site = null;
            SPWeb rootWeb = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (site = new SPSite(SPSiteUrl))
                {
                    using (rootWeb = site.OpenWeb(SPWebUrl))
                    {

                    }
                }
            });

            SPDocumentLibrary doclib = (SPDocumentLibrary)rootWeb.Lists[SPDocumentLibraryName];
            MakeFile(doclib.RootFolder, BackupPath);
            Console.ReadLine();

        }

        public static void MakeFile(SPFolder folder, string BackupPath)
        {
            Console.WriteLine("Current Folder:" + folder.Url);

            string folderPath = BackupPath + "\\" + folder.Url;
            if (!System.IO.Directory.Exists(folderPath))
            {
                Console.WriteLine("Create Folder:" + folder.Url);
                Directory.CreateDirectory(folderPath);
            }

            foreach (SPFile file in folder.Files)
            {
                Console.WriteLine("Create File:" + folderPath + "\\" + file.Name);
                byte[] bs = file.OpenBinary();
                File.Create(folderPath + "\\" + file.Name);
            }

            foreach (SPFolder subfolder in folder.SubFolders)
            {
                MakeFile(subfolder, BackupPath);
            }

        }
    }
}

  

posted @ 2017-09-18 08:08  每天进步一点点!  阅读(682)  评论(0编辑  收藏  举报