DownloadList with custom field

Posted by Community Admin on 04-Aug-2018 08:04

DownloadList with custom field

All Replies

Posted by Community Admin on 11-Nov-2013 00:00

Hi, 
I am new to sitefinity.

i want to create a widget to upload files and display files like downloadlist widget
and also i want to allow user to enter the title field to that library

suppose

i have a library category 1

in that i have file1, file2

and in category 1 i have another library and contains file3, file4

so i want to display the files like below and i selected category1 library in library option

Title
------------------------------
Category1
-file1
-file2
-Category2
    -file3
    -file4

please help
thanks in advance....

Posted by Community Admin on 12-Nov-2013 00:00

Hi Kumar,

My apologies, I don't think I'm exactly following what you need to do. Can you give me a step by step user story on how your custom widget will work?

Also, have you considered using the Digital Asset Manager for this task?

 - Drag & Drop Digital Asset Libraries

Regards,
David C
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

Posted by Community Admin on 12-Nov-2013 00:00

Hi David,

Thanks for reply. Actually i want to modify the Downloadlist but i have to allow the user to enter the title of this document list

means when displaying the uploaded file, i want to show it in tree view with bullet list.
the library name as title and its file under this as child  and if that library have another library then it i will also display in that and this sub library's files as its child as shown in the image which is attached

please find the attached image

    




Posted by Community Admin on 13-Nov-2013 00:00

Hi Kumar,

Please take a look at the following documentation: Documents and files. This will go into detail about how to use the Sitefinity API to create libraries and documents. 

I would recommend using Sitefinity Thunder to build a custom widget and then adding your code to create libraries and upload documents. Please note that Sitefinity doesn't have an upload component, so you will need code the upload dialog using C# or VB.Net.

Hopefully this helps. Please let us know if you have any additional questions. 

Regards,
David C
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

Posted by Community Admin on 15-Nov-2013 00:00

Hi David,

I created a widget like downloadlist using documents api

DownloadListsNewModel.cs
-------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Libraries.Model;
using Telerik.Sitefinity.Modules.Libraries;

namespace SitefinityWebApp.Mvc.Models

    public class DownloadListsNewModel
   
        public DownloadListsNewModel(IQueryable<Document> documents,List<DocumentLibrary>  librariesList)
       
            this.Items = documents;
            this.LibrariesList = librariesList;
       

        public IQueryable<Document> Items
         
            get;
            private set;
       
        public List<DocumentLibrary> LibrariesList
       
            get;
            private set;
       

        public string Title get; set;

   







DownloadListsNewController.cs
---------------------------------------------------------------------------


using SitefinityWebApp.Mvc.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Sitefinity;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Libraries.Model;
using Telerik.Sitefinity.Modules.Libraries;
using Telerik.Sitefinity.Mvc;


namespace SitefinityWebApp.Mvc.Controllers

    [ControllerToolboxItem(Name = "MVC DownloadList", Title = "MVC DownLoadList", SectionName = "MvcNewWidgets")]
    public class DownloadListsNewController:Controller
   
        public ActionResult Index()
       

            LibrariesManager librariesManager = LibrariesManager.GetManager();
            var documents= librariesManager.GetDocuments().Where(d => d.Status == ContentLifecycleStatus.Live);

            var documentsLibraries = App.WorkWith().DocumentLibraries().Get().Distinct().ToList();

            var documentsModel = new DownloadListsNewModel(documents,documentsLibraries )
           
                Title=this.Title
            ; 

            return View("DownloadListsNew", documentsModel);
       

        [Category("String Properties")]
        public string Titleget;set;


   



DownloadListsNew.cshtml
---------------------------------------------------------------------


@model SitefinityWebApp.Mvc.Models.DownloadListsNewModel
 
<div>
   <strong>@Html.Raw(Model.Title)</strong>

    @Html.Raw(Model.LibrariesList.Count)
    @foreach (var libraries in Model.LibrariesList )
   
       <strong>@Html.Raw(libraries.Title)</strong>
<ul>
     @foreach(var documents in Model.Items)
   
         if(libraries.Title==documents.Library.Title)
         
        <li>
            <strong>
              
                 <a class="sfdownloadTitle" href="@Url.Content( documents.MediaUrl)" target="_blank">@Html.Raw(documents.Title)</a>
            </strong>
            <p>
                @Html.Raw(documents.Library.Title)
            </p>
        </li>
         
   
</ul>
   

</div>

this is the code


and in this every files library name is showing only parent library name only if it is in the sub library also

but i want to display based on its library name as heading

and how to get the category and tag details of the file

please help .....

Posted by Community Admin on 18-Nov-2013 00:00

Hi Kumar,

I did a some more research on your question and there's one more step to getting your sub libraries content items. Your sub-libraries are not treated as libraries at all, but are actually organizational folders within your library.  For example:

Library 1
SubLibrary 1
SubLibrary 2
Library 2
SubLibrary 3

Only Library 1 and Library 2 are considered libraries. SubLibrary 1, SubLibrary 2, etc... are considered folders within each library. 

Take a look at the following documentation, especially item #3, for more info on how to get sub folders and sub items.

Here's a quick sample of how you could do it in a foreach loop, though.

foreach(var library in documentLibraries)

var childItemsUnderFolder = librariesManager.GetChildFolders(library);

foreach (var subLibrary in childItemsUnderFolder)

var subLibraryItems = librariesManager.GetAncestorItems(subLibrary);



From there you will probably have to construct your own libraries and library items list to make it all manageable in your view. 

Take a look at this forum post about how to get associated taxonomies from a document.

Regards,
David C
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

This thread is closed