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》里说得很详细,能够参考。 

1、导出stp文件 

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

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

2、导入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时就能够选择上传的木板进行建立。post

 
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);
            }

        }
    }
}

  

相关文章
相关标签/搜索