public void CreateFolder(string folderName) { if (string.IsNullOrEmpty(folderName)) { return; } SPWeb website = null; try { website = GetWebSite(); var library = (SPDocumentLibrary)website.Lists[ListName]; SPFolderCollection folders = website.Folders; folders.Add(Utilities.RemoveSlashAtTheEnd(SiteUrl) + "/" + Utilities.RemoveSlashAtTheEnd(SiteName) + "/" + Utilities.RemoveSlashAtTheEnd(ListName) + "/" + Utilities.RemoveSlashAtTheEnd(folderName) + "/"); library.Update(); } catch (Exception ex) { var log = new AppEventLog(AppException.ExceptionMessage(ex, "CreateFolder", "ClsHelper")); log.WriteToLog(); } finally { if (website != null) { website.Dispose(); } } }
private void CreateSubFolders(string[] folderUrls, SPFolder folder) { for (int i = 0; i < folderUrls.Length; i++) { SPFolderCollection coll = folder.SubFolders; coll.Add(folder.ServerRelativeUrl + "/" + folderUrls[i]); } }
public SPFolderInstance Add(string strUrl) { var result = m_folderCollection.Add(strUrl); if (result == null) { return(null); } return(new SPFolderInstance(this.Engine.Object.InstancePrototype, result.ParentWeb.Site, result.ParentWeb, result)); }
private void EnableAuditSettings(string site) { string auditLogLib = "ForSiteAuditing"; string auditLogPath = "/" + auditLogLib + "/"; try { using (SPWeb webNew = new SPSite(site).OpenWeb()) { SPSite spSite = webNew.Site; Guid id = webNew.Lists.Add(auditLogLib, "For Auditing", SPListTemplateType.DocumentLibrary); SPList listdoc = webNew.Lists[id]; listdoc.OnQuickLaunch = false; listdoc.Hidden = true; listdoc.Update(); SPDocumentLibrary _MyDocLibrary = (SPDocumentLibrary)webNew.Lists[auditLogLib]; SPFolderCollection _MyFolders = webNew.Folders; string folderURL = spSite.Url + auditLogPath + "AuditReports"; _MyFolders.Add(folderURL); //"ttp://adfsaccount:2222/My%20Documents/" + txtUpload.Text + "/"); _MyDocLibrary.Update(); spSite.TrimAuditLog = true; spSite.AuditLogTrimmingRetention = 90; Microsoft.Office.RecordsManagement.Reporting.AuditLogTrimmingReportCallout.SetAuditReportStorageLocation(spSite, folderURL); //AuditLogTrimmingReportCallout.SetAuditReportStorageLocation // Audi spSite.Audit.AuditFlags = SPAuditMaskType.Delete | SPAuditMaskType.Update | SPAuditMaskType.SecurityChange | SPAuditMaskType.SecurityChange | SPAuditMaskType.SchemaChange | SPAuditMaskType.Search; // site.Audit.AuditFlags =(Microsoft.SharePoint.SPAuditMaskType)auditOptions; spSite.Audit.Update(); } } catch { } }
private void CreateDirectories(string path, SPFolderCollection oFolderCollection) { //Upload Multiple Files foreach (var oFi in new DirectoryInfo(path).GetFiles()) { var fileStream = System.IO.File.OpenRead(oFi.FullName); var spfile = oFolderCollection.Folder.Files.Add (oFi.Name, fileStream, true); spfile.Update(); } //Upload Multiple Folders foreach (var oDi in new DirectoryInfo(path).GetDirectories()) { var sFolderName = oDi.FullName.Split('\\') [oDi.FullName.Split('\\').Length - 1]; var spNewFolder = oFolderCollection.Add(sFolderName); spNewFolder.Update(); //Recursive call to create child folder CreateDirectories(oDi.FullName, spNewFolder.SubFolders); } }
public static void CreateFolderTree(string spsURL, string libName, string fileFolders) { using (SPSite site = new SPSite(spsURL)) { using (SPWeb web = site.OpenWeb()) { string fullpath = spsURL + "/" + libName; char charReplace = '_'; char[] sch_or = { '|' }; char[] sch_star = { '*' }; char[] sch_slash = { '\\' }; string logFile = "c:\\logs.txt"; string limitGroup = "TestGroup"; using (System.IO.StreamReader sr = new System.IO.StreamReader(fileFolders)) { while (!sr.EndOfStream) { string s = sr.ReadLine(); string forPath = fullpath; string[] sarr = s.Split(sch_or); sarr[0] = StringClean(sarr[0], charReplace); string[] FPath = sarr[0].Split(sch_slash); string[] FCoordinators = sarr[1].Split(sch_star); string[] FAuthors = sarr[2].Split(sch_star); string[] FReaders = sarr[3].Split(sch_star); string[] FApprovers = sarr[4].Split(sch_star); int cols = FPath.GetLength(FPath.Rank - 1); for (int i = 1; i < cols; i++) { SPFolder exFolder = web.GetFolder(forPath + "/" + FPath[i]); if (!exFolder.Exists) { SPFolderCollection colFolders = web.GetFolder(forPath).SubFolders; colFolders.Add(FPath[i]); if (!exFolder.Exists) { WriteLog("===> Warning!!! Folder not create: " + forPath + "/" + FPath[i], logFile); } } if (i == cols - 1) { foreach (string coord in FCoordinators) { // spsURL, libName, Path, User, Permission if (coord != "") { string[] scoord = coord.Split(sch_slash); if (scoord[0] == "EMEA") { AddToGroup(spsURL, limitGroup, coord); SetPermUser(spsURL, libName, forPath + "/" + FPath[i], coord, "Full Control"); } } } foreach (string author in FAuthors) { if (author != "") { string[] sauthor = author.Split(sch_slash); if (sauthor[0] == "EMEA") { AddToGroup(spsURL, limitGroup, author); SetPermUser(spsURL, libName, forPath + "/" + FPath[i], author, "Contribute"); } } } foreach (string reader in FReaders) { if (reader != "") { string[] sreader = reader.Split(sch_slash); if (sreader[0] == "EMEA") { AddToGroup(spsURL, limitGroup, reader); SetPermUser(spsURL, libName, forPath + "/" + FPath[i], reader, "Read"); } } } foreach (string approver in FApprovers) { if (approver != "") { string[] sapprover = approver.Split(sch_slash); if (sapprover[0] == "EMEA") { AddToGroup(spsURL, limitGroup, approver); SetPermUser(spsURL, libName, forPath + "/" + FPath[i], approver, "Design"); } } } } forPath += "/" + FPath[i]; } forPath = ""; } } } } } // Close CreateFolderTree
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite siteCollection = properties.Feature.Parent as SPSite) { using (SPWeb web = siteCollection.OpenWeb()) { SPList list = web.Lists["Documents"]; string memGrpName = "Folder_Templates_Member"; string memPermName = "PWC Contribute"; string visGrpName = "Folder_Templates_Visitor"; string visPermName = "Read"; string blackbeltGroupName = "BlackBelt"; string greenbeltGroupName = "GreenBelt"; FormHomePage(siteCollection.OpenWeb().Url + "/SitePages/BreakThroughProcertProjectsTracking.aspx", "Header", "BreakThroughProcertProjectsTracking.aspx", ""); AddGroupUsers(siteCollection.OpenWeb().Url + "/SitePages/AddGroupUsers.aspx", "Header", "", ""); EmailCommentNotification(siteCollection.OpenWeb().Url + "/SitePages/EmailNotification.aspx", "Header", "EmailNotification.aspx", ""); CreateList(web, "Lookup_Organization_List", "This List Is used In BreakThroughProCertProjectsTracking.", "Lookup_Organization_List", "Lookup_Organization_List"); CreateList(web, "Lookup_ProcertMultilingual_List", "This List Is used In BreakThroughProCertProjectsTracking.", "Lookup_ProcertMultilingual_List", "Lookup_ProcertMultilingual_List"); CreateList(web, "Lookup_Plant_List", "This List Is used In BreakThroughProcertProjectsTracking.", "Lookup_Plant_List", "Lookup_Plant_List"); CreateList(web, "Lookup_ProjectType_List", "This List Is used In BreakThroughProcertProjectsTracking.", "Lookup_ProjectType_List", "Lookup_ProjectType_List"); CreateList(web, "Lookup_ProjectTeamData_List", "This List Is used In BreakThroughProcertProjectsTracking.", "Lookup_ProjectTeamData_List", "Lookup_ProjectTeamData_List"); CreateList(web, "Lookup_ProjectTeamRole_List", "This List Is used In BreakThroughProcertProjectsTracking.", "Lookup_ProjectTeamRole_List", "Lookup_ProjectTeamRole_List"); CreateList(web, "BreakThroughProcertProjectsTracking", "This List Is used In BreakThroughProcertProjectsTracking.", "BreakThrough Procert Projects Tracking", "BreakThroughProcertProjectsTracking"); CreateList(web, "Lookup_OtherAttachments_List", "This List Is used In BreakThroughProCertProjectsTracking.", "Lookup_OtherAttachments_List", "Lookup_OtherAttachments_List"); CreateList(web, "Lookup_ProcertEmailConfiguration", "This List Is used In BreakThroughProCertProjectsTracking.", "Lookup_ProcertEmailConfiguration", "Lookup_ProcertEmailConfiguration"); CreateList(web, "Lookup_Metricsarea_List", "This List Is used In BreakThroughProCertProjectsTracking.", "Lookup_Metricsarea_List", "Lookup_Metricsarea_List"); CreateDiscussionList(web); DeletecolumninDiscussion(web); AddColumnToDiscussion(web); if (!ContainsGroup(web.SiteGroups, blackbeltGroupName)) { CreateSubSiteGroup(web, blackbeltGroupName, memPermName, "This is Six Sigma Black Belt Group"); } if (!ContainsGroup(web.SiteGroups, greenbeltGroupName)) { CreateSubSiteGroup(web, greenbeltGroupName, memPermName, "This is Six Sigma Green Belt Group"); } if (!ContainsGroup(web.SiteGroups, memGrpName)) { CreateSFGroup(web, memGrpName, memPermName, "member"); } if (!ContainsGroup(web.SiteGroups, visGrpName)) { CreateSFGroup(web, visGrpName, visPermName, "visitor"); } SPFolderCollection spFolderColl = list.RootFolder.SubFolders; if (!web.GetFolder(web.ServerRelativeUrl + list.RootFolder + "/Templates").Exists) { SPFolder folder = spFolderColl.Add("Templates"); SPContentType secFolCT = list.ContentTypes["PWC Secure Folder"]; folder.Item[SPBuiltInFieldId.ContentTypeId] = secFolCT.Id; folder.Item.IconOverlay = "SecureFolderIcon.png"; folder.Item.SystemUpdate(); string[] FolderUrls = { "Info", "Info/Background", "Info/Problem Statement", "Info/Project Metrics", "Info/Benefits", "Info/Costs", "Info/Financial Analysis", "Info/Milestones", "Updates", "Updates/Quad Charts", "Gates", "Gates/Define", "Gates/Measure", "Gates/Analyze", "Gates/Improve", "Gates/Control", "Final Report" }; CreateSubFolders(FolderUrls, folder); SetFolderPermissions(web, "Templates", memGrpName, visGrpName, blackbeltGroupName, greenbeltGroupName, folder); } GrantPermissionOnSitePages(web); } } }); }