Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • loic ponchon 36 posts 56 karma points
    Aug 01, 2011 @ 13:53
    loic ponchon
    0

    Get media associated to the content

    Hello,

    I got a content as an article.

    I associated a picture to this one, and i can't get it.

    Just the one associated to this content.

    I need to get the media associated to this content.

    Thank you in advance

  • Toni Becker 146 posts 425 karma points
    Aug 01, 2011 @ 14:09
    Toni Becker
    0

    Please post your XML from umbraco.config so we can see the structure of your file.

  • loic ponchon 36 posts 56 karma points
    Aug 01, 2011 @ 14:10
    loic ponchon
    0
    <?xml version="1.0" encoding="utf-8" ?>
    <settings>
        <content>
            <imaging>
                <!-- what file extension that should cause umbraco to create thumbnails -->
                <imageFileTypes>jpeg,jpg,gif,bmp,png,tiff,tif</imageFileTypes>
                <!-- what attributes that are allowed in the editor on an img tag -->
                <allowedAttributes>alt,border,class,style,align,id,name,onclick,usemap</allowedAttributes>
            </imaging>
            <scripteditor>
                <!-- Path to script folder - no ending "/" -->
                <scriptFolderPath>/scripts</scriptFolderPath>
                <!-- what files can be opened/created in the script editor -->
                <scriptFileTypes>js,xml</scriptFileTypes>
                <!-- disable the codepress editor and use a simple textarea instead -->
                <!-- note! codepress editor always disabled in IE due to automatic hyperlinking "feature" in contenteditable areas -->
                <scriptDisableEditor>false</scriptDisableEditor>
            </scripteditor>

            <!-- should umbraco store the uploaded files like /media/xxx/filename.ext or like /media/xxx-filename.ext
    should be set to false if the aspnet account hasn't got readrights of the driveroot up to the /media directory -->
            <UploadAllowDirectories>True</UploadAllowDirectories>
            <errors>
                <!-- the id of the page that should be shown if the page is not found -->
                <!--        <errorPage culture="default">1</errorPage>-->
                <!--        <errorPage culture="en-US">200</errorPage>-->
                <error404>1</error404>
            </errors>
            <notifications>
                <!-- the email that should be used as from mail when umbraco sends a notification -->
                <email>your@email.here</email>
            </notifications>

            <!-- if true umbraco will ensure that no page under the same parent has an identical name -->
            <ensureUniqueNaming>True</ensureUniqueNaming>

            <!-- lowercase, either 'gif' or 'png' -->
            <graphicHeadlineFormat>gif</graphicHeadlineFormat>

            <!-- clean editor content with use of tidy -->
            <TidyEditorContent>True</TidyEditorContent>

            <!-- the encoding type for tidy. Default is UTF8, options are ASCII, Raw, Latin1, UTF8, ISO2022, MacroMan-->
            <TidyCharEncoding>UTF8</TidyCharEncoding>

            <!-- to enable new content schema, this needs to be false -->
            <UseLegacyXmlSchema>false</UseLegacyXmlSchema>

            <!-- Whether to force safe aliases (no spaces, no special characters) at businesslogic level on contenttypes and propertytypes -->
            <!-- HIGHLY recommend to keep this to true to ensure valid and beautiful XML Schemas -->
            <ForceSafeAliases>true</ForceSafeAliases>

            <!-- Enable / disable xml content cache -->
            <XmlCacheEnabled>True</XmlCacheEnabled>

            <!-- Update disk cache every time content has changed -->
            <ContinouslyUpdateXmlDiskCache>True</ContinouslyUpdateXmlDiskCache>

            <!-- Show the /config/splashes/booting.aspx page while initializing content -->
            <EnableSplashWhileLoading>False</EnableSplashWhileLoading>

            <!-- Show property descriptions in editing view "icon|text|none" -->
            <PropertyContextHelpOption>text</PropertyContextHelpOption>

            <!-- The html injected into a (x)html page if Umbraco is running in preview mode -->
            <PreviewBadge><![CDATA[<a id="umbracoPreviewBadge" style="position: absolute; top: 0; right: 0; border: 0; width: 149px; height: 149px; background: url('{1}/preview/previewModeBadge.png') no-repeat;" href="{0}/endPreview.aspx?redir={2}"><span style="display:none;">In Preview Mode - click to end</span></a>]]></PreviewBadge>

            <!-- Cache cycle of Media and Member data fetched from the umbraco.library methods -->
            <!-- In seconds. 0 will disable cache -->
            <UmbracoLibraryCacheDuration>1800</UmbracoLibraryCacheDuration>
        </content>

        <requestHandler>
            <!-- this will ensure that urls are unique when running with multiple root nodes -->
            <useDomainPrefixes>false</useDomainPrefixes>
            <!-- this will add a trailing slash (/) to urls when in directory url mode -->
            <addTrailingSlash>true</addTrailingSlash>
            <urlReplacing removeDoubleDashes="true">
                <char org=" ">-</char>
                <char org="&quot;"></char>
                <char org="%"></char>
                <char org="."></char>
                <char org=";"></char>
                <char org="/"></char>
                <char org=":"></char>
                <char org="#"></char>
                <char org="+">plus</char>
                <char org="*">star</char>
                <char org="&amp;"></char>
                <char org="?"></char>
                <char org="æ">ae</char>
                <char org="ø">oe</char>
                <char org="å">aa</char>
                <char org="ä">ae</char>
                <char org="ö">oe</char>
                <char org="ü">ue</char>
                <char org="ß">ss</char>
                <char org="Ä">ae</char>
                <char org="Ö">oe</char>
            </urlReplacing>
        </requestHandler>

        <templates>
            <useAspNetMasterPages>true</useAspNetMasterPages>
        </templates>


        <!-- this is used by Umbraco to determine if there's valid classes in the /App_Code folder to be used for Rest/XSLT extensions -->
        <developer>
            <appCodeFileExtensions>
                <ext>cs</ext>
                <ext>vb</ext>
            </appCodeFileExtensions>
        </developer>

        <scripting>
            <razor>
                <!-- razor DynamicNode typecasting detects XML and returns DynamicXml - Root elements that won't convert to DynamicXml -->
                <notDynamicXmlDocumentElements>
                    <element>p</element>
                    <element>div</element>
                </notDynamicXmlDocumentElements>
            </razor>
        </scripting>

        <!-- This moves the asp.net viewstate data to the end of the html document instead of having it in the beginning-->
        <viewstateMoverModule enable="false" />

        <logging>
            <enableLogging>true</enableLogging>
            <enableAsyncLogging>true</enableAsyncLogging>
            <disabledLogTypes>
                <!-- <logTypeAlias>[alias-of-log-type-in-lowercase]</logTypeAlias> -->
            </disabledLogTypes>
            <!-- You can add your own logging tool by implementing the umbraco.BusinessLogic.Interfaces.ILog interface and add the reference here -->
            <!-- The external logger can also act as the audit trail storage by setting the logAuditTrail attribute to true -->
            <!--<externalLogger assembly="~/bin/assemblyFileName.dll" type="fully.qualified.namespace.and.type" logAuditTrail="false" /> -->
        </logging>

        <scheduledTasks>
            <!-- add tasks that should be called with an interval (seconds) -->
            <!--    <task log="true" alias="test60" interval="60" url="http://localhost/umbraco/test.aspx"/>-->
        </scheduledTasks>

        <!-- distributed calls make umbraco use webservices to handle cache refreshing -->
        <distributedCall enable="false">
            <!-- the id of the user who's making the calls -->
            <!-- needed for security, umbraco will automatically look up correct login and passwords -->
            <user>0</user>
            <servers>
                <!-- add ip number or hostname, make sure that it can be reached from all servers -->
                <!-- <server>127.0.0.1</server>-->
            </servers>
        </distributedCall>

        <!-- configuration for webservices -->
        <!-- webservices are disabled by default. Set enable="True" to enable them -->
        <webservices enabled="False">
            <!-- You must set user-rights for each service. Enter the usernames seperated with comma (,) -->
            <documentServiceUsers>your-username</documentServiceUsers>
            <fileServiceUsers>your-username</fileServiceUsers>
            <stylesheetServiceUsers>your-username</stylesheetServiceUsers>
            <memberServiceUsers>your-username</memberServiceUsers>
            <templateServiceUsers>your-username</templateServiceUsers>
            <!-- type of files (extensions) that are allowed for the file service -->
            <fileServiceFolders>css,xslt</fileServiceFolders>
        </webservices>

        <!-- Configuration for repositories -->
        <!-- Add or remove repositories here. You will need the repository's unique key to be able to connect to it.-->
        <repositories>
            <repository name="Umbraco package Repository" guid="65194810-1f85-11dd-bd0b-0800200c9a66" />
        </repositories>

        <providers>
            <users>
                <!-- if you wish to use your own membershipprovider for authenticating to the umbraco back office -->
                <!-- specify it here (remember to add it to the web.config as well) -->
                <DefaultBackofficeProvider>MyADMembershipProvider</DefaultBackofficeProvider>
            </users>
        </providers>

        <!-- Maps language, usertype, application and application_url to help pages -->
        <help defaultUrl="http://our.umbraco.org/wiki/umbraco-help/{0}/{1}">
            <!-- Add links that should open custom help pages -->
            <!--<link application="content" applicationUrl="dashboard.aspx"  language="en" userType="Administrators" helpUrl="http://www.xyz.no?{0}/{1}/{2}/{3}" /> -->
        </help>

    </settings>
  • Toni Becker 146 posts 425 karma points
    Aug 01, 2011 @ 14:18
    Toni Becker
    0

    Hehe not the web.config :) the umbraco.config in the folder App_Data/

    Here's the XML cache saved and your Document Structure. :)

  • loic ponchon 36 posts 56 karma points
    Aug 01, 2011 @ 14:21
    loic ponchon
    0

    It'sz the umbracoSetting.config

    It was strange you asked me for that ^^

     

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE root
    <!ELEMENT directory ANY>
    <!ATTLIST directory id ID #REQUIRED>
    <!ELEMENT DirectoryContactSheet ANY>
    <!ATTLIST DirectoryContactSheet id ID #REQUIRED>
    <!ELEMENT Homepage ANY>
    <!ATTLIST Homepage id ID #REQUIRED>
    <!ELEMENT Libraries ANY>
    <!ATTLIST Libraries id ID #REQUIRED>
    <!ELEMENT Login ANY>
    <!ATTLIST Login id ID #REQUIRED>
    <!ELEMENT MediaDocument ANY>
    <!ATTLIST MediaDocument id ID #REQUIRED>
    <!ELEMENT MediaPhoto ANY>
    <!ATTLIST MediaPhoto id ID #REQUIRED>
    <!ELEMENT MediaVideo ANY>
    <!ATTLIST MediaVideo id ID #REQUIRED>
    <!ELEMENT News ANY>
    <!ATTLIST News id ID #REQUIRED>
    <!ELEMENT NewsArticleDocument ANY>
    <!ATTLIST NewsArticleDocument id ID #REQUIRED>
    <!ELEMENT NewsArticlePhoto ANY>
    <!ATTLIST NewsArticlePhoto id ID #REQUIRED>
    <!ELEMENT NewsArticleVideo ANY>
    <!ATTLIST NewsArticleVideo id ID #REQUIRED>

    ]>
    <root id="-1">
      <Login id="1180" parentID="-1" level="1" writerID="0" creatorID="0" nodeType="1178" template="1177" sortOrder="0" createDate="2011-07-29T16:19:44" updateDate="2011-08-01T12:26:07" nodeName="Login" urlName="login" writerName="lponchon" creatorName="lponchon" path="-1,1180" isDoc="">
        <Homepage id="1192" parentID="1180" level="2" writerID="0" creatorID="0" nodeType="1058" template="1125" sortOrder="1" createDate="2011-08-01T12:24:24" updateDate="2011-08-01T12:26:07" nodeName="Home" urlName="home" writerName="lponchon" creatorName="lponchon" path="-1,1180,1192" isDoc="">
          <bodyText><![CDATA[]]></bodyText>
          <siteName>Total Business</siteName>
          <siteDescription><![CDATA[A share point for all employees]]></siteDescription>
          <generic />
        </Homepage>
        <News id="1193" parentID="1180" level="2" writerID="0" creatorID="0" nodeType="1059" template="1124" sortOrder="1" createDate="2011-08-01T12:24:24" updateDate="2011-08-01T12:26:07" nodeName="News" urlName="news" writerName="lponchon" creatorName="lponchon" path="-1,1180,1193" isDoc="">
          <NewsArticleDocument id="1194" parentID="1193" level="3" writerID="0" creatorID="0" nodeType="1128" template="1123" sortOrder="1" createDate="2011-08-01T12:24:24" updateDate="2011-08-01T12:26:07" nodeName="Manual utilisateur d'umbraco" urlName="manual-utilisateur-d'umbraco" writerName="lponchon" creatorName="lponchon" path="-1,1180,1193,1194" isDoc="">
            <name>Manual utilisateur umbraco</name>
            <pdf>/media/352/umbraco_v4_-_manuel_de_l_utilisateur_v1.0.0.pdf</pdf>
            <descriptionText><![CDATA[
    <p>un super pdf sur l'utilisation utilisateur d'umbraco</p>
    ]]></descriptionText>
          </NewsArticleDocument>
          <NewsArticlePhoto id="1195" parentID="1193" level="3" writerID="0" creatorID="0" nodeType="1130" template="1121" sortOrder="2" createDate="2011-08-01T12:24:24" updateDate="2011-08-01T12:26:07" nodeName="Hadra" urlName="hadra" writerName="lponchon" creatorName="lponchon" path="-1,1180,1193,1195" isDoc="">
            <photo>1175</photo>
            <name>Hadra</name>
            <aa />
            <qsd />
            <content />
            <contentText><![CDATA[
    <p>Contenue du hadra</p>
    ]]></contentText>
            <description />
            <descriptionText><![CDATA[
    <p>Description du hadra</p>
    ]]></descriptionText>
          </NewsArticlePhoto>
          <NewsArticleVideo id="1196" parentID="1193" level="3" writerID="0" creatorID="0" nodeType="1132" template="1122" sortOrder="3" createDate="2011-08-01T12:24:25" updateDate="2011-08-01T12:26:07" nodeName="Article Video" urlName="article-video" writerName="lponchon" creatorName="lponchon" path="-1,1180,1193,1196" isDoc="">
            <name>Video sample test</name>
            <content />
            <contentText><![CDATA[
    <p>video content</p>
    ]]></contentText>
            <description />
            <descriptionText><![CDATA[
    <p>super description d'une video inutile</p>
    ]]></descriptionText>
            <video>/media/367/downloadhelper_-_media_download_firefox_extension.flv</video>
          </NewsArticleVideo>
        </News>
        <Libraries id="1197" parentID="1180" level="2" writerID="0" creatorID="0" nodeType="1114" template="1113" sortOrder="2" createDate="2011-08-01T12:24:25" updateDate="2011-08-01T12:26:07" nodeName="Libraries" urlName="libraries" writerName="lponchon" creatorName="lponchon" path="-1,1180,1197" isDoc="">
          <MediaDocument id="1198" parentID="1197" level="3" writerID="0" creatorID="0" nodeType="1162" template="1161" sortOrder="1" createDate="2011-08-01T12:24:25" updateDate="2011-08-01T12:26:07" nodeName="Document" urlName="document" writerName="lponchon" creatorName="lponchon" path="-1,1180,1197,1198" isDoc="" />
          <MediaVideo id="1199" parentID="1197" level="3" writerID="0" creatorID="0" nodeType="1164" template="1160" sortOrder="2" createDate="2011-08-01T12:24:25" updateDate="2011-08-01T12:26:08" nodeName="Video" urlName="video" writerName="lponchon" creatorName="lponchon" path="-1,1180,1197,1199" isDoc="" />
          <MediaPhoto id="1200" parentID="1197" level="3" writerID="0" creatorID="0" nodeType="1163" template="1159" sortOrder="3" createDate="2011-08-01T12:24:25" updateDate="2011-08-01T12:26:08" nodeName="Photo" urlName="photo" writerName="lponchon" creatorName="lponchon" path="-1,1180,1197,1200" isDoc="" />
        </Libraries>
        <directory id="1201" parentID="1180" level="2" writerID="0" creatorID="0" nodeType="1133" template="1111" sortOrder="3" createDate="2011-08-01T12:24:25" updateDate="2011-08-01T12:26:08" nodeName="Directory" urlName="directory" writerName="lponchon" creatorName="lponchon" path="-1,1180,1201" isDoc="">
          <DirectoryContactSheet id="1202" parentID="1201" level="3" writerID="0" creatorID="0" nodeType="1135" template="1112" sortOrder="1" createDate="2011-08-01T12:24:25" updateDate="2011-08-01T12:26:08" nodeName="Directory Contact Sheet" urlName="directory-contact-sheet" writerName="lponchon" creatorName="lponchon" path="-1,1180,1201,1202" isDoc="" />
        </directory>
      </Login>
    </root>
  • Toni Becker 146 posts 425 karma points
    Aug 01, 2011 @ 14:28
    Toni Becker
    0

    Okay you can do the following so i would do that:
    Create a new Script with Macro:

    For example you have a Template named RenderMyNewsArea.master here you can insert the new macro called e.g. "MyNewsRender"

    Than inside the Macro you could use:

    @using umbraco.MacroEngines
    //Where sitting on the Node "News" and get all the Children
    //Just outputting the url first for the File if it*s not working than you can use NiceUrl on the Node

    @foreach(var c in Model.NewsArticlePhoto) {
       <p>@c.photo</p> @* Just to look if it's accesing the Data
       <img src="@c.photo" alt=""/>
    }

     

    Try this out. If it's not working i will rebuild your structure and test it out locally on my PC

     

  • loic ponchon 36 posts 56 karma points
    Aug 02, 2011 @ 10:54
    loic ponchon
    0

    Doesn't work. It find nothing, How can i get intellisence via visual studio ?

  • Dwight Demmers 4 posts 25 karma points
    Aug 24, 2011 @ 15:32
    Dwight Demmers
    0

    c.photo is an Id if you put that in the source it wouldn't work. Instead of that try the following code:

    @using umbraco.cms.businesslogic.media;

    @{

    foreach(var c in Model.NewsArticlePhoto)

    //Convert the Id into a media object
    Media thePhoto = new Media(c.photo);

      <img src="@thePhoto" alt="" />
    }
    }

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies