public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { var web = properties.Feature.Parent as SPWeb; var relativeWebUrl = web.ServerRelativeUrl; if (!relativeWebUrl.EndsWith("/")) { relativeWebUrl += "/"; } var list = web.GetList(string.Format("{0}_catalogs/design", relativeWebUrl)); if (list == null) { return; } SPQuery query = new SPQuery(); query.ViewFields = "<FieldRef Name='ThemeUrl' />"; query.RowLimit = 10; query.Query = string.Format("<Where><Eq><FieldRef Name='Name' /><Value Type='Text'>{0}</Value></Eq></Where>", THEMENAME); SPListItemCollection listItems = list.GetItems(query); if (listItems.Count >= 1) { listItems.Delete(0); } }
private static void RemoveOldFiles(SPWeb web) { SPList list = GetOASList(web); DateTime limit_date = DateTime.Now.Subtract(new TimeSpan(TIME_LIMIT, 0, 0)); web.AllowUnsafeUpdates = true; bool removed = false; do { removed = false; SPListItemCollection listItems = list.Items; int itemCount = listItems.Count; for (int k = 0; k < itemCount; k++) { SPListItem item = listItems[k]; if ((DateTime)item["Started"] < limit_date) { //source file string fileid = item["FileId"].ToString(); //conveted file string source = Path.GetFileNameWithoutExtension(fileid); SPFolder lib = GetOASLibrary(web); //delete result file SPFile res = GetFile(lib, fileid); if (res != null) { res.Delete(); lib.Update(); } //delete source file res = GetFile(lib, source); if (res != null) { res.Delete(); lib.Update(); } listItems.Delete(k); removed = true; break; } } }while (removed); web.AllowUnsafeUpdates = false; }
// Uncomment the method below to handle the event raised after a feature has been activated. //public override void FeatureActivated(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised before a feature is deactivated. //public override void FeatureDeactivating(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised after a feature has been installed. public override void FeatureInstalled(SPFeatureReceiverProperties properties) { try { //active feature for CA web app during install //SPDashFeature = beba7f1a-f972-4759-89fe-8777a539a4cb //SPDashTimerJobFeature = 753f6c7b-95fb-41de-977f-489689d4902c Logger.LogInfo("FeatureInstalled - SPDashFeature beba7f1a-f972-4759-89fe-8777a539a4cb"); Microsoft.SharePoint.Administration.SPAdministrationWebApplication caApp = SPAdministrationWebApplication.Local; string caUrl = caApp.Sites[0].Url; string caCmd = string.Format("Start-Sleep 10; Enable-SPFeature 753f6c7b-95fb-41de-977f-489689d4902c -Url " + caUrl + "; Enable-SPFeature beba7f1a-f972-4759-89fe-8777a539a4cb -Url " + caUrl); Logger.LogInfo("caUrl = " + caUrl); Logger.LogInfo("caCmd = " + caCmd); //empty CA library (if found from previous install) using (SPSite caSite = caApp.Sites[0]) { using (SPWeb caWeb = caSite.OpenWeb()) { caWeb.AllowUnsafeUpdates = true; //attempt to find SPList listSPDash = caWeb.Lists.TryGetList("SPDash"); if (listSPDash != null) { SPListItemCollection items = listSPDash.Items; for (int i = items.Count - 1; i > -1; i--) { items.Delete(i); } } caWeb.AllowUnsafeUpdates = false; } } //start cmd ProcessStartInfo startinfo = new ProcessStartInfo(); startinfo.FileName = "powershell.exe"; startinfo.Arguments = caCmd; startinfo.UseShellExecute = false; startinfo.CreateNoWindow = true; Process process; process = Process.Start(startinfo); Logger.LogInfo("FeatureInstalled - OK"); //execute first population Engine.main(); } catch (Exception x) { Logger.LogError(String.Format("SPDash Feature Activation error: {0}", x.Message)); } }
private static void RemoveConversionFiles(SPWeb web, string JobId) { SPList list = GetOASList(web); SPListItemCollection listItems = list.Items; int itemCount = listItems.Count; web.AllowUnsafeUpdates = true; for (int k = 0; k < itemCount; k++) { SPListItem item = listItems[k]; if (JobId == item["JobId"].ToString()) { //source file string fileid = item["FileId"].ToString(); //conveted file string source = Path.GetFileNameWithoutExtension(fileid); SPFolder lib = GetOASLibrary(web); //delete result file SPFile res = GetFile(lib, fileid); if (res != null) { res.Delete(); lib.Update(); } //delete source file res = GetFile(lib, source); if (res != null) { res.Delete(); lib.Update(); } listItems.Delete(k); break; } } web.AllowUnsafeUpdates = false; }
void CheckReferencedata(String Listname, Object Value) { SPSite site = new SPSite("SiteURL"); SPWeb web = site.AllWebs["WebnameWhenthelistsarethere"]; web.AllowUnsafeUpdates = true; SPList list = web.Lists[Listname]; SPQuery Query = new SPQuery(); Query.Query = "<Where><Eq><FieldRef Name='ProgramId'/><Value Type='Text'>" + Value + "</Value></Eq></Where>"; SPListItemCollection AnswerItems = list.GetItems(Query); int Count = AnswerItems.Count; if (Count > 0) { for (int index = 0; index < Count; index++) { SPListItem item = AnswerItems[index]; AnswerItems.Delete(index); } } list.Update(); }
public void Delete(int index) { m_listItemCollection.Delete(index); }
/// <summary> /// Deletes the list items from specified ListCollection. /// </summary> /// <param name="listItems">The listItem collection.</param> private void DeleteLinkItems(SPListItemCollection listItems) { try { for (int intIndex = listItems.Count - 1; intIndex > -1; intIndex--) { listItems.Delete(intIndex); } } catch (Exception) { throw; } }