In working through my last post I managed to leave a remnant in Central Admin of a removed Host Named Site Collection that was stored in the default HNSC Content database. After many attempts to repair in a more acceptable way, (DB Repairs, removing/adding content db, etc) I finally realized that the issue wasn't in my HNSC content db, but rather a leftover reference in the SharePoint_Config DB. Taking a page from the book-of-things-you-should-never-do-in-SharePoint, I found the reference in the SiteMap table and had to manually delete that row. I backed up the database first in anticipation of impending doom, but it seems to have done the trick.
I'm going to poke around the internet a little more, hoping there's a better way to clean this up or even some timer job or other process that takes care of this in the future, but if you know of the better way, please post it.
Saturday, April 27, 2013
Deleted Site Collection continues to show up in Central Admin
Getting Started With Host Named Site Collections - PowerShell Script
Well, it's been a while, but I'm finally getting around to really digging deep into SP2013. As I go through this I figured I'd start putting together a few helper PowerShell Scripts:
Once you've got a SP2013 developer machine created you may want to stand up additional Host Named Site Collections (If you haven't created one yet, use the Critical Path Training guide at http://www.criticalpathtraining.com in the Members section). I've also included the ability to stand up a new ContentDB for your site collection.
Here's a relatively simple Powershell script to help you with this:
$snapin = Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SharePoint.Powershell" }
if($snapin -eq $null)
{
Write-Host "...loading Microsoft.SharePoint.PowerShell snapin" -ForegroundColor Gray
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
function CreateHNSC($name, $url, $template, $contentdatabasename)
{
$defaultWebApp = Get-SPWebApplication |
Where-Object { $_.IisSettings["Default"].ServerBindings[0].Port -eq 80 -and $_.IisSettings["Default"].ServerBindings[0].HostHeader -eq "" }
if($defaultWebApp){
$ownerAlias = [Environment]::UserDomainName + "\" + [Environment]::UserName
if($contentdatabasename)
{
Write-Host "Creating new content database '$contentdatabasename'"
New-SPContentDatabase -Name $contentdatabasename -WebApplication $defaultWebApp
Write-Host "Creating new Host Named Site Collection '$name' at $url (in '$contentdatabasename' content database)"
New-SPSite -Name $name -Url $url -HostHeaderWebApplication $defaultWebApp -Template $template -OwnerAlias $ownerAlias -ContentDatabase $contentdatabasename
}
else
{
Write-Host "Creating new Host Named Site Collection '$name' at $url (in default HNSC content database)"
New-SPSite -Name $name -Url $url -HostHeaderWebApplication $defaultWebApp -Template $template -OwnerAlias $ownerAlias
}
}
else{
Write-Host "default SP2013 web application was not found" -ForegroundColor Red
}
}
#call the function for each host named site colletion you want to create
#with new content db
CreateHNSC -name "Solutions Site" -url "http://solutions.mydomain.com" -template "DEV#0" -contentdatabasename "WSS_Content_Solutions"
#to default content db
#CreateHNSC -name "Solutions Site 2" -url "http://solutions2.mydomain.com" -template "DEV#0"
One thing to remember (and might be worth handling in this script in the future) is that if you're using this to set up HNSCs on a dev machine, you'll need to add the additional hosts to your hosts file or Visual Studio won't recognize your new host. This appears to be a known bug.
Wednesday, January 4, 2012
Using JQuery to Tweak Editform.aspx
For smaller changes to your Editform.aspx you may want to avoid doing a solution deployment that contains a custom content type feature with a custom EditForm.aspx. This is a quick workaround. It's pretty much the same as we used to to in MOSS with only minor changes to the way you get to the form.
I did this in IE, but it's probably similar in other browsers:
- Place an html document containing some JavaScript/Jquery into a document library on your list's site. (Try just putting this for initial testing: <script type="text/javascript">alert('hello world');</script>)
- Navigate to the list whose editform.aspx you want to change
- Right click on any item's link to it's display form and choose 'open in new tab'
- Go to the newly opened tab and click the 'Edit Item' button to open the item in the editform.aspx
- append &ToolPageView=2 to the url
- Add a Content Editor Web Part and point it to your document from step 1.