在作一個和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); } } } }