Adding a product to a catalog using code
You can add a product to a Commerce Server Catalog using the next code. Notice that you have to add a reference to the Microsoft.CommerceServer.Catalog.dll (CommerceSharePointExtensibilityKit) and the Microsoft.CommerceServer.Runtime.dll
BaseCatalog baseCatalog = (BaseCatalog)CommerceContext.Current.CatalogSystem.CatalogContext.GetCatalog("Adventure Works Catalog");
//baseCatalog.CreateProduct(string defintionName, string productId, decimal listPrice, string parentCategoryName);
Product item = baseCatalog.CreateProduct("Tents", "Iglo", 30m, "Tents");
item.DisplayName = "Iglo";
item["Description"] = "Very nice tent";
item.Save();
Adding extended WebPart to Commerce Server 2009
If you’re planning to develop your own SharePoint WebParts for Commerce Server 2009 this article could help you with a lot of troubles.
First problem there is not a lot of info about extending or writing your own WebParts on the internet. Some issues are covered on the Commerce Forum: http://social.msdn.microsoft.com/Forums/en-US/commserver2009/threads
Before you start developing WebParts for Commerce Server 2009 take a close look to the CommerceSharePointExtensibilityKit. This Kit are the sources of the defaultSite WebParts, UserControls etc. You can find it in a zip at the following location: C:\Program Files\Microsoft Commerce Server 2007\Microsoft Commerce Server 2009\Sdk\Samples\CommerceSharePointExtensibilityKit.zip
Trying to unzip the CommerceSharePointExtensibilityKit, I was prompted for a password (some files are password protected). I canceled the extracting process and copied the whole zip to my desktop. Extracting it there didn't prompt me for a password and all files were successfully extracted.
After extracting you can load the solution in Visual Studio 2008. You can build it (try this and take a look to the bin folder).
You will notice some references in the examples. One reference is the reference to: Microsoft.Commerce.Portal.Common. This is a Commerce dll which is in your GAC (c:\windows\assembly). If you read some articles on the internet you have to sign this assembly before using it. This is covered in the next article: Adding Extended Web Parts. In my solution I added a copy of the GAC assembly as a reference to my Visual Studio SharePoint WebPart project. In this case it was not necessary to re-sign all references of my Commerce Site with my public key (because I use the default). Notice that this is NOT! a best practice since you'r using the runtime environment, It's better to use your own key and delay signing. Because I only use it in a demo environment VPC this way is quicker that edit all public keys, and have the risc to break my whole site since I'm using the out of the box SharePoint Commerce Server 2009 Default Site. In this article you can find out how you can get a copy of a GAC assembly: http://blog.sharepointdevelopment.nl/post/Copy-a-DLL-from-the-Global-Assembly-Cache-GAC.aspx
In my case it was required to build a SharePoint WebPart with the content of an anonymous basket (the basket of a user which has no login, eg a visitor). Problem with the GetBasket method is that you have to put in a userid (GUID), see the next sample. Normally you can get the userID by using a method like: CommerceContext.Current.UserId. This didn’t work for me (maybe because I'm extending my SharePoint Site?). I discovered that if u use another basket object (from another .dll reference) you can get the current userID (that’s the reason for working with two basket objects in my sample). Possibly you have a better solution for me. Feel free to drop a comment about some improvements. For now I’m happy with my first working Commerce WebPart.
[code:c#]
// Get the lineitems in a basket of an anonymous user (visitor)
private Microsoft.CommerceServer.Runtime.Orders.Basket basket;
protected override void CreateChildControls()
{
try
{
ShoppingController shoppingController;
// Load Basket to set SubTotal/Number of Items in cookie
shoppingController = new ShoppingController(true, false, false, false, false, false);
shoppingController.AddBasketQueryRequest(ShoppingController.DefaultBasketName);
shoppingController.ExecuteBrokerRequests();
Microsoft.Commerce.Portal.Common.Basket b =
shoppingController.GetBasket(ShoppingController.DefaultBasketName);
basket = CommerceContext.Current.OrderSystem.GetBasket(new Guid(b.UserId), "default");
//Normally we get a userId like
// Get the current CommerceContext and current user.
//CommerceContext csContext = CommerceContext.Current;
//String userId = csContext.UserID;
}
catch (Exception ex)
{
}
}
protected override void Render(HtmlTextWriter writer)
{
try
{
foreach (OrderForm orderForm in basket.OrderForms)
{
foreach (Microsoft.CommerceServer.Runtime.Orders.LineItem lineItem in
orderForm.LineItems)
{
// Write product displaynames and quantity of basket
Writer.WriteLine(lineItem.DisplayName.ToString() + " (" +
lineItem.Quantity.ToString() + "x) ";
}
}
}
}
Copy a DLL from the Global Assembly Cache GAC
Sometimes you need to copy a DLL from the GAC to Visual Studio.
It is not possible to copy DLL's from the GAC since you have only the ability to uninstall them. .NET contains a DLL called shfusion.dll which is a Assembly Cache viewer (location: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll). By using some commands you can change the view of the GAC which allows you to copy a DLL from the GAC (and add it as a reference in Visual Studio).
Change GAC View to folders by running this command in the run box: regsvr32 -u C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll (uninstalls shfusion.dll)
Back to original GAC View by running this command in the run box: regsvr32 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll (installs shfusion.dll)
Code blocks are not allowed in this file - Hiding controls in SharePoint Masterpage
If you want to hide some controls in your SharePoint masterpage if you're not logged in, you can use the next code (I use it in my Commerce Server 2009 CSDefaultSite masterpage):
<% if (Page.User.Identity.IsAuthenticated){ %>
<Commerce:SPMiniCartWebPart id="miniCart" runat="server" XslTemplateUri="[Templates]/MiniCart/DefaultSite_MiniCart.xslt" __WebPartId="{B9D043A2-47E5-496F-A388-51E109FCD387}"/>
<%} %>
Using this code, I hide the Commerce Server "miniCart" control. After testing the page you will receive te error: Code Blocks are not allowed in this file!
SharePoint disables the ability to create server-side script by default, you have to turn it on. You do that in the web.config file, in the configuration/SharePoint/PageParserPaths configuration section:
<PageParserPaths>
<PageParserPath VirtualPath="/_catalogs/masterpage/CSDefaultSite.master" CompilationMode="Always" AllowServerSideScript="true" />
</PageParserPaths>
Now your codeblock works and the control will only be shown after login. This example uses Commerce Server 2009 but it also works for other controls and if you're not using Commerce Server! Just change the italic part to your own control.
Loading SPItems from a SPList to a DataSet
Using the next code you can load SPItems from a SPList to a DataSet. You can use this dataset for e.g. binding it to a GridView.
private DataSet LoadSPData(string listName)
{
DataSet ds = new DataSet();
SPSite siteCollection = SPContext.Current.Site;
SPWeb site = SPContext.Current.Web;
SPList list = site.Lists[listName];
if (list != null)
{
DataTable dt = list.Items.GetDataTable();
DataColumn col1 = new DataColumn("MyColumn");
dt.Columns.Add(col1);
ds.Merge(dt);
return ds;
}
else
return null;
}
GridView and SPGridView paging problem
You can make use of a GridView (.NET) or SPGridView (SharePoint) in a SharePoint webpart. You can also enable paging. Make sure you add this controls to the page controls collection before you bind it to a datasource. Otherwise paging will not work:
GridView GridView1 = new GridView();
//Add control before binding it to a datasource
this.Controls.Add(GridView1);
GridView1.DataSource = myDataSource;
GridView1.DataBind();
Microsoft Commerce Server 2009 code name R2 - June 2009 Community Technical Preview
Microsoft Commerce Server 2009 code name "R2" - June 2009 CTP is the first pre-release of the next version of Commerce Server. Please note that this pre-release version is not feature complete.
Download: http://www.microsoft.com/downloads/details.aspx?FamilyID=dfaca6d6-6e1a-4067-8857-61ff1300bf6b&displaylang=en
System Requirements
- Supported Operating Systems: Windows Server 2008
Single-server deployments are supported, which consists of running all the Commerce Server 2009 components and software requirements (including Microsoft Windows and Microsoft SQL Server) on a single computer. The single-server deployment uses the following software products:
- Microsoft Windows Server 2008 (64-bit) or Microsoft Windows Server 2008 R2 (64-bit) and Microsoft Windows critical updates
- IIS 7.0 with Microsoft Windows Server 2008
- Microsoft SQL Server 2008 Standard and Enterprise (64-bit)
- Microsoft .NET Framework 3.5 with SP1
- Microsoft Windows SharePoint Services 3.0 (WSS) SP1 or Microsoft Office SharePoint Server 2007 (MOSS) SP1
If using WSS:
If using MOSS:
Spencer Harbar, Bob Fox and Robin Meure at the SDN Event on June 26th
The next SDN event will be on friday, june 26th 2009 in Hotel Van der Valk in Houten in the Netherlands. Part of the event is the Information Worker track. Spencer Harbar, Bob Fox and our dutch SharePoint specialist Robin Meure will be presenting there. So spread the word!!
There will also be a SharePint afterwards talking about nothing else then SharePoint. This will be the second SharePint in the Netherlands. I will be there too and hope to see you all!
Sessions will be:
- SharePoint Mythbusters: Debunking common SharePoint Farm Misconceptions - Spencer Harbar
This interactive session will dive into common SharePoint Farm Myths and discuss common misconceptions around Global Deployments, Farm Topologies, Shared Service Providers, High Availability, Security and more. Alongside best practices for each “myth”, the SharePoint “magic numbers” will be covered and there will be plenty of scope to discuss any particular queries you may have on farm deployment
- Best Practices for Virtualization with Hyper V and SharePoint - Bob Fox
In this presentation I am going to give an overview of Microsoft Windows Server 2008 Hyper Virtualization Technology with a strong emphasis on how to leverage using SharePoint in a Virtual Environment. Some of the topics covered: - Hyper V What is it - Hyper V what are the benefits - Hyper V What you need to know - Hyper v How to implement (Demo) - Hyper v How do I deploy my SharePoint environments (Demo) - Hyper V Recommendations and take away info
- Kerberos part 1: No ticket touting here. Does SharePoint add another head? - Spencer Harbar and Bob Fox
This session will provide an overview of Kerberos and the benefits it offers in a SharePoint 2007 deployment including: Discussion of whether your SharePoint deployment needs Kerberos. A tour of the required pre-requisites and configuration settings. Best Practices for automating configuration in a SharePoint Farm. Best Practices for diagnosing common configuration error
- Kerberos part 2: advanced scenarios and additional considerations - Spencer Harbar and Bob Fox
This second Kerberos session will provide an example, end to end scenario with MOSS, Excel Services and 3rd Party applications, and dive into additional troubleshooting and auditing best practices, known issues and workarounds, including Q&A/Discussion. This session is part two of a two part session. Part two assumes attendees are familiar with the concepts presented in part one.
- Waarom SharePoint Application Pages? - Robin Meuré (in dutch)
Wanneer je maatwerk oplossingen bouwt bovenop SharePoint dan heb je vaak behoefte aan een pagina in Central Admin om je oplossing te kunnen configureren. Het liefst zou je dezepagina in de look&feel van SharePoint willen hebben en uiteraard wil je zo veel mogelijk gebruik maken van bestaande SharePoint controls. En als het even kan zou je ook graag je configuratie willen opslaan zoals SharePoint zijn configuratie opslaat.. ;)
More information can be found on http://www.sdn.nl/sde.
When you install the 2007 Microsoft Office servers Service Pack 2 the product expiration date is activated incorrectly
"During the installation of the 2007 Microsoft Office servers Service Pack 2, a product expiration date is activated incorrectly. This means that any of the products that are listed in the "Applies to" section will expire 180 days after Service Pack 2 is deployed, as if it were a trial installation."
Fix:
- Click Start, point to All Programs, point to Administrative Tools, and then click SharePoint 3.0 Central Administration.
- Click the Operations tab.
- Click Convert License Type.
- In the Enter the Product Key text box, type your product identification number, and then click OK.
- The License Synchronizer Job will run on all computers in the farm after a few moments. After all the computers have updated their license from the timer job, the Convert License Type page will reflect the correct license.
http://support.microsoft.com/kb/971620/en-us
Stsadm Technical Reference for SharePoint Server 2007
Got this cool link from a collegue. Using this interactive application you can learn about the available commands.
http://technet.microsoft.com/en-us/office/sharepointserver/cc948709.aspx