SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In one interview, interviewer asked this question. I have one table in sql server database which contains the Title and its id(int). Now I want to retrieve those values from database and based on the title, I have to create sites under one root website. How many values are there, that many sites needs to be create.

    Title                    ID  
    A                        1
    B                        2
    C                        3

These are the values. Now I want to creata these three sites at a time. How to achieve it and if I change title of the site then it should update in the database as well. Any suggestions please

share|improve this question

This should not be hard, here is pseudocode:

Connect to this database and retrieve all the rows in this table
Connect to the desired SharePoint Site Collection (SPSite)

Foreach row in rows
       Add a web site under SPSite.RootWeb.Webs using Add method

For more details check SPSite, SPWeb, SPWebCollection objects and SPWebCollection.Add methods.

share|improve this answer
What about the update method. When we update the title of a site it should reflect in the database – Mihir Aug 11 '12 at 9:12
Unfortunately SharePoint only has event handler that fires when an SPWeb object is created, there is no onupdate event.…. You would have to build some scheduled check that iterates SPSite.AllWebs collection and checks if changes were made. – Toni Frankola Aug 11 '12 at 9:36
  1. One other alternative would be to create a BDC Entity out of your Table with SharePoint Designer, then from the newly External List have a new Workflow again via SharePoint Designer to start on item Creation and create a site automatically based on details. On update (ONLY via SharePoint list), use "Wait for a field change" activity you could update respective site. Both Create/Update site would rely on a custom Workflow Activity which is the only piece of code the would create/update site.
  2. Or directly from within your SQL Server (particularly if you have a single-server farm) rely on SQL Triggers to call .NET Managed procedures which could use SharePoint Client Side Managed Code to create/update sites. - more complex honestly (security wise particularly).
share|improve this answer
I am not sure item 1. is an option. SharePoint workflows can't be triggered by External Lists. They can, once running from someplace else, read/write to external lists. Ref: "Workflows cannot be associated with an external list. In SharePoint Server 2010, although workflows work with external lists, they cannot be associated directly with external lists. You can create a site workflow, or have a list workflow on a SharePoint list, such as a document library, and have it read or update from an external list." – lwbecker2 Aug 13 '12 at 15:41
1. Indeed you cannot direclty but ingenious alternatives allow to bridge that gap (more here…) – Marius Constantinescu - MVP Aug 13 '12 at 20:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.