Ejemplo n.º 1
0
        private void RemoveSistema(int id)
        {
            using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb web = site.RootWeb)
                {
                    web.AllowUnsafeUpdates = true;

                    SPList listMeusSistemas = web.Lists.TryGetList(LIST_MEUSSISTEMAS);

                    if (listMeusSistemas != null)
                    {
                        SPListItem sistema = listMeusSistemas.Items.GetItemById(id);

                        if (sistema != null)
                        {
                            sistema.Delete();
                            Page.Response.Redirect("/SitePages/MeusSistemas.aspx");
                        }
                    }

                    web.AllowUnsafeUpdates = false;
                }
            }
        }
Ejemplo n.º 2
0
        internal static void DeleteGateKeeperItem(int id)
        {
            SPWeb  web = null;
            string url = SPContext.Current.Web.Url;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(url, SPUserToken.SystemAccount))
                {
                    site.AllowUnsafeUpdates = true;
                    web = site.OpenWeb();

                    if (web != null)
                    {
                        web.AllowUnsafeUpdates = true;

                        SPList gatekeeper = web.Lists["GateKeeper"];
                        SPListItem item   = gatekeeper.Items.GetItemById(id);
                        if (item != null)
                        {
                            item.Delete();
                            gatekeeper.Update();
                        }
                        web.AllowUnsafeUpdates = false;
                    }

                    site.AllowUnsafeUpdates = false;
                }
            });
        }
Ejemplo n.º 3
0
        private void RecursivelyDeleteIfExists(SPSite site, SPWeb web, SPList list, SPListItem item, string username, string password)
        {
            string localWebURL         = item.WBxGetColumnAsString(LOCAL_PAGE_URL);
            string localWebRelativeURL = WBUtils.GetURLWithoutHostHeader(localWebURL);

            bool isOriginalMapping = item.WBxGetColumnAsBool(ORIGINAL_MAPPING);

            try
            {
                SPWeb localWeb = site.OpenWeb(localWebRelativeURL);

                if (localWeb.Exists)
                {
                    // NB that this method also disposes of the SPWeb object passed in:
                    WBUtils.RecursivelyDeleteSPWeb(localWeb);
                }

                if (!isOriginalMapping)
                {
                    item.Delete();
                }
            }
            catch (Exception error)
            {
                WBLogging.Migration.Unexpected("Error when trying to perform 'Delete' action: " + error.Message);
            }
        }
Ejemplo n.º 4
0
        public bool Delete(int id)
        {
            if (id > 0)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (SPSite site = new SPSite(SiteUrl))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            web.AllowUnsafeUpdates = true;
                            SPList list            = web.GetList(string.Format("{0}{1}", web.Url, ListUrl));

                            SPListItem item = list.GetItemById(id);
                            if (item != null)
                            {
                                item.Delete();
                                list.Update();
                            }

                            web.AllowUnsafeUpdates = false;
                        }
                    }
                });
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        public bool RemoveDocumentByID(String recordID)
        {
            if (!IsOpen)
            {
                Open();
            }

            WBLogging.Debug("Call to RemoveDocumentByID with recordID = " + recordID + " for library: " + this.URL);

            SPListItem recordItem = WBUtils.FindItemByColumn(Site, List, WBColumn.RecordID, recordID);

            if (recordItem == null)
            {
                // There is currently no such item - so there is nothing to remove.
                return(false);
            }
            else
            {
                Records.UndeclareItemAsRecord(recordItem);
                recordItem.Delete();
                //libraryWeb.Update();

                return(true);
            }
        }
        public void CleansingFiles(string OutputFolder, string DocLib)
        {
            try
            {
                int    CleansingDays = new CleansingHelper().GetCleansingDays();
                SPSite Site          = new SPSite(ConfigurationManager.AppSettings["SharePointOnPremURL"].ToString());
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPWeb web = Site.OpenWeb())
                    {
                        web.AllowUnsafeUpdates = true;
                        SPFolder libFolder     = web.Folders[DocLib];
                        SPFileCollection file  = libFolder.Files;

                        foreach (SPFile f in file)
                        {
                            SPListItem item = f.Item;
                            int diff_days   = (DateTime.Now - f.TimeCreated).Days;
                            if (diff_days > CleansingDays)
                            {
                                item.Delete();
                            }
                        }
                        web.AllowUnsafeUpdates = false;
                    }
                });
            }
            catch (Exception ex)
            {
                new GenerateTxt().GenerateTxtLogError(OutputFolder, ex.Message, "CleansingFiles SharePoint - " + DocLib);
            }
        }
Ejemplo n.º 7
0
        private void Remove_ZaimportowaneFaktury_ExecuteCode(object sender, EventArgs e)
        {
            SPList faktury   = item.Web.Lists.TryGetList(_tabFaktury);
            SPList dokumenty = item.Web.Lists.TryGetList(_libFaktury);

            foreach (SPListItem fk in fakturyKlineta)
            {
                int fakId = fk.ID;
                if (fakId > 0)
                {
                    SPListItem f = faktury.Items.GetItemById(fk.ID);
                    if (f != null)
                    {
                        f.Delete();
                    }
                }


                int docId = (int)BLL.Tools.Get_Value(fk, "_DokumentId");
                if (docId > 0)
                {
                    SPListItem d = dokumenty.Items.GetItemById(docId);
                    if (d != null)
                    {
                        d.Delete();
                    }
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dAlert"></param>
 internal void DeleteAlerts(string alertID, MailTemplateManager mtManager)
 {
     try
     {
         SPListItem alertItem = null;
         //Delete the alert
         if (!string.IsNullOrEmpty(alertID))
         {
             alertItem = this.alertList.GetItemById(Convert.ToInt32(alertID));
             if (alertItem != null)
             {
                 try
                 {
                     alertItem.Delete();
                     //Delte the template objects for the alerts
                     mtManager.DeleteTemplateUsageObjects(alertID);
                 }
                 catch
                 {
                     //error occured while deleting alert
                 }
             }
         }
         else
         {
             //Alert Id is null or empty
         }
     }
     catch
     {
         //Error occured while deleting alert
     }
 }
 /// <summary>Deletes the folder.</summary>
 public void Delete()
 {
     assignmentFolder.Delete();
     if (isLearnerFolder == false)
     {
         DeleteAssociatedView();
     }
 }
Ejemplo n.º 10
0
        public override bool Perform()
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    using (var spSite = new SPSite(Web.Site.ID))
                    {
                        using (SPWeb spWeb = spSite.OpenWeb(Web.ID))
                        {
                            if (!spWeb.IsRootWeb)
                            {
                                LogMessage(spWeb.Title + " is not a root web.", MessageKind.SKIPPED, 2);
                                return;
                            }

                            LogMessage("Getting " + SETTINGS_LIST + " list", 2);

                            SPList list = Web.Lists.TryGetList(SETTINGS_LIST);
                            if (list != null)
                            {
                                LogMessage("Remove menu item: Get Started!.", 2);

                                SPQuery jobQueueQuery             = new SPQuery();
                                jobQueueQuery.Query               = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>Get Started!</Value></Eq></Where>";
                                SPListItemCollection jobListItems = list.GetItems(jobQueueQuery);

                                if (jobListItems != null && jobListItems.Count > 0)
                                {
                                    SPListItem li = jobListItems[0];
                                    li.Delete();

                                    LogMessage("Get started menu item removed.", MessageKind.SUCCESS, 4);
                                }
                                else
                                {
                                    LogMessage("Get started menu item not available.", MessageKind.SKIPPED, 2);
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception e)
            {
                LogMessage(e.Message, MessageKind.FAILURE, 2);
            }
            finally
            {
                try
                {
                    CacheStore.Current.RemoveSafely(Web.Url, new CacheStoreCategory(Web).Navigation);
                }
                catch { }
            }
            return(true);
        }
Ejemplo n.º 11
0
        public static void DeleteGroupProxyItem(SPList groupProxyList, SPUser user)
        {
            SPListItem item = GetGroupProxyItem(groupProxyList, user);

            if (item != null)
            {
                item.Delete();
            }
        }
Ejemplo n.º 12
0
        // Удаляем файл
        private void deleteFile()
        {
            // Получаем элемент из библиотеки документов по UniqueID и удаляем его
            SPWeb      web        = SPContext.Current.Site.RootWeb;
            SPList     list       = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, libraryName));
            SPListItem spFileItem = list.GetItemByUniqueId(currentFile.UniqueID);

            spFileItem.Delete();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Fires when delete button was clicked
        /// </summary>
        /// <param name="sender"> Button </param>
        /// <param name="e"></param>
        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            int selectedIndex = TasksList.SelectedIndex;
            //get items depending on selected index
            SPListItem item = CurrentSite.Web.Lists.TryGetList("TestList").Items[selectedIndex];

            item.Delete();

            FillData();
        }
Ejemplo n.º 14
0
 public static void DeleteUnsafe(this SPListItem item)
 {
     if (item != null)
     {
         bool allow = item.Web.AllowUnsafeUpdates;
         item.Web.AllowUnsafeUpdates = true;
         item.Delete();
         item.Web.AllowUnsafeUpdates = allow;
     }
 }
Ejemplo n.º 15
0
        public void Remove(string key, string contextId)
        {
            SPListItemCollection items = QueryListItems(key, contextId);

            if (items.Count > 0)
            {
                SPListItem item = items[0];
                item.Delete();
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Deletes the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        public virtual void Delete(int id)
        {
            SPListItem spListItem = ParentList.GetItemById(id);

            ParentList.ParentWeb.AllowUnsafeUpdates = true;

            spListItem.Delete();
            ParentList.Update();

            ParentList.ParentWeb.AllowUnsafeUpdates = false;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// The Delete method will delete a SPListItem in the specified list.
        /// </summary>
        /// <param name="web">The SPWeb of the SPList</param>
        /// <param name="listName">The name of the SPList</param>
        /// <param name="listItemId">The Id of the list item to update</param>
        public void Delete(SPWeb web, string listName, int listItemId)
        {
            SPListItem           item       = null;
            SPListItemCollection collection = null;

            collection = web.Lists[listName].GetItems(BuildQuery(listItemId));

            if (collection != null && collection.Count > 0)
            {
                item = collection[0];

                item.Delete();
            }
        }
 internal void DeleteTemplateByID(string templateID)
 {
     try
     {
         SPListItem item = this.mailTemplateList.GetItemById(Convert.ToInt32(templateID));
         if (item != null)
         {
             item.ParentList.ParentWeb.AllowUnsafeUpdates = true;
             item.Delete();
             item.ParentList.ParentWeb.AllowUnsafeUpdates = false;
         }
     }
     catch { //Errror occured while deleting template
     }
 }
 /// <summary>
 /// delete a sharepoint item
 /// </summary>
 /// <param name="item">the item to delete</param>
 public void DeleteItem(SPListItem item)
 {
     if (item == null)
     {
         return;
     }
     try
     {
         item.Delete();
     }
     catch (Exception ex)
     {
         var log = new AppEventLog(AppException.ExceptionMessage(ex, "DeleteItem", "ClsHelper"));
         log.WriteToLog();
     }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Delete list item by id
        /// </summary>
        /// <param name="web"></param>
        /// <param name="listName"></param>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public bool DeleteListItemById(SPWeb web, string listName, int itemId)
        {
            bool   isDelete = false;;
            SPList lst      = web.Lists[listName];

            if (lst != null)
            {
                SPListItem item = lst.GetItemById(itemId);
                if (item != null)
                {
                    item.Delete();
                    isDelete = true;
                }
            }
            return(isDelete);
        }
Ejemplo n.º 21
0
 public void DeleteRow(string ItemId)
 {
     using (SPSite site = new SPSite(SPContext.Current.Web.Url))
     {
         using (SPWeb web = site.OpenWeb())
         {
             SPList     list = web.Lists.TryGetList("Customers");
             SPListItem item = null;
             item = list.GetItemById(int.Parse(ItemId));
             web.AllowUnsafeUpdates = true;
             item.Delete();
             list.Update();
             web.AllowUnsafeUpdates = false;
         }
     }
 }
Ejemplo n.º 22
0
        public bool DeletaItem(string NomeLista, int id)
        {
            try
            {
                SPListItem objItem = SPContext.Current.Web.Lists[NomeLista].GetItemById(id);
                objItem.Web.AllowUnsafeUpdates = true;
                objItem.Delete();
                objItem.Update();

                return(true);
            }
            catch (Exception ex)
            {
                Erro = ex.Message;
                return(false);
            }
        }
Ejemplo n.º 23
0
        protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                SPWeb web = SPContext.Current.Web;
                web.Site.CatchAccessDeniedException = false;
                string id = e.CommandArgument.ToString();

                SPList     list = web.Lists["EPMLivePeriods"];
                SPListItem li   = list.Items[new Guid(id)];

                deleteWebPeriod(web, li.Title, web.Url);

                li.Delete();

                loadPeriods(web);
            }
        }
Ejemplo n.º 24
0
        public virtual void Delete(SPListItem item)
        {
            Debug.Assert(item != null);
            var listName = item.ParentList.Title;
            var webUrl   = item.Web.Url;

            try
            {
                item.Web.AllowUnsafeUpdates = true;
                item.Delete();
            }
            catch (Exception ex)
            {
                var message = $"Ошибка при удалении элемента списка {item.ParentList.Title} узла {item.Web.Url} с ID={item.ID}";
                InvalidOperationException exception = new InvalidOperationException(message, ex);
                throw exception;
            }
        }
 public void DeleteRow(string ItemId)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate
     {
         using (SPSite site = new SPSite(SPContext.Current.Web.Url))
         {
             using (SPWeb web = site.OpenWeb())
             {
                 SPList list            = web.Lists.TryGetList("ScheduleInterview");
                 SPListItem item        = list.GetItemById(int.Parse(ItemId));
                 web.AllowUnsafeUpdates = true;
                 item.Delete();
                 //list.Update();
                 web.AllowUnsafeUpdates = false;
             }
         }
     });
 }
Ejemplo n.º 26
0
        public override void ItemDeleting(SPItemEventProperties properties)
        {
            base.ItemDeleting(properties);

            SPUser loginUser = properties.Web.CurrentUser;
            string loginInfo = loginUser.ID + ";#" + loginUser.Name;
            SPList lstNews   = properties.List;//
            bool   hasRight  = UserHaveApproveRight(properties.SiteId, properties.Web.Name, properties.List.Title, loginUser);
            string modeState = properties.ListItem["审批状态"].ToString();

            if (modeState == "0" && !hasRight)//审批通过
            {
                properties.Status = SPEventReceiverStatus.CancelNoError;
            }
            else if (properties.Status == SPEventReceiverStatus.Continue)
            {
                if (properties.List.Fields.ContainsField("新闻ID"))
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite mySite = new SPSite(properties.Site.ID))
                        {
                            using (SPWeb spWeb = mySite.RootWeb)
                            {
                                SPList listNews = spWeb.Lists.TryGetList("新闻");
                                if (listNews != null)
                                {
                                    SPListItemCollection itemsNews = listNews.Items;
                                    int Newsid          = int.Parse(properties.ListItem["新闻ID"].ToString());
                                    SPListItem itemNews = itemsNews.GetItemById(Newsid); //查找指定同步标记ID的这条新闻
                                    if (itemNews != null)                                //该条新闻存在
                                    {
                                        itemNews.Delete();
                                        listNews.Update();
                                    }
                                }
                            }
                        }
                    });
                }
            }
        }
        public Boolean DeleteItemPermanentlyByID(String strListName, Int32 ItemId)
        {
            Boolean    isSucess      = false;
            SPListItem objSPListItem = null;

            try
            {
                objSPListItem = GetListItemByID(strListName, ItemId);
                if (objSPListItem != null)
                {
                    objSPListItem.Delete();
                    isSucess = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(isSucess);
        }
        public Boolean DeleteItemByTitle(String strListName, String strTitle)
        {
            String     strqueryXml   = String.Empty;
            Boolean    IsSucess      = false;
            SPListItem objSPListItem = null;

            try
            {
                strqueryXml = @"<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + strTitle + "</Value></Eq></Where>";
                GetListItem(strListName, strqueryXml, out objSPListItem, this.CurrentWeb);
                if (objSPListItem != null)
                {
                    objSPListItem.Delete();
                }
            }
            catch (Exception Ex)
            {
            }
            return(IsSucess);
        }
Ejemplo n.º 29
0
 public void BorrarDocumentos()
 {
     string[] archivos = Directory.GetFiles(_path, "*.docx", SearchOption.AllDirectories);
     using (SPSite site = new SPSite(this._url))
     {
         using (SPWeb Web = site.OpenWeb())
         {
             foreach (string archivo in archivos)
             {
                 string consulta    = archivo.Split('\\').Last().Split('.').First();
                 string urlConsulta = string.Concat(_url, "/", consulta, ".docx");
                 SPFile file        = Web.GetFile(urlConsulta);
                 if (file.Exists && file.InDocumentLibrary)
                 {
                     SPListItem listItem = file.Item;
                     listItem.Delete();
                 }
             }
         }
     }
 }
        private SPWeb RecordWebForDelete()
        {
            SPWeb  web  = RecorderManager.CreateMockedObject <SPWeb>();
            SPList list = RecorderManager.CreateMockedObject <SPList>();
            SPListItemCollection itemCollection = RecorderManager.CreateMockedObject <SPListItemCollection>();
            SPListItem           item           = RecorderManager.CreateMockedObject <SPListItem>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(web.Lists["Registrations"], list).RepeatAlways();
                recorder.ExpectAndReturn(list.GetItems(new SPQuery()), itemCollection).RepeatAlways();
                recorder.ExpectAndReturn(itemCollection.Count, 1);
                recorder.ExpectAndReturn(itemCollection[0], item);
                //recorder.ExpectAndReturn(web.AllowUnsafeUpdates, false);
                //web.AllowUnsafeUpdates = true;
                item.Delete();
                //web.AllowUnsafeUpdates = false;
            }

            return(web);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Сохранить данные
        /// </summary>
        /// <param name="listItem">Элемент списка</param>
        /// <param name="saveMode">Режим сохранения</param>
        /// <param name="reloadMode">Нужно ли перечитать данные списка после сохранения</param>
        /// <returns></returns>
        public bool Save(SPListItem listItem, ItemRecordSaveMode saveMode, ItemRecordReloadMode reloadMode)
        {
            bool result = false;
            try
            {
                result = SaveData(listItem);
                if (!result)
                {
                    return false;
                }

                if (saveMode == ItemRecordSaveMode.Simple)
                {
                    listItem.Update();
                }
                else
                {
                    listItem.SystemUpdate();
                }

                IsNew = false;
                result = true;
                Reload(listItem, reloadMode);
            }
            catch
            {
                if (IsNew)
                {
                    listItem.Delete();
                }
                throw;
            }
            return result;
        }