IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
To add a downloadable file to a product you must perform the following:
Here is a code example:
public
static
void
AddDownloadableFileToProduct(Guid productId, Guid documentId)
{
string
providerName =
"SystemLibrariesProvider"
;
CatalogManager catalogManager = CatalogManager.GetManager();
LibrariesManager librariesManager = LibrariesManager.GetManager(providerName);
ContentLinksManager contentLinksManager = ContentLinksManager.GetManager();
Product product = catalogManager.GetProduct(productId);
Document document = librariesManager.GetDocument(documentId);
ProductFile file =
new
ProductFile();
file.Id = document.Id;
file.Title = document.Title;
file.FileSize = document.TotalSize.ToString();
file.FileName = document.FilePath;
file.UploadedDate = document.DateCreated.ToString();
file.Url = document.Url;
product.Files.Add(file);
catalogManager.SaveChanges();
ContentLink contentLink = contentLinksManager.CreateContentLink(
"ProductFile"
, product, document);
contentLinksManager.SaveChanges();
}
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important