Add downloadable files to a product

To add a downloadable file to a product you must perform the following:

  1. Get instances of the following managers:
    • Libraries manager
      Note that you  must specify the manager to use the system libraries provider.
    • Catalog manager
    • Content links manager
  2. Get the document.
    Get an instance of the file that you want to add to the product. For more information, see For developers: Query documents.
  3. Get the product.
    Get an instance of the product that you want to add the file to. For more information, see For developers: Query products.
  4. Create a product file.
    Create an instance of the ProductFile class. This class wraps the information about the document and stores it in the product.
  5. Set the properties of the ProductFile instance.
    You must set the following properties:
    • Id
      Gets or sets the ID of the product file. You must set this property to the ID of the Document instance.
    • Title
      Gets or sets the title of the product file. You must set this property to the title of the Document instance.
    • FileSize
      Gets or sets the file size. You must set this property to the value for the TotalSize property of the Document instance.
    • FileName
      Gets or sets the name of the file. You must set this property to the value of the FilePath property of the Document instance.
    • UploadedDate
      Gets or sets the date when the product file has been uploaded. Set this property to the value of the DateCreated property of the Document instance.
    • Url
      Gets or sets the URL of the product file. Set this property to the value of the URL property of the Document instance.
  6. Add the product file.
    To add the product file instance to the product, use the Files collection property of the Product instance.
  7. Save the product.
    Save the changes to the catalog manager.
  8. Create a content link between the document and the product.
    To create a content link, call the CreateContentLink method of the ContentLinksManager instance. As componentPropertyName pass “ProductDocumentsAndFiles”, as parentDataItem pass the instance of the product, and as childDataItem pass the instance of the document.
  9. Save the content link.
    Save the changes to the content links manager.
  10. Publish the product.
    Publish the product by calling the MessageWorkflow method of the WorkflowManager class and pass the required parameters.

Use the following code sample:

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

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. 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?