SPMetal Error: Web cannot be found when URL has spaces or %20

Posted: 28th June 2011 in LINQ 2 Sharepoint, Powershell, Sharepoint 2010

Today, while trying generate a model, using SPMetal, I found out that SPMetal does  not like spaces in the web URL. After trying the URL in quotes with the space and again with %20 in the string for the URL encoding seen below. Neither of them were able to find the application. 

SPMetal /web: ”http://sharepoint/services/Rota Management” /namespace: etc
SPMetal /web: ”http://sharepoint/services/Rota%20Management” /namespace: etc

Resulting in the following errors respectively

Error: Web at http://sharepoint/services/Rota Management could not be found.
Error: Web at http://sharepoint/services/Rota0Management could not be found.

So in order to get the model definition I used the following PowerShell command.

Start-SPAssignment –Global
$web = Get-SPWeb "http://sharepoint/services/Rota Management"
$web.ServerRelativeUrl = "/services/RotaManagement"
$web.Update()
Stop-SPAssignment –Global

Then, I ran the SPMetal command again and it worked no problem.

After generating the class just reversed the above to restore the URL

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s