Upload files to the Downloadable goods library

NEW TO SITEFINITY?

When you upload files to the Downloadable goods library, to use the system libraries provider, you must specify the manager. The string representation of the provider is “SystemLibrariesProvider”.

For more information about uploading files to a media library, see For developers: Create documents.

NOTE: When you work with the Downloadable goods library, you must always use the libraries manager with the system libraries provider.

For more information about how to get an instance of the Downloadable goods library, see For developers: Query the Downloadable goods library.

To upload a file to the Downloadable goods library, use the following code sample:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Telerik.Sitefinity.Libraries.Model;
using Telerik.Sitefinity.Modules.Libraries;
using Telerik.Sitefinity.Workflow;
namespace SitefinityWebApp
{
public class UploadFileToDownloadableGoodsLibrary
{
public static void UploadFileToDownloadableGoods(string fileTitle, Stream fileStream, string fileExtension)
{
string providerName = "SystemLibrariesProvider";
Guid downloadableGoodsId = new Guid("e5915e51-707e-4232-9830-68f2800067f8");
LibrariesManager librariesManager = LibrariesManager.GetManager(providerName);
//Create the document.
var document = librariesManager.CreateDocument();
//Get the downloadable goods library.
DocumentLibrary downloadableGoods = librariesManager.GetDocumentLibraries().Where(d => d.Id == downloadableGoodsId).SingleOrDefault();
//Set the library.
document.Parent = downloadableGoods;
document.Title = fileTitle;
document.DateCreated = DateTime.UtcNow;
document.PublicationDate = DateTime.UtcNow;
document.LastModified = DateTime.UtcNow;
document.UrlName = Regex.Replace(fileTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
librariesManager.Upload(document, fileStream, fileExtension);
librariesManager.SaveChanges();
var bag = new Dictionary<string, string>();
bag.Add("ContentType", typeof(Telerik.Sitefinity.Libraries.Model.Document).FullName);
WorkflowManager.MessageWorkflow(document.Id, typeof(Document), null, "Publish", false, bag);
}
}
}

Want to learn more?

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?