Pages

Search This Blog

Sunday, April 22, 2012

SharePoint List Bulk Delete

Hi Friends,

I came through some requirement where I need to delete number of rows on the basis of some condition. Here we have choice of iterating all the list items and match the required condition if matched delete that list record. This is fine when we say its meeting the requirement. But when we look into its performance its not really a good solution. So here we have another very efficient solution of using ProcessBatchData of SPWeb. This batch technique is 10 times faster than list.Delete(i) technique and it minimizes the round trips to DB. Please find a very simple implementation of this you can alter this as per your requirement.


private void button1_Click(object sender, EventArgs e)
        {
            String strSourceList = "Bulk Delete List";//textBox2.Text.Trim();
            String strSite = "http://abcSite:9000/sites/uk/";//textBox1.Text.Trim();
            String strIds = String.Empty;
            try
            {
                if (!String.IsNullOrEmpty(strSite))
                {
                    if (!String.IsNullOrEmpty(strSourceList))
                    {
                        try
                        {
                            SPSite sourceSite = null;
                            try
                            {
                                sourceSite = new SPSite(strSite);
                            }
                            catch { }

                            if (sourceSite != null)
                            {
                                SPWeb sourceWeb = sourceSite.RootWeb;
                                if (sourceWeb != null)
                                {
                                    sourceWeb.AllowUnsafeUpdates = true;

                                    SPList sourceList = sourceWeb.Lists[strSourceList];
                                    StringBuilder sbDelete = new StringBuilder();
                                    sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");

                                    if (sourceList != null)
                                    {
                                        string command = "<Method>" +
                                                         "<SetList Scope=\"Request\">" + sourceList.ID + "</SetList>" +
                                                         "<SetVar Name=\"ID\">{0}</SetVar>" +
                                                         "<SetVar Name=\"Cmd\">Delete</SetVar>" +
                                                         "</Method>";

                                        foreach (SPListItem objListItem in sourceList.Items)
                                        {
                                            sbDelete.Append(string.Format(command, objListItem.ID.ToString()));
                                        }
                                        sbDelete.Append("</Batch>");

                                        string retVal = sourceWeb.ProcessBatchData(sbDelete.ToString());

                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }

Thanks
Prabhat

Publish Content Type in Content Type hub SharePoint 2010

Sometimes we have a requirement where we need to create the content type in hub and publish the same via code. Following are the methods to Publish or Un-Publish the Content Type in Content Type HUB


 public static String PublishorUnPublishedContentType(SPSite hubSiteCollection, SPContentType cType, bool doPublish)
        {
            String sMessage = String.Empty;
            if (ContentTypePublisher.IsContentTypeSharingEnabled(hubSiteCollection))
            {
                ContentTypePublisher publisher = new ContentTypePublisher(hubSiteCollection);
                try
                {
                    if (doPublish)
                    {
                        publisher.Publish(cType);
                        sMessage = "Content Type Published Successfully.";
                    }
                    else
                    {
                        if (publisher.IsPublished(cType))
                        {
                            publisher.Unpublish(cType);
                            sMessage = "Content Type UnPublished Successfully.";
                        }
                        else
                        {
                            sMessage = "Content Type is not published. You need to Publish the Content Type before UnPublished.";
                        }
                    }
                }
                catch (Exception ex)
                {
                    sMessage = ex.Message;
                }
            }
            else
            {
                // The provided site is not a valid hub site.
                sMessage = hubSiteCollection.Url + ": is not a valid Content Hub Site.";
            }
            return sMessage;
        }

Hope this will help you out !!!!!

Wednesday, April 18, 2012

Free Small Business Site Template for SharePoint 2010

Small Business Template is a SharePoint site definition that can be used as the starter point for publishing your business site on SharePoint 2010. This template provides you a basic set of 5 initial pages that you can increase or edit based on your organization's content. Publishing feature is a pre requisit for this template to work.

 http://code.google.com/p/free-sharepoint-small-business-website-template-theme/

Who benefits from using Small Business Site Template?

Using this template benefits all of the following:
End Users / Administrators – End Users can build their company portal within minutes and then customize the same according to their requirements from the UI itself.
SharePoint Application Developers – Application developers can customize the existing template easily and can update the package to undergo new implementation.

What features does Small Business Site Template offer?

This template provides the following functional features:
  • Rocket-Launch your Website in minutes !!!
  • Ready to use Company portal
  • Support for end to end customization according to own requirements.
  • Customizable Theme
  • Common site content (Header, Footer) customizable by administrator.
  • Easy enhancement support for developers.
  • Publishing as easy as 1-2-3 ! 

Tuesday, April 10, 2012

How to disable mobile views in SharePoint 2010?

It is as simple as adding a new configuration block in web.config of your application

<browserCaps>      <result type="System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>      <filter>isMobileDevice=false</filter>    </browserCaps>

Add this setting block anywhere between system.web node.