Commerce Server 2009 Installation Guide

In this lesson/tutorial I will show you how to install Commerce Server 2009 and all needed for a development platform  on a single machine, standalone installation, not farm,  meaning that all needed will be on the same machine : Windows Server 2008, Sql Server 2008, IIS 7.0, Windows Sharepoint Services 3.0,  Visual Studio 2008, etc.

This installation will be for educational purposes, in real life situation farm installation being advised. It would be better for the overall performance/ security /mantainance to have a  separate Sql Server Machine and separate Sharepoint Server for example.

Being a Microsoft product you would expect an easy installation with next, next – finish setup.

Well this is not the case, the setup being a long process with traps along the way.

I will try to show you the steps for installing and configuring Commerce Server 2009 .

Step number 1. Prepare Windows Server Environment

Let`s say you have installed Windows Server 2008.

This platform is for building B2X ecommerce applications/ websites,  so the first thing you would need is IIS  7.0 or 7.5 Web Server.

For this you have to go to Server Manager – > Roles – > Add Role -> Web Server (IIS)

Next you have to select the Role services .

Select

  • Application development (if other features need to be installed you will be prompted with a new form. Click on the “Add Requiered Features” button.
Commerce Server 2009 installation guide

Commerce Server 2009 installation / install guide / development platform

  • From Security select
    •  Basic Authentication,
    • Client Certificate Mapping Authentication
    • IIS Client Certificate Mapping Authentication
Commerce Server 2009 installation guide

Commerce Server 2009 installation / install guide / development platform

  • From Management Tools select All

Click next and Install.

Step number 2. Install SQL Server R2 Express

Next you have to install Sql Server 2008 R2 Express. I chose the Sql Server Express with Advanced Services package because it includes the Reporting Services, which could be useful.

http://www.microsoft.com/download/en/details.aspx?id=25174

Download the package from Microsoft, enter the setup then click on “New Installation or add features to an existing installation button”.

Observation on the installation:

  • If you get this:
Commerce Server 2009 installation guide

Commerce Server 2009 installation / install guide / development platform

Then go to Server Manager -> Features -> Add Features – > Windows PowerShell

  • You should select the features below at the Sql Server Install:
Commerce Server 2009 installation guide

Commerce Server 2009 installation / install guide / development platform

.

  • You could select any name for your Server, but I advise you to let the default SQLExpress name for future references
  • In the Server Configuration Section Select the Sql Browser Services and select the Automatic Startup Type:
Commerce Server 2009 installation guide

Commerce Server 2009 installation / install guide / development platform

  •  At DataBase Configuration Add the current User (should be administrator account)
  • After the installation go to SQL Management Studio and verify your instance name

Step number 3. Visual Studio Installation

Install Visual Studio 2008/2010 and Services Packs if they exists (for example Visual Studio 2008 had a SP1 edition)

Step number 4. SharePoint Installation

SharePoint installation

Download Windows SharePoint Services 3.0 or SharePoint Foundation 2010 from Microsoft .

Find and choose the x86 or x64 version,  based on your machine .

Observation

  • Install in Advanced Mode
  • Choose Web Front End Server Type
  • At the end check the “Run the SharePoint Products and Technologies Configuration Wizard now” and click the close button and then :
    • At Connect to a Server farm Screen choose “No, I want to create a new server farm”
    • At the next step choose the right instance name of your database server (You could go to Sql Management Studio and copy paste the Server Name.  It could be only the servers name (usually when you have a higher version of the Express Server) or MachineName\InstanceName) . In our case it is “Ecommerce\SQLEXPRESS”

At the username choose your administrator account (You could make an account with the specific rights for Sharepoint Administration)

After the installation/ configuration go to SharePoint Central Administration (program files) , to Operations Tab -> Services on Server from Topology and Services :

Commerce Server 2009 installation / install guide / development platform

Commerce Server 2009 installation / install guide / development platform

Select the Windows SharePoint Services Search and click on Start :

Commerce Server 2009 installation guide

Commerce Server 2009 installation / install guide / development platform

Next use your Administrators credentials in the User Name and Passwords textboxes and Context Access Acount  ad then click start :

Commerce Server 2009 install guide

Commerce Server 2009 installation / install guide / development platform

Then,  go to Central Administration again, Application Management, Create or Extend Web Application and click “Create a new Web Application”.

Choose a new port, for example 8088, and choose your Adminstrators credentials for the application pool:

Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform

Select your Windows Sharepoint Services search Server, in this situation being the current machine :

Commerce Server 2009 Installation

Commerce Server 2009 Installation

Step number 5. Commerce Server 2007 Installation

Insert the first part/cd of the Commerce Server 2009 installation package, and install Commerce Server 2007 (Commerce Server 2009 is based on 2007)

Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform

Install in this order :

  1. Commerce Server 2007 (other than the one below use default settings in the wizard)
  • Choose Direct Mailer from components (it is useful for the Marketing System)

    Commerce Server 2009 Installation guide

    Commerce Server 2009 installation / install guide / development platform

At the end of the installation wizard uncheck the “Launch the Commerce Server Configuration Wizard” and click finish .

  1. Next install the Microsoft Commerce Server Business User Applications  with default wizard settings.

Step number 6. Commerce Server 2009 Installation

Insert the second  part/cd of the Commerce Server 2009 installation package, and install Commerce Server 2009 .

In the Commerce Server Configuration Wizard

  • Select the right Sql Server name : Ecommerce\SQLEXPRESS (in our case). Click Test to test the sql server connection.
  • Use the Adminstrator credentials for direct mailer service account (you could make a user just for this service )
Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform

In the Upgrade Wizard :

  • You should select a different location for the log file, to know its location precisely if something does not work as planed

Next go to Program Files, Commerce Server 2009, Tools and start  Sharepoint Commerce Server Configuration Wizard

  • Select Commerce SharePoint Default Web Site and Web Parts
  • Use the web application that we created earlier (SharePoint – 8088), Select “Unpack Commerce Server Site(With Sample Data) and enter the right instance of the Database Server :
Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform

Next go to Program Files, Commerce Server 2009, Tools and start Site packager :

  • Select Unpack from a package file (.pup)
  • Select custom unpack, click browse and go to Program Files, Commserce Server 2007, Commerec Server 2009, Site and select MicrosoftCommerceDefaultSiteWithSampleData.pup
  • Select Add an Application in the package to an existing site
  • All of the other steps are with default values

Step number 7. Commerce Server 2009 Configuration

Now we have to configure the Business tools (Catalog Manager, Customers and Orders Manager, Marketing Manager, etc. )

We have to create a user for every web service the sdk uses for the business tools :

Go to Server Manager – > Configuration – > Local Users and Groups -> Users – > New User  -> Insert CatalogWebSvc as the UserName and set its password (uncheck “User Must Change password at next logon”. I also unchecked “Password never expires”)

Add the user RunTimeUser  also, using the same steps described before.

Also create the users : MarketingWebSvc , OrdersWebSvc, ProfilesWebSvc

Then go to Logal Users and Groups to Groups.

  • Add the group CatalogAdminGroup and add the CatalogWebSvc user.
  • Add the group MarketingAdminGroup and add MarketingWebSvc user.
  • Add the group OrdersAdminGroup and add OrdersWebSvc user.
  • Add the group ProfilesAdminGroup and add ProfilesWebSvc user.
  • Find the IIS_IUSRSGroup and add the following users :
    • RunTimeUser
    • CatalogWebSvc
    • OrdersWebSvc
    • ProfilesWebSvc
    • MarketingWebSvc

Go to Internet Information Services (IIS Manager in Administrative Tools)  – > Application Pools  (right click on it) and create the following Application Pools(select Classic Managed Pipeline Mode):

  • CatalogWebSvcAppPool
  • OrdersWebSvcAppPool
  • ProfilesWebSvcAppPool
  • MarketingWebSvcAppPool

Next go to CatalogWebSvcAppPool -> Advanced Settings->

Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform

Select the Identity from Process Model :

Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform

Select Custom Account and add CatalogWebSvc user .

Do the same to

  • OrdersWebSvcAppPool  ( associate the OrdersWebSvc user )
  • ProfilesWebSvcAppPool  ( associate the ProfilesWebSvc user )
  • MarketingWebSvcAppPool  ( associate the MarketingWebSvc user )

Go to Sites (from IIS maneger) ->Default Web Site – > Default_CatalogWebService -> Advanced Settings > and change the Application pool to CatalogWebSvcAppPool :

Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform

Do the same (and associate the appropriate Application pool ) with:

  • DefaultSite_MarketingWebService
  • DefaultSite_OrdersWebServiec
  • DefaultSite_ProfilesWebService

Open Sql Management Studio and go to Security Logins :

  1. New Login – > Add the RunTimeUser (Windows Auth), in this case Ecommerce\RunTimeUser

Then you add the other 4 users :

  • Ecommerce\CatalogWebSvc
  • Ecommerce\OrdersWebSvc,
  • Ecommerce\ProfilesWebSvc,
  • Ecommerce\MarketingWebSvc,

Now we have to configure the user mappings and permissions every users has.

  1. Select ECOMMERCE\CatalogWebSvc from Logins, go to User Mappings and select(check) MSCS_Admin  and add the admin_reader_role.

Check the MSCS_CatalogScratch database and add the roles:

  • db_ddladmin
  • db_datawriter
  • db_ddladmin

Check  DefaultSite_productcatalog database  and select:

  • ctlg_CatalogWriterRole
  • db_datareader
  • db_datawriter
  • db_ddladmin
  • db_securityadmin
  • Inventory_ReaderRole
  • Inventory_WriterRole
Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform

  1. Select the ECOMMERCE\MarketingWebSvc user from logins and go to User Mappings .

Check  MSCS_Admin database and select admin_reader_role .

Check MSCS_CatalogScratch database and select the roles :

  • Db_datawriter
  • Db_datareader
  • Db_ddladmin

Check DefaultSite_Marketing database and select the roles :

  • Mktg_marketing_Service_Role
  • Mktg_runtime_role
  • Mktg_promoCodeGenerator

Check DefaultSite_marketing_lists database and select the dbo_owner role.

Check DefaultSite_productcatalog database and select the roles :

  • Ctlg_CatalogReaderRole

Check DefaultSite_profiles database and select the roles :

  • Profile_Reader
  • Profile_Schema_Reader
  1. Select the ECOMMERCE\OrdersWebSvc user from logins and go to User Mappings .

Check  MSCS_Admin database and select admin_reader_role .

Check MSCS_CatalogScratch database and select the roles :

  • Db_datawriter
  • Db_datareader
  • Db_ddladmin

Check DefaultSite_productcatalog database and select the roles :

  • Ctlg_CatalogReaderRole
  • Inventory_ReaderRole

Check DefaultSite_transactionconfig database and select the roles :

  • Orders_Management

Check DefaultSite_transactions database and select the roles :

  • Orders_Management
  • Orders_Runtime

Check DefaultSite_Marketing database and select the roles :

  • Db_ddladmin
  • Mktg_runtime_role
  1. Select the ECOMMERCE\ProfilesWebSvc user from logins and go to User Mappings .

Check  MSCS_Admin database and select admin_reader_role .

Check DefaultSite_profiles database and select the roles :

  • Profile_Schema_Manager
  • Profile_Runtime
  1. Select the ECOMMERCE\RunTimeUSer user from logins and go to User Mappings .

Check  MSCS_Admin database and select admin_reader_role .

Check MSCS_CatalogScratch database and select the roles :

  • Db_datawriter
  • Db_datareader
  • Db_ddladmin

Check DefaultSite_Marketing databae and select the roles :

  • Db_ddladmin
  • Mktg_runtime_role

Check DefaultSite_marketing_lists database and select the db_datareader role.

Check DefaultSite_productcatalog database and select the roles :

  • Ctlg_CatalogReaderRole
  • Inventory_RuntimeRole

Check DefaultSite_profiles database and select the roles :

  • Profile_Runtime
  • Profile_Schema_Reader

Check DefaultSite_transactions database and select the roles :

  • Orders_Runtime

Check DefaultSite_transactionconfig database and select the roles :

  • Orders_Runtime

Configuring the Catalog Manager

Go to Start and write azman.msc in execute and press enter. Go Actions->Open Authorisation Store– > Browse c:\inetpub\wwwroot\DefaultSite_catalogWebService and select the CatalogAuthorizationStore  xml file .

Go to CatalogInventorySystem-> Role Assignments -> Administrator , right click on the empty right part (where it writes “There are no items to show in this view)  and Assign Users and Groups (from active directory) and add CatalogAdminGroup and your Administrator Account .

I also added the administrator account  to every other role in the role assignments, but I do not think it is necessary, so feel free to try it without the last part.

Go to IIS Management tool -> Sites -> Default Web Site ->  DefaultSite_CatalogWebService -> browse and add the CatalogWebService.asmx part to the end of the url in the browser.

It should be something like this :

http://ecommerce/DefaultSite_CatalogWebService/CatalogWebService.asmx

Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform

Go to Program Files and open the Catalog Manager from Commerce Server 2009.

At first run you will get an error. Press ok and then edit the url path of the webservice and add the url from above:

http://ecommerce/DefaultSite_CatalogWebService/CatalogWebService.asmx

and press ok. You will get another error. If you check the event viewer you will see that that it does not have rights to access the AuthorizationStore.xml.

All you have to do is to go to c:\inetpub\wwwroot\DefaultSite_CatalogWebService, folder properties, security , edit -> add user , and there you add the administrator account and CatalogWebSvc User with full control .

Do the same to the folders c:\inetpub\wwwroot\DefaultSite_MarketingWebService, but add the MarketingWebSvc user,  c:\inetpub\wwwroot\DefaultSite_OrdersWebService, but add the OrdersWebSvc user and c:\inetpub\wwwroot\DefaultSite_ProfilesWebService, but add the ProfilesWebSvc user.

If you open the Catalog Manager again it should work.

Configuring the Customers and Orders and Marketing Manager

Go to IIS Manager, the main node (with the machine name, in this case ECOMMERCE) and go t Server Certificates :

Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform

Create Self-Signed Certificate, and give it the machine name : ECOMMERCE

Now go to Sites->Default Web Site -> Bindings -> Add and choose https with the newly created certificate (ECOMMERCE)

For the other Business tools to work we have to configure the roles in azman.msc as we did with the CatalogManager:

Go to azman.msc again. Right Click on the first node (Authorization Manager) Open Authorization Store, and go to c:\inetpub\wwwroot\DefaultSite_MarketingWebService\  and open the MarketingAuthorizationStore.xml

Go to the MarketingSystem subnode -> Role Assignments and add MarketingAdminGroup to MarketingAdministrator Role

Right Click on the first node (Authorization Manager) Open Authorization Store, and go to c:\inetpub\wwwroot\DefaultSite_OrdersWebService\  and open the OrdersAuthorizationStore.xml

Go to the OrdersSystem subnode -> Role Assignments and add OrdersAdminGroup to OrdersAdministrator role and Admin to OrdersViewer role

Right Click on the first node (Authorization Manager) Open Authorization Store, and go to c:\inetpub\wwwroot\DefaultSite_ProfilesWebService\  and open the ProfilesAuthorizationStore.xml

Go to the ProflesSystem subnode -> Role Assignments and add ProfilesAdminGroup and the Administrator account to ProfilesAdministrator role

Go to DefaultSite_OrdersWebService(iis manager -> sites->Default Web Site – > Default_OrdersWebService  browse (https 443) and add the OrdersWebServices.asmx to the url .

It should look like this : https://ecommerce/Default_OrdersWebService/OrdersWebServices.asmx

Do the same with the profiles webservices :

https://ecommerce/default_profileswebservices/profileswebservice.asmx

Go to start and in the program files find the Customers and Orders tool from Commerce server and open it.

Click the edit  button and edit the webservices url . Use the two urls from above for the orders webservice and profile web services and the url we mentioned at the Catalog Manager : http://ecommerce/DefaultSite_CatalogWebService/CatalogWebService.asmx

Now go to start button again and in the proram files find the Marketing Manager tool and open it.

Click the edit button and set the webservices straight :

http://ecommerce/DefaultSite_MarketingWebService/MarketingWebService.asmx  for the marketing webservice and the mentioned above url for the CatalogWebService .

Commerce Server Starter Site

As you might remember, we unpacked a site with sample data on the Sharepoint – 8088 web application.

Let`s try the website. Enter the url in the browser : http://ecommerce:8088

The site should load, but you will have some webpart errors.

Go to site actions – > Site Settings -> User And Permissions -> Advanced permissions

Then in the left side click on Channel Configuration. Click on Channel , edit item and write “DefaultChannel”(without commas)  in the value textbox .

Go back, click DefaultCatalog, edit, and write “Adventure Works Catalog” (without commas) in the value textbox and press ok.

Go back to http://ecommerce:8088 . It should work now.

We still have something to do though. If you write something in the search box, like big sur, for example, you will get a page that says results have been found, but you do not see them.

Click site actions again, edit page, and go to Search Results Web Part and click on Modify Shared Web Part :

Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform

In the right side of the page a panel will appear .

Go to Commerce tab -> (Tab 2) Content Type and select “None”

Commerce Server 2009 Installation guide

Commerce Server 2009 installation / install guide / development platform


[i] Gheorghe Dan-Alexandru

Multiple instances of webpart with custom EditorPart properties

I have recently stumbled upon an interesting problem in a sharepoint webpart.

I wanted to build a webpart that would dynamically create a contact form based on properties that the user set in the webpart property section. Because i wanted to give the user a dropdown from which he would select a sharepoint list from his site, and this dropdown has to populate on load based on his site, i had to use editorpart .

I won`t write about how this is done, because there are many other great posts in other blogs that explain how to do this : link1 , link2 .

After i have implemented the webpart, i have tested it and observed a problem. If i had only one webpart in the site collection, all went according to plan : the user set the properties based upon his needs and the webpart worked well.

The problem appeared when i added another instance of the webpart on another page from that site.  When i set its properties it changed the properties of first webpart as well. This problem persisted in a subsite as well.

After i googled a little i found 2 threads with the same problem, and no answers (in the meantime, i found the solution and answered).

Link1 

Link2

At first i had the properties of the webpart defined like this (this is an example of one):

public static string _emailReceiver;
[WebBrowsable(false), Personalizable(PersonalizationScope.Shared)]
public string EmailReceiver
{

get { return _emailReceiver; }
set { _emailReceiver = value; }
}
In the public class ContactFormWebPartEditorPart : EditorPart i had a textbox defined :
private TextBox Subject;

The apply changes in the editorpart :

public override bool ApplyChanges()
{

EnsureChildControls();

ContactFormWebPart webPart = WebPartToEdit as ContactFormWebPart;

if (webPart != null)

{

webPart.ContactFormList = _dropDownLists.SelectedValue.ToString();

webPart.EmailReceiver = Email.Text;

webPart.EmailSubject = Subject.Text;

webPart.RedirectTo = redirect.Text;

}

return true;

}

All you have to do is to change the EmailReceiver property from the webpart to:

[WebBrowsable(false), Personalizable(PersonalizationScope.Shared)]

public string EmailReceiver

{

get;

set;

}

I have tested it with 3 different webparts, configured each with different properties. It works! Two of them were on the same page!

Maybe it works because the setter and the getter generate random field names on compile time.

Hope that helps!

Working with sharepoint large lists

Please visit this : Samsung Service Galaxy S

In a recent project, I had to get some information from the last sharepoint listitems inserted. I used foreach. Of course it is a bad idea. When the list grew (thousand of listitems)…the program worked as fast as a drunken turtle. Ok… As I was saying the data I needed was from the last x items inserted. So I replaced the foreach with a simple for:
count=10; (the last 10 items inserted)
for (int i = oList.Items.Count – count; i < oList.Items.Count; i++)

I ran the program and saw that the improvement was not what I expected, so I made a testProject to measure the execution time, for the foreach block code and the code above (with the simple for);

DateTime startTime = DateTime.Now;

chunk of code (for or foreach iteration)

DateTime stopTime = DateTime.Now;
TimeSpan duration = stopTime – startTime;

For large lists the foreach statement took forever. The for statement took from 5 to 30 seconds for 4000 list items.
The odd part was that in the for statement as I said before, i iterated through the last 10 items.
So for 10 items I waited some good seconds.
I googled for the truth and I found this interesting article.

So I found out the SPQuery is one of the best ways to work with large lists.

SPQuery query = new SPQuery(oList.Views[0]);
Comm
query.RowLimit = 10;
SPListItemCollection filteredList = oList.GetItems(query);
foreach (SPListItem item in filteredList)
{
Blabla;
}

I ordered the list Descending by their ID so i got the most recent 10 list items.
I measured the execution time. At the first run it took 800 milliseconds for 4000 list items. The next executions took only from 15 to 30 milliseconds.
I would say…it is at least a good improvement;
An easier way to create CAML queries is with U2U CAML Query Builder
I tried to use CAML query to get the max ID directly but I didn`t succeed. If someone reads this…:P and knows how please leave a reply.

Commerce Server 2009
Thank you,
Ing. Msc. Dan Gheorghe

Kill “Not responding” programs in windows with a shortcut.

Please visit this : Samsung Service Galaxy S

As i was stumbling around, i found this article .
You can kill frozen application just with a double click on a shortcut on your desktop.
You must create a new shortcut and in the location bar write : taskkill.exe /f /fi “status eq not responding” .

Commerce Server 2009

How to make index_changed event work for asp.net Gridview

Please visit this : Samsung Service Galaxy S

I have tried to work with indexchanged event of the asp.net gridview. It didn`t even enter the function. After some searching i found solution.
You must add a column to the gridview typeof linkbutton.
In the Command atribute type “Select”

addlinkbutton1

In the RowDataBound event attach the function GridView1_RowDataBound:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

// Get reference to button field in the gridview.
LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "Select$" + e.Row.RowIndex);
e.Row.Style["cursor"] = "hand";
e.Row.Attributes["onclick"] = _jsSingle;

}
}
}

Now you must override the Render function:

protected override void Render(HtmlTextWriter writer)
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
ClientScript.RegisterForEventValidation(((LinkButton)row.Cells[0].Controls[0]).UniqueID, "Select$" + row.RowIndex);
}
}

base.Render(writer);
}

After this you can attach the indexChanged function to the gridview indexchanged event and get your row selected index when you click the row.

Commerce Server 2009

Add RoleAssignment to listitem.

Please visit this : Samsung Service Galaxy S

This is continuing the previous post. After you create the list item impersonating the current logged in user in the sharepoint site you might want to give that user only the right to read it.
After oListItem.Update(); you must run the code to do this with elevated Privileges to assign the role.

SPUser user = oWebsiteRoot.SiteUsers.GetByID(web.CurrentUser.ID);
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite site = new SPSite(SPControl.GetContextSite(this.Context).ID);
SPWeb w = site.OpenWeb();
Guid g = oListItem.UniqueId;
oListItem = w.Lists["Announcements"].GetItemByUniqueId(g);

oListItem is the listitem created in the previous post

I tried to set the RoleInheritence of the list item to false: oListItem.BreakRoleInheritance(false);
but i had some problems with it. I got the error:
“Updates are currently disallowed on GET requests.”

oListItem.BreakRoleInheritance(false) sets the spweb.AllowUnsafeUpdates to false; so after this you must set it true manually again even though we did that in the code before this (in the previous post) :

oListItem.BreakRoleInheritance(false);
w.AllowUnsafeUpdates = true;
w.Update();

Now to set the roles:

SPRoleDefinitionCollection webroledefinitions = w.RoleDefinitions;

SPRoleAssignment roleassignment = new SPRoleAssignment(user);

roleassignment.RoleDefinitionBindings.Add(webroledefinitions["Read"]);
oListItem.RoleAssignments.Add(roleassignment);
oListItem.Update();

});

And now every user sees the the items created by themselves.

Commerce Server 2009
By Ing. Msc. Dan Gheorghe

Sharepoint Impersonation.

Please visit this : Samsung Service Galaxy S

When you create a web form or web part for wss or sharepoint and work with list items for example you should impersonate the current logged user in your application to see who modified, added the list item. I chose this example to be the simplest.
So I created a web part for my sharepoint site.

I added this to the default project created when you choose Sharepoint Web Part project:
c# code:

private string customMessage = "Hello, world!";
[WebBrowsable(true),
WebDescription("Displays a custom message"),
WebDisplayName("Display Message"),
Personalizable(PersonalizationScope.User)]
public string DisplayMessage
{
get { return customMessage; }
set { customMessage = value; }

}

In the render function i added my code. To make a similarity to asp.net you can think of it as page_load handler. Whenever you refresh the page that has the web part on it it executes your code.
Here i get the current logged in user i display it on the screen and then i create a new item in the Announcements List as added by the user logged in:

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
try
{
HttpContext ctx = HttpContext.Current;
SPWeb web = SPControl.GetContextWeb(this.Context);

if ( (ctx.User != null) &amp;&amp; (ctx.User.Identity != null))
customMessage=ctx.User.Identity.Name;
writer.Write(DisplayMessage);

And we show this way the current logged in user.
Now we impersonate the user and create a new item in the Announcements list in his name. Every logged in user has a token (it identifies the authentication process applied to the user).

SPSite impersonatedSiteCollection = new SPSite( SPControl.GetContextSite(this.Context).ID, token);
SPWeb oWebsiteRoot = impersonatedSiteCollection.OpenWeb();
oWebsiteRoot.AllowUnsafeUpdates = true;
SPList oList = oWebsiteRoot.Lists["Announcements"];

SPListItem oListItem = oList.Items.Add();
oListItem["Title"] = "My Item";
oListItem["Created"] = new DateTime(2004, 1, 23);
oListItem["Modified"] = new DateTime(2005, 10, 1);
oListItem.Update();
}
catch (System.ArgumentException e)
{
customMessage = e.Message ;
writer.Write(DisplayMessage);
}

I put it in a try catch sequence because the current logged in user might not have the rights to add a new item to that list and if so the page that contains the webpart will crash and he would not see it even though he has rights to. With the try catch the webpart will tell him that he has no rights.

Commerce Server 2009

DataGrid column width.

Please visit this : Samsung Service Galaxy S

I recently found out that the datagrid component doesn`t have the column property. The smartdevice project doesn`t have DataGridView in the toolbox, so you would have to work with the DataGrid componnent.

[All code below is in C#]
At first you must create a DataGridTableStyle :

DataGridTableStyle ts = new DataGridTableStyle();

ts.MappingName = “”;

ts.GridColumnStyles.Clear();
If you have a DataTable to use as a datasource for the grid :

DataTable t = getProduse();

Now if you have to create DataGridColumnStyles for each column in the datatable:

for (int i = 0; i < t.Columns.Count; i++)

{

DataGridColumnStyle Col = new DataGridTextBoxColumn();

Col.MappingName = t.Columns[i].ColumnName;

Col.HeaderText = t.Columns[i].ColumnName;

Col.Width = 400;

ts.GridColumnStyles.Add(Col);

}

After this you add the DataGridTableStyle to the DataGrid:
dataGrid1.TableStyles.Add(ts);
Now when you select the DataSource the grid will have the Style you want:
dataGrid1.DataSource = t;

Commerce Server 2009
By Ing. Msc. Dan Gheorghe

Visual Studio 2008 Smart Device project connect to sql server.

Please visit this : Samsung Service Galaxy S

A friend of mine ran into some trouble with a smart device project these days. At first with internet connectivity on the pocket pc emulation. After some heavy swearing and a lot of tries he managed to connect to the network and then to
the sql server. There are 2 steps here:

1.Connect to the network

2.Connect to the server

1.To connect to the local network through the pocket pc emulator you must install virtual pc and Windows Mobile Device Center.

Virtual PC

Windows Mobile Device Center.

Run the Windows Mobile Device Center and use the following settings:

Windows  Mobile Center Settings

Windows Mobile Center Settings

Let it run in the background.

After you create the smart device project in visual studio you must enter Tools\Device Emulator Manager, choose the type of emulator you are using right click connect and right click cradle.

cradle

cradle

In the emulator you must go to file\Configure to the Network Tab and enable the first checkbox.

pocketpc emulator network settings

pocketpc emulator network settings

Check in the windows mobile center program if it says connected in the lower left corner. If it didn’t connect reset the settings connect mode to Bluetooth or something else, click ok, and then reset tot DMA again.

2. The sql connection string mustn’t have the name of the server. You must use the ip and the port of the machine from the network where you have sql installed, for example: “Data Source=192.168.0.30,1433;”.

string ConnectionString = “Data Source=192.168.0.30,1433;Initial Catalog=Companies;User ID=admin2;Password=test”;

1433 is the default port that sql server uses.

If you try now it still won’t work.

You must enter in sql server configuration manager\sql server network configuration\protocols and enable TCP/IP, then go to sql server native client configuration\client protocols and enable TCP/IP here also.

Double click on the TCP\IP from network Configuration\protocols, enter the IP ADDRESSES tab and delete from top to bottom TCP Dynamic Ports (let it blank) and enter TCP port 1433 :

Sql Configuration Manager TCP\IP

Sql Configuration Manager TCP\IP

After this you the application should connect to the sql server.

Commerce Server 2009
By Ing. Msc. Dan Gheorghe

with the help of Catalin Manole