+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to return a specific downloadable product/document.

How to return a specific downloadable product/document.

2 posts, 0 answered
  1. Keefe
    Keefe avatar
    1 posts
    Registered:
    04 Mar 2013
    19 Jul 2013
    Link to this post
    Does anyone know how to return a link or a stream to a downloadable product.

    I found this code in the documentation:

    public static DocumentLibrary GetDownloadableGoodsLibrary(){  
     string providerName = "SystemLibrariesProvider";   
    Guid downloadableGoodsId = new Guid("e5915e51-707e-4232-9830-68f2800067f8");    
    LibrariesManager librariesManager = LibrariesManager.GetManager(providerName);   
     DocumentLibrary downloadableGoods = librariesManager.GetDocumentLibraries().Where(d => d.Id == downloadableGoodsId).SingleOrDefault();    
    return downloadableGoods;
    }

    Can someone fill me in on how to get a specific downloadable document?

    Thanks
  2. Patrick Dunn
    Patrick Dunn avatar
    237 posts
    Registered:
    03 Nov 2014
    22 Jul 2013
    Link to this post
    Hi Keefe,

     The downloadable goods library is just a "system" library. It can be queried, along with its contents, like you would any other public library. The documentation you have is just how to get the entire library. So once you have it you can get documents a few different ways.

    Here's an example of a few ways.

    public string providerName = "SystemLibrariesProvider";
     
            public  DocumentLibrary GetDownloadableGoodsLibrary()
            {
                Guid downloadableGoodsId = new Guid("e5915e51-707e-4232-9830-68f2800067f8");
     
                LibrariesManager librariesManager = LibrariesManager.GetManager(providerName);
     
                DocumentLibrary downloadableGoods = librariesManager.GetDocumentLibraries().Where(d => d.Id == downloadableGoodsId).SingleOrDefault();
     
                return downloadableGoods;
            }
     
            public IQueryable<Document> GetDownloadableGoodsByLibrary(DocumentLibrary docLib)
            {
                return docLib.Documents();
            }
     
            public Document GetDownloadableGoodByTitle(string title)
            {
                var lm = LibrariesManager.GetManager(providerName);
                return lm.GetDocuments().Where(d => d.Title == title).FirstOrDefault();
            }
     
            public List<Document> GetDownloadableGoodsByProduct(Product product)
            {
                var returnList = new List<Document>();
                var lm = LibrariesManager.GetManager();
                foreach (var file in product.Files)
                {
                    var doc = lm.GetDocuments().Where(d => d.Title == file.Title).FirstOrDefault();
                    returnList.Add(doc);
                }
                return returnList;
            }

    I hope this helps.

    Regards,
    Patrick Dunn
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered