Note: This post applies to SharePoint Server 2010 Beta 2 and Visual Studio Ultimate Beta 2.
I ran into two issues today that had me tied up for a few hours so I thought I would share. The first was simple:
SPFarm _farm = SPFarm.Local; However, the _farm object was being returned as null.
The second was again simple:
SPSite _site = new SPSite(“http://teams”); This line errored with:
The Web Application at http://teams could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.
First, notice that by default, Visual Studio compiles in x86. Since SharePoint is running in x64, this would definitely be a good place to start.
However, there is no x64 platform to compile to by default
What we need to do is create an x64 platform and copy existing settings from x86. We’ll do this by entering the Configuration Manager. Once in the Configuration Manager, select the platform drop down and choose New.
Choose the new platform to be “x64” and choose to copy settings from x86.
After you click OK, ensure the settings on your projects are change to use the new platform “x64”
Close out of Configuration Manager and ensure you are now building in x64.
Lastly, try your project again. That should have solved it.
Note: you may also receive this error if you do not have permissions to the configuration database while developing a Windows Forms or WPF application. Ensure that the account you are developing on has appropriate permissions to the config database. If you are running a web client (web part, etc.), ensure that its app pool account has the same permissions to the read from the database.
Special thanks to Tajeshwar for his help in resolve this.
These HOLs are about a month old now, but I wanted to share them for anyone who missed the announcement at SPC. There are 10 Hands On Labs in both C# and Visual Basic for SharePoint 2010 Beta 2.
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=c010fc68-b47f-4db6-b8a8-ad4ba33a35c5
Also, I have set up several tags in Diigo for SharePoint , you can find my “SharePoint2010” bookmarks here:
http://www.diigo.com/user/erickraus/sharepoint2010
I update links to this site daily.
This post will take you down the process of configuring your SharePoint farm while introducing the new administrative functionality shipping in the PowerShell provider.
During the SharePoint Installation, make sure you choose “Server Farm” and then “Complete” install. This will allow you to create a SharePoint farm rather than a standalone server.
After the install completes, the setup program will ask you if you want to run the SharePoint Technologies Configuration Wizard (default is checked). Uncheck the box to NOT run the wizard.
Under the Start Menu, browse to Microsoft SharePoint 2010 Products. Right-click on SharePoint 2010 Management Shell and choose Run as administrator
Notice: Since we have not created a farm yet, the shell will load with an error that the local farm is not accessible. This is expected.
Next, run the following command to create a new configuration database and central admin content database. The main reason we are using this method, versus the GUI is because we can specify the central admin content database name. (In the GUI, you cannot specify the name and it is created with a GUID) <—DBA’s hate this
New-SPConfigurationDatabase –DatabaseName “SharePoint2010_Config” –DatabaseServer “<db server>” –AdministrationContentDatabaseName “SharePoint2010_Admin_Content” –Passphrase (ConvertTo-SecureString “pass@word1” –AsPlaintext –Force) –FarmCredentials (Get-Credential)
Notice: rather than hard coding the credential for the farm account, I am having PowerShell prompt me for it. You can also do this with the passphrase by accessing the “Password” property of the of the credential object: (Get-Credential).Password
After the process runs, you can test that the server has not been added to a farm, by reloading the PowerShell window. Close and repeat the “Run as administrator” step above. It should load with no warning message.
Next, we need to provision the central admin web application on our desired port. This will also link up the web application with the admin content database we created in the previous step.
New-SPCentralAdministration -Port 1234 -WindowsAuthProvider "NTLM"
After that command completes, we now need to install the features on the server.
Install-SPFeature –AllExistingFeatures
Lastly, we need to install and provision the services onto the farm.
Install-SPService -Provision
DONE! Now, you can open up Internet Explorer to the central admin site/port you specified and you’re on your way!
Windows Management Framework, which includes Windows PowerShell 2.0, WinRM 2.0, and BITS 4.0, has been officially released today. This down-level release is now supported for Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7, and Windows Server 2008 R2 operating systems.
You can find the release here: http://go.microsoft.com/fwlink/?LinkID=151321
For those wishing to get started on PowerShell, here is an excellent free eBook by Dr. Tobias Weltner, PowerShell MVP.
http://powershell.com/Mastering-PowerShell.pdf
One of the great features in PowerShell 2.0 is the ability to extend .NET object types to add additional custom properties and methods. For instance, the type System.String does not have a property called IsANumber that returns whether or not the string is a number. Typically, you would have to do a TryParse. By extending the System.String object, we can add such property.
Here’s how it works:
We will create a custom XML file that will define the .NET object that we would like to extend and how we want to extend it. Then, we will load that XML into our PowerShell session and the new methods/properties will be available to us.
Types.ps1xml file, located at $pshome ships with PowerShell 2.0 It is a good place to look at example extensions. Because this file is digitally signed, we cannot modify it directly, this is why we will create a custom XML file.
Let’s get started.
Open PowerShell by right clicking and choosing “Run as Administrator”
This next step (which is actually three commands) will create a new XML file “MyCustomTypes.ps1xml” at the $pshome location, (typically: C:\Windows\System32\WindowsPowerShell\v1.0) and open it in Notepad.
$mycustfile = “$pshome\MyCustomTypes.ps1xml”; New-Item –ItemType File –Path $mycustfile; notepad $mycustfile
Note: we are using PowerShell 2.0 but the install location for that is called “1.0”
Next, add the following XML to the notepad window that opened:
<?xml version="1.0" encoding="utf-8" ?>
<Types>
<Type>
<Name>System.String</Name>
<Members>
<ScriptProperty>
<Name>IsANumber</Name>
<GetScriptBlock>
$out = $null; [System.Double]::TryParse($this, [ref] $out)
</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
</Types>
The $this property is the current object of the type you are extending. In our example it will always be a string, since we are extending the System.String object.
Save and close Notepad
Back in PowerShell type the following command to load the custom types xml file and give it higher precedence than any other loaded file:
Update-TypeData -PrependPath $mycustfile
Now, to test that the new property has been added, we can create a new string variable and check the IsANumber property.
Below are a few of the different types of extensibility that you can perform:
<AliasProperty> – defines a new name for an existing property
<CodeMethod> – references a static method of a .NET class as a method for the object
<CodeProperty> – references a static method of a .NET class as a property for the object
<NoteProperty> – defines a property with a static value
<ScriptMethod> – defines a method whose output is the value of a script
<ScriptProperty> – defines a property whose output is the value of a script
For more information:
get-help about_types.ps1xml and get-help update-typedata
Developers of SharePoint should be giddy with excitement in all of the tools and features coming out of Visual Studio 2010 and SharePoint Designer 2010. Here are the biggest take-a-ways from Paul Andrew’s talk on the 2010 developer platform:
1. “Save site as template” now exports as a WSP which can be imported into Visual Studio 2010 as a new project
2. BDC is now Business Connectivity Services which supports full Create, Read, Update, Delete calls to sources, plus Office 2010 integration using new SharePoint Designer 2010 tools
3. LINQ to SharePoint to replace complex CAML queries in code. Strongly typed, intelli-sense, joins and projections
4. Developer Dashboard displays call stack, load time, and other valuable data to debug and review code
5. Relationships between lists, supporting cascade deletes (transactions are actually handled on SQL Server)
6. Large List? No problem! Just be certain of data in views. Use throttling and indexes for performance. 10’s to 100’s of thousands of documents = no problem.
7. Column Validation – lets us add validation logic when defining columns
8. Client Object Model – simple API to Add, Retrieve, Update and Manage data. Commands are batched for performance:
ClientContext cnt = new ClientContext (“http://siteurl”);
Web site = context.Web;
context.Load(site);
context.ExecuteQuery();
site.Title = “Something New”;
site.Update();
context.ExecuteQuery();
9. Rest APIs – uses ADO.NET Data Services. Out of the box services in SharePoint. Retrieve data off of site in 3 lines of code.
10. Better Events and Workflow. Event Receivers and Workflows now possible at the site scope level (workflow does not bind to a list). Event receivers can run asynchronously
11. Easily build dialog forms using AJAX.
12. Silverlight web part out of the box. - code doesn’t need to run on server!!!
13. Sandboxed Solutions – can monitor counters on server (CPU, RAM, etc.) to automatically shutdown bad code. Uses a proxy worker process so not direct access to Microsoft.SharePoint.dll
14. WSP is the unified developer platform (for both Site Collections and local machine)
15. Integration with Team Foundation Server (TFS): work item tracking, source control, team build, manage test cases, automated testing, and load testing!
You may have already heard that SharePoint 2010 will ship with a PowerShell provider that contains over 500 cmdlets for you to administer SharePoint. The killer though, is that these commandlets can be executed remotely with PowerShell 2.0 WinRM. Awesome! Don’t worry about STSADM, it will still be around to support existing administration scripts and utilities.
You can load the PowerShell provider by typing:
add-pssnapin Microsoft.SharePoint.PowerShell
Much of what Christian (iLoveSharePoint) and I have worked on in SPoshMod for SharePoint 2007 supports the same pattern as the 2010 provider. Verb-Noun, with SP prefix. Get-SPSite, Get-SPWeb, etc.
What you may not know is that developers can add custom providers and deploy them to SharePoint. You can do this by using the Microsoft.SharePoint.PowerShell namespace. To distinguish a normal PowerShell cmdlet from a SharePoint cmdlet, an new abstract class has been added to the namespace called: SPCmdlet (other cmdlets inherit directly from PSCmdlet).
More to come on this topic…
I’ll be at SharePoint Conference 2009 and will be participating with EndUserSharePoint.com in their LiveBlogging sessions.
Live blogging/twittering at SharePoint Conference 2009:
I will be attending the SharePoint Conference in Las Vegas next week and wanted to share my schedule with those that might be interested in checking back for content. I will be blogging on content throughout the event. There may be multiple sessions listed under a given timeslot as I will be narrowing down content as I attend other sessions.
I will be cross posting some content on my blog with EndUserSharePoint.com more info can be found on my next blog post:
--> Live Blogging from SharePoint Conference 2009
or on Twitter: http://twitter.com/erickraus
Monday, October 19th, 2009
9:00 AM - Keynote: Unveiling Microsoft SharePoint 2010
Speaker: Steve Ballmer
10:30 AM - Keynote: Microsoft SharePoint 2010 Drilldown
Speaker: Jeff Teper
1:15 PM - Overview of the SharePoint 2010 Developer Platform
2:45 PM -
SharePoint 2010 Administration: Part 1
Visual Studio 2010 SharePoint Development Tools Overview
4:30 PM -
SharePoint 2010 Administration: Part 2
Overview of Social Computing in SharePoint 2010
Developing with SharePoint 2010 Sandboxed Solutions
Tuesday, October 20th, 2009
9:00 AM -
Building Rich Internet Applications with Silverlight 3 and...
Advanced Web Part Development in Visual Studio 2010
Overview of Office 2010 for the IT Pro
10:30 AM -
Building A Great Extranet: Proven Principles & Best Practices
Scaling SharePoint 2010 topologies for your organization
1:15 PM -
SharePoint isn’t just for Servers anymore
Developing SharePoint 2010 Applications with the Client Object Model
Authentication and Authorization in SharePoint 2010
2:45 PM - Deep Dive into SharePoint 2010 My Sites and Social Networking...
Wednesday, October 21th, 2009
9:00 AM - Developing an Automated Site Management Lifecycle with SharePoint 2010
10:30 AM - Business Connectivity Services Runtime and Object Model Deep Dive
1:15 PM - Developing with REST and LINQ in SharePoint 2010
2:45 PM -
Externalizing BLOB Storage in SharePoint 2010
Developing Social Applications with SharePoint 2010
4:30 PM - Advanced Development for Silverlight 3 in SharePoint 2010
Thursday, October 22th, 2009
9:00 AM - Unveiling New Management Tools for Administering SharePoint 2010
10:30 AM - Application Lifecycle Management for Developers in SharePoint 2010
12:00 PM - Upgrading SharePoint 2007 code to SharePoint 2010
This came up for a recent customer, so thought I would share my solution as many people are not aware of this customization possibility. The solution ultimately solved the problem that feature staplers activate features BEFORE any lists are provisioned on a site. So, the only eloquent way to modify a list or list item is to create a new list template in a new site definition. Here is an alternative solution to consider instead of supporting another site definition in your environment.
When SharePoint shows you the list of site definitions available to create a new site, it compiles this list from the list of files in: 12 Hive\TEMPLATE\1033\XML\ SharePoint will collectively pull all of the contents in the files named: webtemp*.xml and display a list of available site definitions. By creating your own webtempcustom.xml you can effectively add site definitions to the list of choices at the ‘create’ screen. (nothing new here)
However, you don’t necessarily have to create a site definition along with your webtemp*.xml file. Instead, you can call custom code to build your site to your needs and return that site to the provisioning process. This can be accomplished by leveraging the SPWebProvisioningProvider class when a new site is created. This class, which is inherited from, is specified in your webtempcustom.xml file.
Here is an example of a webtempcustom.xml file with the provisioning class specified:
And the provisioning class:
Now, just deploy your xml file to the 12\TEMPLATE\1033\XML folder and your compiled DLL to the GAC. When the site is created, it will still be created with the STS#0 (or the template you apply in your code. Essentially, eliminating the dependency on any other site definitions.
Another thought, you could even add the ProvisionAssembly and ProvisionClass to an existing template entry such as STS to override the provisioning process for an existing site definition.
Here’s a great (FREE) opportunity to attend a day-long workshop completely dedicated to SharePoint. Come learn from developers, IT Pros, consultants, and local companies who have implemented SharePoint and have a story to share.
I will be presenting again this year on one of my favorite topics, PowerShell. Here is an abstract of the session:
PowerShell Administration and Development in SharePoint
PowerShell is a hot topic for SharePoint 2007 and will be even more for 2010. Discover the power of PowerShell 2.0 and PowerGUI as they are used to perform advanced administrative & development tasks in SharePoint. This session will start with a brief introduction to PowerShell scripting and continue with a look into helpful SharePoint scripts including: filtering event and ULS logs, managing sites and users, streamlining feature development, managing web parts, working with the object model, and much more! Both administrators and developers will benefit from this powerful discussion.
More information, and steps to register, can be found here: http://twincitiessharepointcamp.com/
Hope to see you there!
For those looking to ramp up on a new technology or finally add that certifications under your belt, here is a great offer from Microsoft. You can save up to 20% on MCTS exams through the end of the year.
This offer is available worldwide while supplies last, and you have to register, schedule and purchase your discounted exam by December 31, 2009.
For more information: http://www.microsoft.com/learning/careeroffers
Windows 7 allows you to create custom search connectors to various OpenSearch standard search engines, e.g. Bing and you guessed it: SharePoint! Creating a search connector is super easy!
1. Open Notepad and copy in the XML below
2. Replace the areas in red with your SharePoint Search Center information. Be sure to only replace just the part of the URL that gets to your Search Center: e.g. http://sharepoint.company.com/SearchCenter You can also change the scope: e.g. &s=Intranet or &s=All%20Sites or even &s=People
3. Save the file to your Desktop as: SharePointSite.osdx
4. Double click the file to install the Search Connector. (it will install to your “Searches” directory e.g. c:\Users\<username>\Searches
Optional: you can add a shortcut the favorites area on any Windows Explorer window by dragging the installed Search Connector there.
------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:ms-ose="http://schemas.microsoft.com/opensearchext/2009/">
<ShortName>SharePoint Search</ShortName>
<Description>Search the SharePoint site.</Description>
<Url type="application/rss+xml" template="http://sharepoint.company.com/searchcenter/_layouts/srchrss.aspx?k={searchTerms}&s=All%20Sites"/>
<Url type="text/html" template="http://sharepoint.company.com/searchcenter/Pages/Results.aspx?k={searchTerms}&s=All%20Sites"/>
<ms-ose:ResultsProcessing format="application/rss+xml">
<ms-ose:LinkIsFilePath>-1</ms-ose:LinkIsFilePath>
</ms-ose:ResultsProcessing>
</OpenSearchDescription>
I am frequently asked by colleagues and customers for a dump of all of my SharePoint content (presentations, white papers, etc.) While I continue to add files like these to my hard drive in various different locations, it has started to take me a while to aggregate them all forward. It dawned on me that this need not be a half an hour exercise of locating documents.
Bing! PowerShell
Thanks to another colleagues blog: http://blogs.msdn.com/daiken/archive/2007/02/12/compress-files-with-windows-powershell-then-package-a-windows-vista-sidebar-gadget.aspx
I created a few functions and added them to my PowerShell module that loads with my profile. Now it’s as simple as:
Get-ChildItem -path c: -filter *sharepoint* -recurse | create-zip "c:\sharepoint.zip"
#Special Thanks to:
# http://blogs.msdn.com/daiken/archive/2007/02/12/compress-files-with-windows-powershell-then-package-a-windows-vista-sidebar-gadget.aspx
# Create a new zip file from pipeline
function Create-Zip()
{
param
(
[string]$zipFile
);
New-Zip -zipfileName $zipFile
$zip = Get-Zip -zipfileName $zipFile
#loop through files in pipeline
foreach($file in $input)
{
#add file to zip and sleep 1/2 second
$zip.CopyHere($file.FullName)
Start-sleep -milliseconds 500
}
}
#create a new zip file
function New-Zip
{
param([string]$zipfilename)
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
#get the zip file
function Get-Zip
{
param([string]$zipfilename)
if(test-path($zipfilename))
{
$shellApplication = new-object -com shell.application
$zipFullFilename = (get-childitem $zipfilename).FullName
$shellApplication.NameSpace($zipFullFilename)
}
}