This project is read-only.

Module Development Access Media Stored files

Topics: Administration, Core, Writing modules
Oct 21, 2014 at 11:43 AM
Edited Oct 21, 2014 at 12:46 PM
Hello guys
I'm working to develop my own module, for example i have list of music files stored in media folder i want let the user in admin panel to select the stored files to show using my custome view.
In other words how i can access and list files paths that's stored in media folder inside my module
i was checking inside core modules body there is featuer insert media item if i can use it in my code but i don't know how if someone can help me

Thanks in advance
Oct 22, 2014 at 12:24 AM
Since Media Items are content items, you might be able to achieve what you need by creating a Query that selects all content items of type Music assuming you defined such a content type)?

If you need more control, you can implement a custom widget and part driver that enumerates the Music content items, maybe taking in a source path whose Music items you wish to display. Or maybe that could be implemented as a Projection Filter so you don't have to write a custom widget.
Oct 23, 2014 at 9:43 AM
Actually i have custome Content Type that's show Custome View for Sample music files .. what i'm trying and working on is to implement custome content type
in the admin side, an admin can control which song files that's stored in media using "media-library-picker-field",
should be show in my custome view and set title for each category i have some problems to implement media-library-picker-field in my custome module i'm looking for documentation or examples that's can help me

Oct 23, 2014 at 9:49 AM
Here is Some Parts of my Code
 public class SampleRecord : ContentPartRecord
        public virtual string MainServiceMusicTitle { get; set; }
        public virtual string MainServiceVoiceTitle { get; set; }
        public virtual string MainServiceVisualsTitle { get; set; }
        public virtual string MainServiceScentTitle { get; set; }
        public virtual string MainServiceInteractiveTitle { get; set; }
        public virtual string MainServiceSystemTitle { get; set; }

        public virtual string Description { get; set; }

        public virtual string Category { get; set; }

        public virtual string SoundFilePath { get; set; }

        public virtual string SoundImgPath { get; set; }

    public class SamplePart : ContentPart<SampleRecord>
        public string MainServiceMusicTitle

            get { return Record.MainServiceMusicTitle; }
            set { Record.MainServiceMusicTitle = value; }
        public string MainServiceVoiceTitle

            get { return Record.MainServiceVoiceTitle; }
            set { Record.MainServiceVoiceTitle = value; }

        public string Description
            get { return Record.Description; }
            set { Record.Description = value; }
        public string MainServiceVisualsTitle

            get { return Record.MainServiceVisualsTitle; }
            set { Record.MainServiceVisualsTitle = value; }

        public string MainServiceScentTitle

            get { return Record.MainServiceScentTitle; }
            set { Record.MainServiceScentTitle = value; }

        public string MainServiceInteractiveTitle

            get { return Record.MainServiceInteractiveTitle; }
            set { Record.MainServiceInteractiveTitle = value; }

        public string MainServiceSystemTitle

            get { return Record.MainServiceSystemTitle; }
            set { Record.MainServiceSystemTitle = value; }

        public string Category
            get { return Record.Category; }
            set { Record.Category = value; }

        public string SoundFilePath
            get { return Record.SoundFilePath; }
            set { Record.SoundFilePath = value; }

        public string SoundImgPath
            get { return Record.SoundImgPath; }
            set { Record.SoundImgPath = value; }

    public class SamplesDriver : ContentPartDriver<SamplePart>
        protected override DriverResult Display(
            SamplePart part, string displayType, dynamic shapeHelper)

            return ContentShape("Parts_Samples", () => shapeHelper.Parts_Map(MainServiceMusicTitle: part.MainServiceMusicTitle,
                                                                             MainServiceVoiceTitle: part.MainServiceVoiceTitle,
                                                                             MainServiceVisualsTitle: part.MainServiceVisualsTitle,
                                                                             MainServiceScentTitle :part.MainServiceScentTitle,
                                                                             MainServiceInteractiveTitle: part.MainServiceInteractiveTitle,
                                                                             MainServiceSystemTitle :part.MainServiceSystemTitle,
                                                                             Description: part.Description,
                                                                             CategoryName: part.Category,
                                                                             SoundFilePath: part.SoundFilePath,
                                                                             SoundPhotoPath: part.SoundImgPath));

        protected override DriverResult Editor(SamplePart part, dynamic shapeHelper)

            return ContentShape("Parts_Samples_Edit",() => shapeHelper.EditorTemplate(
                                                                                        TemplateName: "Parts/Samples",
                                                                                        Model: part,
                                                                                        Prefix: Prefix));
        protected override DriverResult Editor(SamplePart part, IUpdateModel updater, dynamic shapeHelper)

            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
public class Migrations : DataMigrationImpl {

        public int Create() {
            // Creating table SampleRecord
            SchemaBuilder.CreateTable("SampleRecord", table => table
                .Column("MainServiceTitle", DbType.String)
                .Column("Category", DbType.String)
                .Column("SoundFilePath", DbType.String)
                .Column("SoundImgPath", DbType.String)

                                                               builder => builder.WithField("Sample",
                                                                   fieldBuilder => fieldBuilder.OfType("MediaLibraryPickerField")
                                                                                               .WithDisplayName("Samples Picker")));

            ContentDefinitionManager.AlterPartDefinition(typeof(SamplePart).Name, cfg => cfg.Attachable());

            return 1;
namespace Samples.Handlers
    public class SamplesHandler : ContentHandler
        public SamplesHandler(IRepository<SampleRecord> repository)
View Template Edit Admin Side:
@using Orchard.ContentManagement
@using Orchard.MediaLibrary.Fields
@using Orchard.Utility.Extensions;

@model Samples.Models.SamplePart


  //var field = (MediaLibraryPickerField)Model.Sample;
    var field = ((MediaLibraryPickerField)Model.Fields.Single(f => f.Name == "Samples")).MediaParts;
    var mediaUrl = (string)null;
    var altText = string.Empty;


<div id="tab-container">
            <li><a href="#main-Music">Music</a></li>
            <li><a href="#main-Voice">Voice</a></li>
            <li><a href="#main-Visuals">Visuals</a></li>
            <li><a href="#main-Scent">Scent</a></li>
            <li><a href="#main-Interactive">Interactive</a></li>
            <li><a href="#main-System">System</a></li>

    <div id="main-Music">

            <label class="sub" for="MainServiceMusicTitle">@T("Main Title")</label><br />
            @Html.TextBoxFor(m => m.MainServiceMusicTitle, new { @class = "text" })<br />
        <nav class="filter_nav">
                <li><a class="active" href="#" data-filter="#voice_samples .sample">ALL</a></li>
                <li><a href="#" data-filter="#voice_samples .sm_rock">ROCK</a></li>
                <li><a href="#" data-filter="#voice_samples .sm_country">COUNTRY</a></li>
        </nav><!-- /.filter_nav -->

        <section class="media-library-picker-field media-library-picker-field @name.HtmlClassify()">
            @foreach (var content in contents)
                    @Display(BuildDisplay(content, "Summary"))

    <div id="main-Voice">
            <label class="sub" for="MainServiceVoiceTitle">@T("Main Title")</label><br />
            @Html.TextBoxFor(m => m.MainServiceVoiceTitle, new { @class = "text" })<br />
    <div id="main-Visuals">
            <label class="sub" for="MainServiceVisualsTitle">@T("Main Title")</label><br />
            @Html.TextBoxFor(m => m.MainServiceVisualsTitle, new { @class = "text" })<br />
    <div id="main-Scent">
            <label class="sub" for="MainServiceScentTitle">@T("Main Title")</label><br />
            @Html.TextBoxFor(m => m.MainServiceScentTitle, new { @class = "text" })<br />
    <div id="main-Interactive">
            <label class="sub" for="MainServiceInteractiveTitle">@T("Main Title")</label><br />
            @Html.TextBoxFor(m => m.MainServiceInteractiveTitle, new { @class = "text" })<br />
    <div id="main-System">
            <label class="sub" for="MainServiceSystemTitle">@T("Main Title")</label><br />
            @Html.TextBoxFor(m => m.MainServiceSystemTitle, new { @class = "text" })<br />
<script language="javascript" type="text/javascript">
    $(function () {
Oct 23, 2014 at 9:50 AM
and i still get error that's related to Media Picker Library Fields:
Server Error in '/OrchardLocal' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0103: The name 'name' does not exist in the current context

Source Error:

Line 47:         </nav><!-- /.filter_nav -->
Line 48: 
Line 49:         <section class="media-library-picker-field media-library-picker-field @name.HtmlClassify()">
Line 50:             @foreach (var content in contents)
Line 51:             {
Oct 23, 2014 at 11:15 AM
You're trying to use a variable "name", that you've haven't initialized or declared.