public override void AddPackage(AddPackageContext context, Boolean autoActivate) { SPWeb targetWeb = context.TargetWeb; SPSite targetSite = targetWeb.Site; StorePackage package = context.StorePackage; SPList solutionsList = targetSite.GetCatalog(SPListTemplateType.SolutionCatalog); bool currentWebUnsafeSettings = context.SPContext.Web.AllowUnsafeUpdates; bool currentSettings = targetWeb.AllowUnsafeUpdates; targetWeb.AllowUnsafeUpdates = true; context.SPContext.Web.AllowUnsafeUpdates = true; SPFile file = solutionsList.RootFolder.Files.Add(context.StorePackage.SolutionFileName, File.ReadAllBytes(context.SolutionFilePath)); SPUserSolution solution = targetSite.Solutions.Add(file.Item.ID); targetWeb.AllowUnsafeUpdates = currentSettings; context.SPContext.Web.AllowUnsafeUpdates = currentWebUnsafeSettings; if (!string.IsNullOrEmpty(package.SetupFeatureID)) { if (autoActivate) { try { SPSINStorePackageUtilities.AddPendingActivationFeature(context.TargetWeb, new Guid(package.SetupFeatureID)); } catch { // Cannot add automatic activation... } } } }
private void SetMasterPage(SPSite siteCollection, string masterPageName) { SPList masterPage = siteCollection.GetCatalog(SPListTemplateType.MasterPageCatalog); string masterUrl = SPUrlUtility.CombineUrl(masterPage.RootFolder.ServerRelativeUrl, masterPageName); foreach (SPWeb site in siteCollection.AllWebs) { site.MasterUrl = masterUrl; site.CustomMasterUrl = masterUrl; site.Update(); } }
internal SPUserSolution DeploySolution(FileInfo _featuteFile) { try { if (SiteCollection == null) { throw new ApplicationException(Resources.SiteCollectionNotExist); } SPDocumentLibrary solutionGallery = (SPDocumentLibrary)SiteCollection.GetCatalog(SPListTemplateType.SolutionCatalog); SPFile file = solutionGallery.RootFolder.Files.Add(_featuteFile.Name, _featuteFile.OpenRead(), true); return(SiteCollection.Solutions.Add(file.Item.ID)); } catch (Exception ex) { string _msg = String.Format( Resources.DeploySolutionFailed, SiteCollection != null ? SiteCollection.Url : Resources.NullReference, _featuteFile.Name, ex.Message); throw new ApplicationException(_msg); } }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { return; SPSite site = properties.Feature.Parent as SPSite; // System.Diagnostics.Debugger.Launch(); if (site != null) { SPWeb topLevelSite = site.RootWeb; // Calculate relative path to site from Web Application root. string webAppRelativePath = topLevelSite.ServerRelativeUrl; if (!webAppRelativePath.EndsWith("/")) { webAppRelativePath += "/"; } // Activate publishing infrastructure // site.Features.Add(new Guid("f6924d36-2fa8-4f0b-b16d-06b7250180fa"), true); SPList masterPageGallery = site.GetCatalog(SPListTemplateType.MasterPageCatalog); foreach (SPListItem li in masterPageGallery.Items) { if (li.File.Name.ToLower() == "napas.master") { if (!li.HasPublishedVersion) { li.File.CheckIn("Automatically checked in by NAPAS.CDMS.Branding Master Page feature", SPCheckinType.MajorCheckIn); li.File.Update(); li.File.Approve("Automatically approved by NAPAS.CDMS.Branding Master Page feature"); li.File.Update(); } } // Enumerate through each site and apply branding. foreach (SPWeb web in site.AllWebs) { // Activate the publishing feature for all webs. // web.Features.Add(new Guid("94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb"), true); web.MasterUrl = webAppRelativePath + "_catalogs/masterpage/napas_theme/napas.master"; web.CustomMasterUrl = webAppRelativePath + "_catalogs/masterpage/napas_theme/napas.master"; web.Update(); } } } }
public SPListInstance GetCatalog(string typeCatalog) { SPListTemplateType listTemplateType; if (!typeCatalog.TryParseEnum(true, out listTemplateType)) { throw new JavaScriptException(Engine, "Error", "Type Catalog must be specified."); } var result = m_site.GetCatalog(listTemplateType); return(result == null ? null : new SPListInstance(Engine, m_site, result.ParentWeb, result)); }
/// <summary> /// Method to get the MasterPage SPFile from a fileName and the SPSite /// RootFolder.Files is a SPFileCollection and the indexer [] throws an ArgumentException if the fileName is not found. /// We can't use web.GetFile() for a catalog file. /// Log the error and return null. /// </summary> /// <param name="site">The current Site Collection where the MasterPage Gallery lives</param> /// <param name="fileName">The filename of the MasterPage we are looking for. With the extension. Ex: seattle.master</param> /// <returns>A SPFile if found, null if not found.</returns> private SPFile GetSiteRelativeMasterPageUrl(SPSite site, string fileName) { SPFile masterPageFile = null; var masterPageCatalog = site.GetCatalog(SPListTemplateType.MasterPageCatalog); try { masterPageFile = masterPageCatalog.RootFolder.Files[fileName]; } catch (ArgumentException e) { this.logger.Warn("The file with filename '{0}' was not found in the master page gallery. StackTrace: {1}", fileName, e.StackTrace); } return(masterPageFile); }
/// <summary> /// Function to activate the SAO feature /// </summary> /// <param name="properties"></param> public override void FeatureActivated(SPFeatureReceiverProperties properties) { try { SPSite site = properties.Feature.Parent as SPSite; if (site != null) { SPWeb rootWeb = site.RootWeb; SPList gallery = site.GetCatalog(SPListTemplateType.MasterPageCatalog); if (gallery != null) { SPListItemCollection folders = gallery.Folders; string featureId = properties.Feature.Definition.Id.ToString(); foreach (string folderUrl in folderUrls) { SPFolder folder = GetFolderByUrl(folders, folderUrl); if (folder != null) { PublishFiles(folder, featureId); } } } } } catch (Exception err) { using (SPSite oSPSite = new SPSite(SPContext.Current.Site.Url)) { using (SPWeb oSPWeb = oSPSite.OpenWeb()) { LogErrorHelper logHelper = new LogErrorHelper(LIST_SETTING, oSPWeb); logHelper.logSysErrorEmail(APP_NAME, err, "FeatureActivated Error!"); logHelper = null; } } SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, err.Message.ToString(), err.StackTrace); } }
public void DisplayTemplate() { SPSite site = properties.Feature.Parent as SPSite; if (site != null) { SPWeb rootWeb = site.RootWeb; SPList gallery = site.GetCatalog(SPListTemplateType.MasterPageCatalog); if (gallery != null) { SPListItemCollection folders = gallery.Folders; string featureId = properties.Feature.Definition.Id.ToString(); foreach (string folderUrl in folderUrls) { SPFolder folder = GetFolderByUrl(folders, folderUrl); if (folder != null) { PublishFiles(folder, featureId); } } } } }
private void LoadTemplateFromPackage(SPSite site, string packageFileName, string packageDirectory) { SPDocumentLibrary solutions = (SPDocumentLibrary)site.GetCatalog(SPListTemplateType.SolutionCatalog); /*SPFile solutionFile = solutions.RootFolder.Files.Add( packageFileName, fileSystemHelper.ReadFile( fileSystemHelper.CombinePath(packageDirectory, packageFileName)));*/ SPFile solutionFile = solutions.RootFolder.Files.Add( packageFileName, ReadFile(CombinePath(packageDirectory, packageFileName))); SPUserSolution solution = site.Solutions.Add(solutionFile.Item.ID); Guid solutionId = solution.SolutionId; SPFeatureDefinitionCollection siteFeatures = site.FeatureDefinitions; var features = from SPFeatureDefinition f in siteFeatures where f.SolutionId.Equals(solutionId) && f.Scope == SPFeatureScope.Site select f; foreach (SPFeatureDefinition feature in features) { site.Features.Add(feature.Id, false, SPFeatureDefinitionScope.Site); } }
public static SPUserSolution AddSandboxedSolution(SPSite site, byte[] fileData, string solutionName) { site.RequireNotNull("site"); fileData.RequireNotNull("fileData"); solutionName.RequireNotNullOrEmpty("solutionName"); SPDocumentLibrary solutionGallery = site.GetCatalog(SPListTemplateType.SolutionCatalog) as SPDocumentLibrary; if (null != solutionGallery) { solutionGallery.ParentWeb.AllowUnsafeUpdates = true; string solutionPath = Path.Combine(solutionGallery.RootFolder.ServerRelativeUrl, solutionName); if (!site.RootWeb.GetFile(solutionPath).Exists) { SPFile solutionFile = solutionGallery.RootFolder.Files.Add(solutionName, fileData); SPUserSolution solution = site.Solutions.Add(solutionFile.Item.ID); return solution; } } return null; }
/// <summary> /// Method to get the MasterPage SPFile from a fileName and the SPSite /// RootFolder.Files is a SPFileCollection and the indexer [] throws an ArgumentException if the fileName is not found. /// We can't use web.GetFile() for a catalog file. /// Log the error and return null. /// </summary> /// <param name="site">The current Site Collection where the MasterPage Gallery lives</param> /// <param name="fileName">The filename of the MasterPage we are looking for. With the extension. Ex: seattle.master</param> /// <returns>A SPFile if found, null if not found.</returns> private SPFile GetSiteRelativeMasterPageUrl(SPSite site, string fileName) { SPFile masterPageFile = null; var masterPageCatalog = site.GetCatalog(SPListTemplateType.MasterPageCatalog); try { masterPageFile = masterPageCatalog.RootFolder.Files[fileName]; } catch (ArgumentException e) { this.logger.Warn("The file with filename '{0}' was not found in the master page gallery. StackTrace: {1}", fileName, e.StackTrace); } return masterPageFile; }
static void Main(string[] args) { bool listOnly = false; Console.ForegroundColor = ConsoleColor.White; if (args.Length == 2 && args[1].ToLower() == "/list") { listOnly = true; } if (args.Length != 2) { Console.WriteLine("Deletes a web part from the web part gallary."); Console.ResetColor(); Console.WriteLine( string.Format( "Usage: {0} {1} {2}", System.AppDomain.CurrentDomain.FriendlyName, "http://localhost:51001", "name.webpart" ) ); Console.WriteLine( string.Format( "Usage: {0} {1} {2}", System.AppDomain.CurrentDomain.FriendlyName, "http://localhost:51001", "webpartID" ) ); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nTo show all installed web parts."); Console.ResetColor(); Console.WriteLine(string.Format("{0} {1} {2}", System.AppDomain.CurrentDomain.FriendlyName, "http://localhost:51001", "/list")); return; } string siteUrl = args[0]; string webpartName = listOnly ? string.Empty : args[1].ToLower(); int webpartID = 0; int.TryParse(webpartName, out webpartID); using (SPSite parentSite = new SPSite(siteUrl)) { List <int> toDelete = new List <int>(); SPList list = parentSite.GetCatalog(SPListTemplateType.WebPartCatalog); Console.WriteLine("Searching..."); Console.ResetColor(); foreach (SPListItem item in list.Items) { if (listOnly) { Console.WriteLine("Found: " + item.ID + ", " + item.Name); continue; } if (webpartID > 0) { if (item.ID == webpartID) { Console.WriteLine("Found: " + item.Name + " with ID " + item.ID); toDelete.Add(item.ID); } } else { if (item["Web Part"].ToString().ToLower() == webpartName) { Console.WriteLine("Found: " + webpartName + " with ID " + item.ID); toDelete.Add(item.ID); } } } if (listOnly) { return; } if (toDelete.Count() == 0) { Console.WriteLine("Found nothing matching."); } foreach (int i in toDelete) { SPListItem item = list.GetItemById(i); item.Delete(); Console.WriteLine("Deleted ID: " + i); } Console.WriteLine("Updating list..."); list.Update(); Console.WriteLine("Done."); } }
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPSite site = null; SPList list = null; List <string> list2 = new List <string>(); bool flag = false; bool flag2 = true; try { foreach (SPElementDefinition definition in (IEnumerable)properties.Definition.GetElementDefinitions(CultureInfo.InvariantCulture)) { if (definition.XmlDefinition.HasChildNodes) { foreach (XmlNode node in definition.XmlDefinition.ChildNodes) { foreach (XmlAttribute attribute in node.Attributes) { if (attribute.LocalName == "Url") { string str; if (!list2.Contains(str = attribute.Value.ToLowerInvariant())) { list2.Add(str); } break; } } } } } } catch { } try { if (((list2.Count > 0) && ((site = properties.Feature.Parent as SPSite) != null)) && ((list = site.GetCatalog(SPListTemplateType.WebPartCatalog)) != null)) { while (flag2) { flag2 = false; foreach (SPListItem item in ProductPage.TryEach <SPListItem>(list.Items)) { if (list2.Contains(item.Name.ToLowerInvariant())) { item.Delete(); flag2 = flag = true; continue; } } } } } catch { } try { if (flag) { site.AllowUnsafeUpdates = true; list.Update(); } } catch { } }