Commerce Server Blog

Build world class ecommerce applications using Microsoft Commerce Server
  •  
  • Home
  • Advertise
  • Copyright Policy
  • Disclaimer
  • About

Adding Image to Profile Sub-System

ravikanth | July 25, 2008

Commerce server profile will provide lot of advantages to developer by allowing extending it as per client business needs. In this article we are discussing how to add an image to use profile. Personalization is currently hot topic in the market and in this article we are extending our profile system to store user image in his profile. This image can be used to display in reviews/communities in ecommerce site.

There are two days we can implement this solution

1.       Store image in file system and the file path in database.

2.       Store image in the database.     

In the current article we are storing image in the database.

Follow these steps

1.       Create a new field named “u_UserImage” of type “Image” in UserObject table (This is  used to store user image).

ALTER TABLE dbo.UserObject ADD

                u_UserImage image NULL

GO

2.       Open commerce server manager. Expand Profile-> profile Catalog-> Data Sources-> ProfileService_SQLSource->DataObjects-> UserProfile.

3.       Right click on User Object and click on “Add Data Member” and enter text as shown in the image.

4.       Open commerce server manager. Expand Profile-> profile Catalog-> Profile Definitions and click on User object.
Add Data Member

5.       Click on General Information and click on Add Property and add values as shown in the image below.

 

Add Property
6.
      
In your registration page, add a input field of type file.

7.      

Add following code at submit button click event.

 

// Reading file content.

Stream s = File.OpenRead(filePath);
byte[] buffer = new byte[s.Length];
s.Read(buffer, 0, (int)s.Length);
s.Dispose();
s.Close();      

//Creating an user profile.

Profile userProfile = profileContext.CreateProfile(newId.ToString(), “UserObject”);
userProfile.Properties["GeneralInfo.user_id"].Value = newId.ToString();
userProfile.Properties["GeneralInfo.first_name"].Value = txtbox_FirstName.Text.ToString();
userProfile.Properties["GeneralInfo.last_name"].Value = txtbox_LastName.Text.ToString();
userProfile.Properties["GeneralInfo.email_address"].Value = txtbox_Email.Text.ToString();
userProfile.Properties["GeneralInfo.user_security_password"].Value = txtbox_Password.Text.ToString();
userProfile.Properties["GeneralInfo.user_type"].Value = 1;
userProfile.Properties["GeneralInfo.language"].Value = “en-US”;
userProfile.Properties["GeneralInfo.password_question"].Value = txtbox_PasswordAns.Text.ToString();
userProfile.Properties["GeneralInfo.password_answer"].Value = txtbox_PasswordAns.Text.ToString();
userProfile.Properties["GeneralInfo.image"].Value = buffer;   
userProfile.Update();

 

If you would like to have multiple images for a profile then better to create a table for all profile images. Each entry will have a unique ID and image content. Create a data object in commerce server. Extend userObject to hold a array of user images – i.e., unique Ids(as similar to storing multiple address).

Categories
commerce server 2007
Tags
add images to profile, commerce server, extending profile sytem, Profile System
Comments rss
Comments rss
Trackback
Trackback

« Products without inventory Creating Discounts through code »

3 Responses to “Adding Image to Profile Sub-System”

  1. Kris says:
    September 17, 2008 at 9:28 am

    Hi,
    I tried the above steps but couldn’t work out. I am getting an error “The value System.Byte[] of the property GeneralInfo.UserImage is not of the correct data type Binary”. Please help on this.

    regards,
    Kris

    Reply
  2. commerceserver says:
    September 17, 2008 at 2:31 pm

    The answer to your problem will og if you change “personal_image” property data type from “binary” to “long binary” – and reset your IIS.

    -Ravi Kanth

    Reply
  3. commerceserver says:
    September 17, 2008 at 3:01 pm

    Can you download the code from the below link and check where you went wrong.

    http://cid-
    f348d7145d1be6c2.skydrive.live.com/self.aspx/Code/Extending%20User%20Profile.zip

    Many people tried this code and it worked well for them.

    -Ravi Kanth

    Reply

Leave a Reply

Click here to cancel reply.

Powered by WP Hashcash

Sign up for Newsletter


Categories

Quiz

  • Catalog Quiz for Beginners
  • Profile Quiz for Beginners
  • Quiz 1 for Advance Users
  • Quiz for Beginners

Recent Posts

  • RCXml2Resx.exe tool stops working
  • Commerce Server Profile Importer Tool
  • Marketing Web service Exception: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM
  • Download Commerce Server 2009 Help Document
  • Commerce Server 2009 work with SharePoint 2010?
  • Failed to set value for profile property ‘email_address’.
  • ArgumentException: An item with the same key has already been added.
  • Please note that one or more items were removed from your order because the product is no longer sold.
  • How to Avoid Duplicate Orders Numbers in Commerce Server
  • Error: Microsoft.Commerce.Contracts.Faults.ItemDoesNotExistFault

Archives

  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008

Tags

add discounts add images to profile Advantages of commerce server approve discounts authentication auto login process automatic user creation basket Brand Management business tools campaign management Catalog catalog import Category CategoryConfiguration commerce server commerce server 2007 commerce server manager Commerce Server SP2 discounts ecommerce Estimation Installation inventory Kanth Koppala marketing system migration error Mojave operation components operation sequence Order subsystem Product profile profile subsystem property metadata purchase order quick checkout Ravi Ravi Kanth site cache refresh starter site tools transactions error Variant
(c) 2009 Commerce Server Blog. All rights Reserved. Articles cannot be reproduced without permission from the author.Write to me at kanth@ravikanth.net if you have any comments, questions, suggestions about this site or would like to send us a tip
About Us | Terms of Use | Disclaimer | Advertise .