Showing posts with label SSOM. Show all posts
Showing posts with label SSOM. Show all posts

Monday, 19 January 2026

Delete All item from sharepoint list using console application

Delete All item from  sharepoint on premise list using console application



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace DeleteAllitem
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://win-0c3p6kepvck:100/kkk/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["Department"];
                    int intcount = list.ItemCount;
                    for (int i = 0; i < intcount; i++)
                    {
                        list.Items.Delete(i);
                        Console.WriteLine("item deleted"+i.ToString());
                    }
                }
            }
        }
    }
}







How to Add Users to a group



Console.WriteLine("Enter a ; delimited list of domain\alias that need to be added:");
            string sAliases = Console.ReadLine(); //captures whatever the user entered
     
            string sAllContacts = "";

            using (SPSite site = new SPSite("http://win-0c3p6kepvck:100/kkk/"))
            {
                site.AllowUnsafeUpdates = true;
                using (SPWeb web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;
                    string[] aAliases = sAliases.Split(';');
                    foreach (string sAlias in aAliases)
                    {
                        SPUser user = web.EnsureUser(sAlias);

                        sAllContacts += user.ID.ToString() + ";#" + user.LoginName.ToString() + ";#";
                        if (sAllContacts.EndsWith(";#"))
                        {
                            sAllContacts = sAllContacts.Substring(0, sAllContacts.Length - 2);
                        }
                        SPList list = web.Lists["DemoList"];
                        SPListItem li = list.Items.Add();
                        li["Title"] = "jhjh";
                        li["parent"] = sAllContacts;
                        li["dname"] = sAllContacts;
                        li.Update();
                        Console.WriteLine("Done");
                    }
                    web.Update();

                }
            }