Archive

Author Archive

Delete SharePoint Application Pools

August 21st, 2011 No comments

Even though you deleted an application pool in IIS, sometimes SharePoint doesn’t seem to care. I recently had some trouble setting up the user profile service, and needed to delete the UPS because of some misconfiguration. When I wanted to recreate the application pool I got an error, stating the application already exists.

app_pool_1

But what when I can’t see this app-pool in IIS? Well PowerShell to the rescue:

Remove-SPServiceApplicationPool [AppPoolName]

This is almost to easy to be true.

BTW: when deleting the UPS (the service application), the application pool does not get deleted in IIS. This is extremely ugly, especially since the app-pool name is just some guid. When re-creating the service-application using the same settings as before (especially the same app pool name), this fails, because the name of the app-pool and the corresponding guid name for IIS seems to be stored in the configuration database.

Categories: SharePoint Tags:

Creating new sites in a batch

August 18th, 2011 No comments

During SharePoint development you just need a whole bunch of sites. Creating them just for test purpose using the central administrations seems to be to much hassle. Instead I created a little batch-file to take care of spinning up a new test-site.

Basically you just have to edit the variables at the beginning of the script. Just specify the port, the site name, title and description. The name is used to create the web-application, application pool, the database and the stuff.

When creating the new site-collection for the web-application I did not provide a template; this way I can choose a template at the first call to the newly create site.

@echo off
setlocal
pushd .
    set SPLocation=%CommonProgramW6432%\Microsoft Shared\web server extensions\12
    set SPAdminTool=%SPLocation%\BIN\stsadm.exe
    set sitePort=6001
    set siteName=SampleSite
    set siteDescription=Demo a SharePoint Web-Application
    set siteTitle=Web-App Demo
echo Creating WebApplication '%siteName%' at port '%sitePort%'
"%SPAdminTool%" -o extendvs -url http://localhost:%sitePort% -owneremail me@acme.local -ownerlogin acme\me -ownername "Acme Big Boss" -databasename WSS_Content_%siteName%_%sitePort% -description "%siteDescription%" -apcreatenew -apidname "WSS_AppPool_%siteName%_%sitePort%" -apidtype NetworkService -donotcreatesite
echo Creating WebSite '%siteTitle%'
"%SPAdminTool%" -o createsite -url http://localhost:%sitePort%/ -owneremail me@acme.local -ownerlogin acme\me -ownername "Acme Big Boss" -lcid 1031 -description "%siteDescription%" -title "%siteTitle%"
popd
endlocal
Categories: SharePoint Tags:

SharePoint 2010 version numbers

August 18th, 2011 No comments

I already created a list of version numbers for SharePoint 2007 (which seems to be a little outdated as it seems).

Well, so now I give that a new try for SharePoint 2010:

Update Name Version number
RTM (all components) 14.0.4763.1000
RTM (farm build version) 14.0.4762.1000
June 2010 CU 14.0.5114.5003
August 2010 CU 14.0.5123.5000
October 2010 CU 14.0.5128.5000
December 2010 CU 14.0.5130.5002
February 2011 CU 14.0.5136.5002
April 2011 CU 14.0.5138.5000
Categories: SharePoint Tags:

SharePoint starts the Fire

August 13th, 2011 No comments

Dux Raymond premiered on BPC09 his song SharePoint is Nice Nice Baby. Last year he performed a new song at ShareFest 2010.

Categories: Fun, SharePoint Tags:

One Content-type, multiple templates

August 12th, 2011 No comments

Let’s assume I want to store different documents in a document-library in SharePoint, based on different templates. The easiest way would be to create different content-types for each kind of document. Each content-type can have an individual template in turn.

But what if I have just one logical content-type, but I have different document templates? I could create master content-type, which holds all properties. Then I create sub content-types and assign the different templates to those. This way I can maintain the properties on the master content-type and don’t have to worry about the sub content-types.

Problem solved!

But what I actually wanted was to have dedicated links to add new documents based on a certain template to my document library. I achieved this, but I needed to created three content-types in order to do so.

A different approach.

Instead of creating different content-types with different templates, I just create two hyperlinks “create document a” and “create document b”. With a couple of lines of javascript I’m ready to go.

First of I need a document library to store my templates. In the next step I add a content editor webpart to my listview. Because I cannot add javascript code to the content editor webpart directly, I placed my code in a separate file, which I also placed in the template document library (to keep thinks simple for now). So I reference this file in the content editor webpart.

This file basically contains some javascript to add new documents based on a certain template to the library:

function NewWord()
{
    var strTemplate = makeAbsUrl("/Template/WordTemplate.docx");
    var strSaveLocation = makeAbsUrl("/Shared Documents");
    var strProgId = "SharePoint.OpenDocuments";
    createNewDocumentWithProgID(strTemplate, strSaveLocation, strProgId, false);
    return false;
}
function NewExcel()
{
    var strTemplate = makeAbsUrl("/Template/ExcelTemplate.xlsx");
    var strSaveLocation = makeAbsUrl("/Shared Documents");
    var strProgId = "SharePoint.OpenDocuments";
    createNewDocumentWithProgID(strTemplate, strSaveLocation, strProgId, false);
    return false;
}

This with some little HTML …

<span style="width: 10px; height: 10px; overflow: hidden; display: inline-block; position: relative;">
    <img style="left: 0px !important; top: -128px !important; position: absolute;" src="/_layouts/images/fgimg.png" alt=""/>
</span>&#160;<a onclick="NewWord();" href="#">New Word-Document</a>&#160;|&#160;
<span style="width: 10px; height: 10px; overflow: hidden; display: inline-block; position: relative;">
    <img style="left: 0px !important; top: -128px !important; position: absolute;" src="/_layouts/images/fgimg.png" alt=""/>
</span>&#160;<a onclick="NewExcel();" href="#">New Excel-Document</a>

… could just do.

Mass-Updating Active Directory

May 3rd, 2011 No comments

I just love PowerShell! Although I’m not really mature in the syntax yet, I find myself moreoften doing little things in powershell.

Today I figured, that in my previous task of creating 150 sample accounts I missed out on the email-address. So I just wrote a simple line of powershell. First off, I went to the OU just by navigating to the AD-provider cd AD: and then change to cd OU=Test,DC=demo,DC=local. That’s already cool. Then just a simple line like

dir | foreach { $x = Get-AdUser $_; $y=$x.samAccountName; Set-Aduser -identity $x -emailaddress "$y@demo.local"; }

And since I’m on a roll, I also updated the passwords for all users

Get-ADUser -Filter 'Name -like "*"' -SearchBase "OU=Acme,DC=demo,DC=local" | Set-ADAccountPassword -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "demo" -Force)
Categories: Programming Tags:

Sample Domain Data

April 16th, 2011 No comments

Sometimes you just need to have a decent amount of sample data. Recently I created an active directory to do some development using SharePoint 2010. In order to have a realistic baseline I needed to have a decent amount of fictive users.

So instead of creating a ton of users like User1 to User150 I thought of something more elaborate. Why not create random user-accounts?

After some google-research I found a blogpost with a list of first- and lastnames as CSV-files. Fantastic! This looks like a promising starting point. To spice everything up a notch I also created list of departments and functions. So this will give me quite a batch of user-data.

To mix everything quite good, I created a little piece of powershell:

# Import list of Last names from Simple Text file
$lastname=import-csv '.\lastname.csv'
# Import list of First names Simple Text file
$firstname=import-csv '.\firstname.csv'
# Import list of roles, prefixes and departments
$roles=import-csv '.\role.csv'
$prefixs=import-csv '.\prefix.csv'
$departments=import-csv '.\department.csv'
# How many names to generate
$totalnames=150
# the Header for our new CSV file
$firstline='Firstname,Lastname,Position,Department,Phone'
# Create a file called “DomainUsers.csv”
Set-content -path 'DomainUsers.csv' -value $firstline
$firstnamecount=$firstname.Count
$lastnamecount=$lastname.Count
$rolecount=$roles.Count-1
$prefixcount=$prefixs.Count-1
$departmentcount=$departments.Count-1
# Go through and Generate some names
foreach ( $namecounter in 1..$totalnames )
{
    # Pick a random first and Last name
    $lastnamenumber=(get-random -min 0 -max ($lastnamecount-1))
    $firstnamenumber=(get-random -min 0 -max ($firstnamecount-1))
    $rolenumber=(get-random -min 0 -max ($rolecount))
    $prefixnumber=(get-random -min 0 -max ($prefixcount))
    $departmentnumber=(get-random -min 0 -max ($departmentcount))
    $FakeName=($firstname[$firstnamenumber].Firstname+','+$lastname[$lastnamenumber].Lastname)+','+
        ($prefixs[$prefixnumber].Prefix+' '+$departments[$departmentnumber].Department+' '+$roles[$rolenumber].Role).Trim()+','+
        $departments[$departmentnumber].Department+','+
        '555-'+(get-random -min 100 -max 999)+'-'+(get-random -min 1000 -max 9999)
    # Echo the New name to the Screen
    write-host $fakename
    # and write to the File
    add-content -path 'DomainUsers.csv' -value $fakename
}

I think the script doesn’t need any further explanation. The result will be a CSV-file with a bunch of random user account data.

The Import into active directory is done in a second powershell-script (just because I had that already).

param([string]$FileName, [string]$adpath)
Import-Module ActiveDirectory
function Import-Users([string]$UserFile)
{
    Import-Csv $UserFile | foreach-object {
        $accountName = $_.Lastname+$_.Firstname.Substring(0,2)
        $displayName=$_.Firstname+" "+$_.LastName
        New-AdUser $accountName -samAccountName $accountName -Company "Acme Corp." -Department $_.Department -DisplayName $displayName -GivenName $_.Firstname -Surname $_.Lastname -OfficePhone $_.Phone -Title $_.Position -CannotChangePassword $true -PasswordNeverExpires $true -Enabled $true -AccountPassword (ConvertTo-SecureString -AsPlainText "demo" -Force) -Path $spou
    }
}
$spou = "OU=Acme,$adpath"
Import-Users $FileName

This is rather boring. To start the script you have to supply the name of the CSV containing the user-data and you have to supply the path to your domain in the form of “dc=acme,dc=local”. This snipplet assumes that there is an OU called Acme, where all the user accounts should be placed.

These are the files I used to generate the sample accounts:

Categories: Programming Tags:

Full Screen Mode in VMWare

April 2nd, 2011 No comments

I just setup a new VM using a Windows 2008 R2 server to do some SharePoint 2010 development. To really get started I switched my VM to fill-screen-mode, in order to get more desk-space.

But that just gave me a blank, black screen. Resizing the window works perfectly fine, but not full-screen. Even manually triggering the “fit client” event didn’t do anything good.

The solution was trivial (as usual with this kind of errors): you have to enable 3D acceleration in the VM settings. What a bummer.

Categories: Programming Tags: ,

Visualize SharePoint using Visio

February 13th, 2011 No comments

To quickly visualize an architecture or a structure Visio might be the tool of choice. But to make such a diagram really appealing you have to have the right shapes.

To create diagrams for SharePoint there are a couple of free shapes available. I collected some of these shapes:

Logging from multiple processes

February 6th, 2011 No comments

When logging with log4net to a file (using the FileAppender), the FileAppender is holding an exclusive lock on the file. This doesn’t cause any problems, not even when the application is running with multiple threads, because log4net should be thread-safe.

This does change however when working with multiple processes, that all share a common log4net configuration and thus all will utilize the same FileAppender. In this case there should not be an exclusive lock by any process. Fortunately log4net has an appropriate configuration-setting.

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

But acquiring and release locks is quite costly and thus will slow down the overall performance of the application.

An alternative would be to create an individual log per processes. Luckily log4net supports the expansion of variables to generate log-filenames, so we can add the process-id to the filename-pattern.

<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
    <file type="log4net.Util.PatternString" value="Log[%processid]" />
[...]
</appender>
Categories: .Net Tags: