Uploading files to the “Downloadable goods” library

The only difference when uploading files to the “Downloadable goods” library, is that you must specify the manager to use the system libraries provider. The string representation of the provider is “SystemLibrariesProvider”. Here is an example of how to get the libraries manager with this provider:

string providerName = "SystemLibrariesProvider";
 
LibrariesManager librariesManager = LibrariesManager.GetManager(providerName);

For more information about uploading files to a regular library, see Creating 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 Querying the “Downloadable goods” library.

Here is a code example of uploading a file to the “Downloadable goods” library:

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);
}

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK