Lets Learn

Opinion Matters

Archive for the ‘SharePoint 2010’ Category

Purging/Deleting a Huge/Large SharePoint List

Posted by Ankush on May 28, 2011

Recently I worked on a case where customer was trying to delete a huge list (it could be a simple list or workflow history list) and was looking for a custom solution to do it.

In case if it is a workflow history list then you can create a new list and set this as a history list and then you can try to delete the list items.

I started working on this and found a very good sample is already available on the web:

http://code.msdn.microsoft.com/CleanWorkflowHistory

But if you look at the code, it gets the ListItem and then it reads the List Item id so that it can create a batch processing to delete the item.

Everything is fine but still the process was slow…I reserached on this and suggested few points which I wanted to highlight here:

1. When you delete the List Items from List, it goes to first recycle bin and then it goes to the second one. So you may want to turn this off when deleting the items. Sometimes it is not practle to delete the items..so think about the overhead.. ..delete the item from a list, then 1st recycle bin and then 2nd recycle bin.

2. Delete Items in batch. instead of deleting them as a big list, delete them in chunk. (for ex: start with 2000 items)

3. This is something not recommended but can be tried in one-off case. Basically you can read List Item ID from the database instead of reading it using Object Model.

=========

============
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Data.SqlClient;

namespace PurgeList
{
class Program
{
private static int iteration = 5;
private static int Count = 2000;

static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine(“first argument: No of iteration”);
Console.WriteLine(“YourprgramName.exe 5”);
Console.WriteLine(“******Program terminated : Argument missing! Please give one argument ****”);

}
else
{
try
{
iteration = Convert.ToInt32(args[0]);

}
catch (Exception ex)
{
Console.WriteLine(“Error : Failed to convert arguments: {0}”, ex.Message);

return; // exit
}
Console.WriteLine(“Current System Time (Start) : ” + DateTime.Now.ToString());
try
{

for (int iterate = 0; iterate < iteration; iterate++)
{
int start = GetMinID();
Console.WriteLine(“Start Index: ” + start.ToString());
using (SPSite site = new SPSite(“http://anksps2010“))
{
using (SPWeb web = site.OpenWeb())
{
SPList wflist = web.Lists[“Workflow History”]; //workflow history
string wflistID = wflist.ID.ToString();

Console.WriteLine(“No of items before deletion: ” + wflist.ItemCount);

Console.WriteLine(“Building query… “);
StringBuilder batchString = new StringBuilder();
batchString.Append(“xml version=\”1.0\” encoding=\”UTF-8\”?>”);
int end = start + Count – 1;
for (int i = start; i <= end; i++)
{
batchString.Append(“<Method>”);
batchString.Append(“<SetList Scope=\”Request\”>” + wflistID + “”);
batchString.Append(“<SetVar Name=\”ID\”>” + Convert.ToString(i) + “”);
batchString.Append(“<SetVar Name=\”Cmd\”>Delete”);
batchString.Append(“</Method>”);

}

batchString.Append(“</Batch>”);

//Console.WriteLine(batchString.ToString());

try
{
web.AllowUnsafeUpdates = true;
Console.WriteLine(“Executing query… “);
Console.WriteLine(“Batch Execution (Start) : ” + DateTime.Now.ToString());
string result = web.ProcessBatchData(batchString.ToString());
//Console.WriteLine(result);
web.AllowUnsafeUpdates = false;

Console.WriteLine(“Batch Execution (END) : ” + DateTime.Now.ToString());

}
catch (Exception ex)
{
Console.WriteLine(“Process batch error : ” + ex.Message);

}
Console.WriteLine(“No of items before deletion: ” + wflist.ItemCount);
using (SPSite site1 = new SPSite(“http://anksps2010“))
{
using (SPWeb web1 = site1.OpenWeb())
{
Console.WriteLine(“No of item after deletion: ” + web1.Lists[“Workflow History”].ItemCount);
}
}

Console.WriteLine(“————————————————–“);

}
}
}
Console.WriteLine(“Current System Time (End) : ” + DateTime.Now.ToString());
Console.WriteLine(“———–Program Completed————“);
}
catch (Exception ex)
{
Console.WriteLine(“Error : ” + ex.Message);
Console.WriteLine(“******Program terminated due to error **** “);

}
}

}

public static int GetMinID()
{

try
{
string connString = @”Data Source=.\SHAREPOINT;Initial Catalog=WSS_Content_c20feb22657e4e2ab82f7db433f3e4c7;Integrated Security=SSPI”;

using (SqlConnection objConn = new SqlConnection(connString))
{
objConn.Open();

string sqlString = “Select min(tp_ID) as col1 from dbo.alluserdata where tp_listid = ‘6463BECE-3560-4D15-B965-B245F3203BEE'”;// workflow list id

SqlCommand cmd = new SqlCommand(sqlString, objConn);
int id = Convert.ToInt32(cmd.ExecuteScalar());
return id;

}
}
catch (Exception ex)
{
Console.WriteLine(“SQL ERROR: ” + ex.Message);
throw ex;

}
}

}
}

==================================

Try this and let me know how it goes!!!!!

Update # 1:

While working on the sample available here (http://code.msdn.microsoft.com/CleanWorkflowHistory), I hit a bug (or should I say a couple of bugs).

Bug # 1:PurgeSiteRecycleBin function again picks the item from the 1st stage (end-user) recycle bin. You need to specify ItemState to get the items from the second stage recycle bin. So currently, It deletes the item twice from the 1st stage recycle bin.

bug # 2: There is no need of PurgeSiteRecycleBin function at all. Basically, when you delete the item using batch processing, it goes into 1st stage re-cycle bin. But when you delete the item from re-cycle bin, it updates the content database so it will land in 2nd stage re-cycle bin. So unless, you want to empty the 2nd stage recycle bin,you can safely remove the code.

 

Advertisements

Posted in SharePoint 2010, Sp 2007 | Tagged: , , , , | Leave a Comment »

SharePoint 2010 Learning Resources

Posted by Ankush on January 20, 2011

Change always brings something new. As I have moved (ore moving) from desktop dev to web developer; I am compiling a list of resources which is helping me a lot.
For all the developers, here is the SharePoint 2010 learning resources:
I. Getting Started Screencast Series
A series of entry-level screencasts by Microsoft SharePoint MVPs that lets you take advantage of an 11-module e-learning course at no cost! The course covers everything you should know as a new SharePoint IT Pro, from basic features and terminology to how to build and maintain a server farm and manage performance.

II.
SharePoint 2010 Advanced IT Professional Training
For IT professionals, SharePoint 2010 offers enhancements to drive productivity, a scalable unified infrastructure, and flexible deployment. SharePoint 2010 Advanced IT Professional Training is a deep technical learning series for current SharePoint professionals who are
looking to upgrade their skills to SharePoint 2010.
1.    Core Architecture of SharePoint 2010
http://technet.microsoft.com/sharepoint/ff677987.aspx
2.    Security in SharePoint 2010
http://technet.microsoft.com/sharepoint/ff677987.aspx
3.    IT Pro Management in SharePoint 2010
http://technet.microsoft.com/sharepoint/ff678027.aspx
4.    Upgrading to SharePoint 2010
http://technet.microsoft.com/sharepoint/ff678049.aspx
5.    Enterprise Search in SharePoint 2010
http://technet.microsoft.com/sharepoint/ff678049.aspx
6.    Content Management in SharePoint 2010
http://technet.microsoft.com/sharepoint/ff678049.aspx
7.    Composite Solutions in SharePoint 2010
http://technet.microsoft.com/sharepoint/ff678052.aspx
8.    Communities in SharePoint 2010
http://technet.microsoft.com/sharepoint/ff678053.aspx
9.    Business Intelligence in SharePoint 2010
http://technet.microsoft.com/sharepoint/ff678054.aspx
III. Enterprise Search IT Professional Training

This course is designed to teach the basics of enterprise search, how search management fits within their organizations and how to get the most out of Microsoft SharePoint Server 2010 search and Microsoft FAST Search Server 2010 for SharePoint.
2.    Windows PowerShell for Search
http://technet.microsoft.com/enterprisesearch/ff961002.aspx
3.    Deployment and Scalability for SharePoint 2010
http://technet.microsoft.com/enterprisesearch/ff961003.aspx
4. Monitoring and System Management for SharePoint 2010
http://technet.microsoft.com/enterprisesearch/ff961004.aspx
5. Search Reporting and Analytics for SharePoint 2010
http://technet.microsoft.com/enterprisesearch/ff961005.aspx
6. Connectors and Using the Business Data Connectivity Services in SharePoint 2010
http://technet.microsoft.com/enterprisesearch/ff961006.aspx
7.  Configuring User Interfaces for Search in SharePoint 2010 and FAST Search Server 2010 for SharePoint
http://technet.microsoft.com/enterprisesearch/ff961007.aspx
9.Advanced Search Security for SharePoint 2010 and FAST Search Server 2010 for SharePoint
http://technet.microsoft.com/enterprisesearch/ff961009.aspx
10.People Search Administration and Management for SharePoint 2010 and FAST Search Server 2010 for SharePoint
http://technet.microsoft.com/enterprisesearch/ff961010.aspx
11. Advanced Deployment and Scalability for SharePoint 2010
http://technet.microsoft.com/enterprisesearch/ff961011.aspx
12. Upgrading from SharePoint 2010 to FAST Search Server 2010 for SharePoint
http://technet.microsoft.com/enterprisesearch/ff961012.aspx
13. Deployment and Scalability for FAST Search 2010 for SharePoint
http://technet.microsoft.com/enterprisesearch/gg213844.aspx
14. Advanced Deployment and Scalability for FAST Search 2010 for SharePoint
http://technet.microsoft.com/enterprisesearch/ff961014.aspx
15. Linguistics for FAST Search Server 2010 for SharePoint
http://technet.microsoft.com/enterprisesearch/ff961015.aspx
16. Relevancy and Ranking for FAST Search Server 2010 for SharePoint
http://technet.microsoft.com/en-us/enterprisesearch/ff961016.aspx
IV. SharePoint Silverlight Snacks
o     Experiencing the Microsoft SharePoint 2010 User Interface
http://www.microsoft.com/learning/_silverlight/learningsnacks/SP10/snack01/Default.html
o     Managing and Troubleshooting with Microsoft SharePoint Server 2010
http://www.microsoft.com/learning/_silverlight/learningsnacks/SP10/snack02/Default.html
o     Developing Solutions with Microsoft SharePoint 2010
http://www.microsoft.com/learning/_silverlight/learningsnacks/SP10/snack03/Default.html
V. SharePoint Server 2010 Resource Centers
Basics
o    Governance
o    Updates
o    What’s new
Capabilities
o    Workflows
IV.       SharePoint TechNet Virtual Labs
In these full-featured TechNet Virtual Labs you connect remotely to a SharePoint Server virtual mahine for a hands-on lab.  You get a downloadable manual and a 90-minute block of time for each module. You can sign up for additional 90-minute blocks any time.
I hope these resources will help you a lot!! In case of any feedback, let me know!!!

Posted in SharePoint 2010 | 4 Comments »

 
%d bloggers like this: