Add images to a product

To add an image to a product, you must perform the following:

  1. Get instances of the following managers:
    • Catalog manager
    • Libraries manager
    • Content links manager
  2. Get an instance of the product. 
    For more information, see For developers: Query products.
  3. Get an instance of the image. 
    The image of a product is represented by a Sitefinity CMS image.
    For more information about uploading images in Sitefinity CMS, see For developers: CRUD operations with images.
  4. Create an instance of the ProductImage class.
  5. Set the properties of the product image to the respective values of the Sitefinity CMS image.

    NOTE: The primary image of a product must have its Ordinal property set to 0. The other images must have their Ordinal properties set to 1, 2, 3, etc. You can only have one primary image per product. 
    In the code example below, the first image is assigned as the primary one. For more information, see For developers: Change the primary image of a product.

  6. Add the product image to the product.
    Add the ProductImage instance to the Images collection of the product.
  7. Save the changes to the product manager.
  8. Create a content link.
    To create a content link between the product and the image, call the CreateContentLink method of the content links manager and pass the product and the image as arguments. For example, as componentPropertyName, pass ProductImage.
  9. Set the ordinal of the content link.

    IMPORTANT: Set the Ordinal property of the content link to the same value as the Ordinal property of the product image.

  10. Save the changes to the content links manager.

Code example: Add images to a product

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?