InfoPath Button: Create a New Site
This applies to SharePoint 2007, SharePoint 2010, and Office 365
In InfoPath, there’s a way to create a button that will create a new SharePoint site. First I’ll go through the steps on how to do it, and then the WHY, and how it could be useful.
- Open a new form in design mode.
- In the Fields pane on the right side of the form, create the following 4 fields:
- Title – text field
- Template – text field
- LCID – whole number – set the default value to 0
- Zone – text field
- Click to create a new data connection to submit data to a web service.
- For the URL to the web service, put the URL to your site, the site where you want to be able to click to create sub-sites, and make it look like this:
- For the operation, choose Create Workspace and click Next
- On the next screen, you have to map each of the listed parameters to the matching field that you already created.
Basically, click the little tree-looking box over to the right of “field or group” to pick the matching field.
- For the Title and templateName parameters, please check the box to “Submit data as a string”
- Finish out the wizard, all the defaults are fine.
Okay, so what does this do? It submits whatever’s in those 4 fields to create a new site. The person clicking the button does need to have access to be able to create sites.
Before we make it pretty, let’s test it. Drag the Title and the Template fields onto the surface of the form, so that we can enter text into them. Just make sure that LCID has a default value of zero, and zone isn’t important (not that I can tell anyway). So you can leave those last 2 fields alone.
Pretty generic form, I know. And where did all my instruction numbering go?… oh well.
In order to test the site creation, let’s stick a button on there. The button will have one action, to submit to that data connection that you just created.
I’m so excited, it’s almost time to push the button and watch magic happen. Go ahead and preview the form, or publish it and try it, it doesn’t matter, it will work either way. Fill out the fields like this:
No, you don’t have to call yours that, you can make the title whatever you want, but be sure and put that template value exactly the same, as STS#2. Hit the button! If you’re in preview mode, you’ll get the pop-up question about connecting to a data source and you can click Yes.
Now, go to your site, the one you entered in at step 4, and View All Site Content. There’s the test site, as a document workspace.
See, even though the web service is called “meetings”, it’s a little misleading because we can create any kind of site with the web service. We just need to know all those little codes for the different templates.
Next, back in design mode, let’s make it a little more user friendly. Right click on the template text box, and change the control to a drop-down list box. Add one manual choice to your list, setting the value as STS#2 and the display as “Document Workspace” like this:
All that is really needed now is the names of all the other templates that you want people to be able to pick from here. Here’s where Jeremy Thake wrote a list of them all. So, you could just manually enter them all in as drop-down choices. That way, people picking the template won’t have to know those codes.
Alright so that’s it, that’s the nitty gritty behind how to do it. But WHY do it?
This solution isn’t the prettiest, and it doesn’t seem like it would be necessary to fill out a form when you could just go to the site and create the sub-site from there, right?
Use this concept for a site provisioning solution. High level overview: Create this as a simple SharePoint form library or even just a list if you’re on 2010 enterprise. Set it up so that users fill out the form when they want to request a new site, just with all the basics, and this form will have to go through an APPROVAL before it gets to the person who will actually be clicking the button that submits to the web service. Once it’s gotten to the approval stage where it’s time to create the site, then the button will be available to click to create the site. The whole approval process could be done a slew of different ways, and the button could be on a certain view just for admins, or a certain hidden section, or it could just have a rule on it that says if approved = yes then it submits to that data connection.
You can learn more about approval processes in many of my other blog posts and videos, and at SPTechCon next week.
Also, big announcement…
Hi Laura, Very cool things indeed 😉 But how to add users and allow access to the new site to those users? Any idea? Kind regards Pascal P
Great article, Laura. Is there a way we could apply this to create site collections?
Hi Laura, Why not use the sites.asmx, as this gives you additional parameters? Regards,
Hi Laura, Great Post! It helped because this is exactly what I wanted to do as a site provisionning solution. I used the sites.asmx instead of the meetings.asms web services. The only thing I haven’t been able to do is to get it to create a site collections instead of a sub site? Any ideas? Thanks again!
Can you get this to work with a Site Template — Not Site Definition – without an error in InfoPath? I’ve tried both meetings.asmx and sites.asmx, and I can get a site provisioned (Note – sites.asmx seems to work much quicker), but I get an error in InfoPath that is not very descript…”the request either timed out or the certificate is not valid”. The site is provisioned correctly, but the error 1) doesn’t let me extend the workflow how I want 2) would require a lot of unnecessary calls to a help desk. I don’t get the error when I’m trying to use a site definition, but that is not practical – we need to be able to reuse “Bob and Jane’s” site templates they created and don’t have bandwidth to create site definitions for all of the templates that pop-up across the organization.
Thanks for the feedback guys! Yes, sites.asmx is a great idea! No, I don’t think there’s a web service method to create a site collection. Vinnie, You’d have to upload your custom site templates on the server using a stsadm command, then you’d be able to use those with this method. Otherwise, just any templates people create on sites won’t be available.
I’ve created a custom template based on the blank site to use with projects sites…
– how can I find/call this template ID ?
You’d have to add that template at the server level. The only way I know is an stsadm command -addtemplate or something like that. There’s probably a new powershell way. It’s not going to have a template ID unless it’s been added at that level (I don’t think).
If i selected few users on this form in text box or people picker, then how can i add these group of users in the “contributors group” of the newly created document Workspace !
Thanks a lot !
I has 1 difficulty. If user who opened the form has “contribute permission”…then how can he create the new site from the button.
How do I get the sites.asmx to work? I can’t seem to get it to connect.
I don’t know, you could try looking into other web services, I think that there are some called permissions.asmx and peoplegroups.asmx.
Also, yes the person creating the site will need to have rights for site creation. Try following my suggestion under the section called “site provisioning” for ideas around that.