1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Security.AccessControl;
using System.Security.Permissions;
using Microsoft.SharePoint ;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.WebControls ;
using System.IO;
namespace W32SP.Class
{
/// <summary>
/// Description : Class for parse information to sharepoint
/// Use for : Create, modify, delete some items on sharepoint
/// </summary>
class CParserSP
{
protected String m_sRootURL = "";
protected SPSite m_oSite;
protected SPWeb m_oWeb;
protected Exception m_xError;
/// <summary>
/// Description : Constructor of CParserSP
/// </summary>
/// <param name="p_sRootURL">Url of the SHAREPOINT root site, exemple : "HTTP://MySharepointsite"</param>
public CParserSP(String p_sRootURL)
{
m_sRootURL = p_sRootURL;
m_oSite = new SPSite(m_sRootURL);
m_oWeb = m_oSite.OpenWeb();
// Set read and write permission
m_oSite.AllowUnsafeUpdates = true;
m_oWeb.AllowUnsafeUpdates = true;
}
#region GET&SET
#region m_oSite
public SPSite get_oSite()
{
return m_oSite;
}
public void set_oSite(SPSite p_oValue)
{
m_oSite = p_oValue;
}
#endregion
#region m_oWeb
public SPWeb get_oWeb()
{
return m_oWeb;
}
public void set_oWeb(SPWeb p_oValue)
{
m_oWeb = p_oValue;
}
#endregion
#endregion
#region CREATE
/// <summary>
/// Method for create a new site
/// </summary>
/// <param name="p_sNameURL">Name for URL (No space)= "my_new_site"</param>
/// <param name="p_sSiteName">Title of the new site = "My New Site"</param>
/// <param name="p_sDescription">Description for site = "my description of the site ..."</param>
/// <param name="p_sTemplate">Template for site
/// "Team site": SiteTemplateCode = "STS#0"
/// "Blank Site": SiteTemplateCode = "STS#1"
/// "Document workspace": SiteTemplateCode = "STS#2"
/// "Basic meeting workspace": SiteTemplateCode = "MPS#0"
/// "Blank meeting workspace": SiteTemplateCode = "MPS#1"
/// "Decision meeting workspace": SiteTemplateCode = "MPS#2"
/// "Social meeting workspace": SiteTemplateCode = "MPS#3"
/// "Multipage meeting workspace": SiteTemplateCode = "MPS#4"
/// "Wiki": SiteTemplateCode = "WIKI#0"
/// "Blog": SiteTemplateCode = "BLOG#0"
/// "Document center": SiteTemplateCode = "BDR#0"
/// "Records center": SiteTemplateCode = "OFFILE#0"
/// "Define routes for incoming files": SiteTemplateCode = "OFFILE#1"
/// "Publishing site": SiteTemplateCode = "CMSPUBLISHING#0"
/// "Publishing site With Workflows": SiteTemplateCode = "BLANKINTERNET#0"
/// "Press releases site": SiteTemplateCode = "BLANKINTERNET#1"
/// "Publishing site with workflow": SiteTemplateCode = "BLANKINTERNET#2"
/// "News and Articles": SiteTemplateCode = "SPSNHOME#0"
/// "Report center": SiteTemplateCode = "SPSREPORTCENTER#0"
/// "Intranet Divisional Portal": SiteTemplateCode = "SPSPORTAL#0"
/// "Profile Site": SiteTemplateCode = "PROFILES#0"
/// "Publishing porta": SiteTemplateCode = "BLANKINTERNETCONTAINER#0" </param>
/// <returns> Normal : SPWeb >> New site </returns>
///
public SPWeb CreateSite(String p_sNameURL, String p_sSiteName, String p_sDescription,String p_sTemplate)
{
SPWebCollection oWebCol = m_oWeb.Webs;
SPWeb oNewSite = oWebCol.Add(p_sNameURL, p_sSiteName, p_sDescription, 1033, p_sTemplate, true, false);
m_oWeb.AllowUnsafeUpdates = false;
return oNewSite;
}
/// <summary>
/// Method for create a new list
/// </summary>
/// <param name="p_sRootWeb">Root web for list</param>
/// <param name="p_oTemplateType">Template Type for list</param>
/// <param name="p_sLibName">Name of the list</param>
/// <returns> Normal : SpList >> New list</returns>
///
public SPList CreateList(SPWeb p_sRootWeb, String p_sLibName, SPListTemplateType p_oTemplateType)
{
Guid oListId = p_sRootWeb.Lists.Add(p_sLibName, null, p_oTemplateType);
return p_sRootWeb.Lists[oListId];
}
/// <summary>
/// Method for create a new Item in list
/// </summary>
/// <param name="p_oRootList">Root List</param>
/// <param name="p_oItemType">Type if the item</param>
/// <param name="p_sItemName">Name of the item</param>
/// <returns> Normal : SPListItem </returns>
///
public SPListItem CreateListItem(SPList p_oRootList,String p_sItemName,SPFileSystemObjectType p_oItemType)
{
SPListItem oListItem = p_oRootList.Items.Add("" , p_oItemType, p_sItemName);
oListItem.Update();
return oListItem;
}
/// <summary>
/// Method for create a Subfolder
/// </summary>
/// <param name="p_oFolderCol">the root collection to attache this folder</param>
/// <param name="p_sFolderName">Name of the folder</param>
/// <returns> Normal : SPFolder </returns>
///
public SPFolder CreateSubFolder(SPFolderCollection p_oFolderCol, String p_sFolderName)
{
SPFolder oNewFolder = p_oFolderCol.Add(p_sFolderName);
oNewFolder.Update();
return oNewFolder;
}
/// <summary>
/// Method for create a wikipage
/// </summary>
/// <param name="p_oRootList">the root list</param>
/// <param name="p_sPageName">Name of the page with .aspx</param>
/// <param name="p_sPageURLName">Relative-URL to put the page with the name and .aspx file</param>
/// <returns> Normal : SPListItem </returns>
///
public SPListItem CreateWikiPage(SPList p_oRootList, String p_sPageURLName ,String p_sPageName,String p_sContent)
{
SPFolder oFolder = p_oRootList.RootFolder;
SPFileCollection oFileCol = oFolder.Files;
SPFile oWikiFile = oFileCol.Add(p_sPageURLName, SPTemplateFileType.WikiPage);
SPListItem oWikiPage = oWikiFile.Item;
oWikiPage["Name"] = p_sPageName;
oWikiPage["Wiki Content"] = p_sContent;
oWikiPage.Update();
return oWikiPage;
}
/// <summary>
/// Method for create a Webpart in wikipage
/// </summary>
/// <param name="p_oPage">The Wiki page where you want to put the webpart</param>
/// <param name="p_oList">WebPart List</param>
/// <param name="p_sNameWebPart">Name of the WebPart</param>
/// <returns> none </returns>
///
public void InsertListWebPart(SPFile p_oPage, SPList p_oList, String p_sNameWebPart)
{
SPLimitedWebPartManager oWPmng = p_oPage.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
XsltListViewWebPart oWP = new XsltListViewWebPart()
{
ListId = p_oList.ID,
Title = p_sNameWebPart
};
oWPmng.AddWebPart(oWP,"WPLibrary",100);
}
#endregion
#region FILES
/// <summary>
/// Method for upload a file
/// </summary>
/// <param name="p_oRootFolder">the destination root folder</param>
/// <param name="p_sFilePath">full path of file with namefile and extension</param>
/// <param name="p_sFileName">Name of the file with extension</param>"
/// <returns> Normal : SPFile </returns>
///
public SPFile UploadFile(SPFolder p_oRootFolder, String p_sFilePath, String p_sFileName)
{
SPFileCollection oFileCol = p_oRootFolder.Files;
String sFileURL = p_oRootFolder.ServerRelativeUrl + "\\" + p_sFileName;
Stream oStream = File.Open(p_sFilePath, FileMode.OpenOrCreate);
Byte[] bContents = new Byte[oStream.Length];
oStream.Position = 0;
oStream.Read(bContents, 0, (int)oStream.Length);
oStream.Close();
SPFile oFile = p_oRootFolder.Files.Add(sFileURL, bContents);
return oFile ;
}
/// <summary>
/// Method for upload a Binary file
/// </summary>
/// <param name="p_oRootFolder">the destination root folder</param>
/// <param name="p_bContents">Binary content</param>
/// <param name="p_sFileName">Name of the file with extension</param>"
/// <returns> Normal : SPFile </returns>
///
public SPFile UploadBinaryFile(SPFolder p_oRootFolder, Byte[] p_bContents, String p_sFileName)
{
SPFileCollection oFileCol = p_oRootFolder.Files;
String sFileURL = p_oRootFolder.ServerRelativeUrl + "\\" + p_sFileName;
SPFile oFile = p_oRootFolder.Files.Add(sFileURL, p_bContents);
return oFile;
}
#endregion
}
} |
Partager