Copied to clipboard

Flag this post as spam?

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


  • lpastor 140 posts 19 karma points
    Feb 17, 2009 @ 23:30
    lpastor
    0

    How to get a path for file in media

    Hi

    I need to figure out how to get a path to my media file..

    I have upload some pdf and not I whant to create a link in page but it ... In C#

    have some code


    [quote]


    Media nm = new Media(mediaNumber); // now I have a media but I need a pdf path


    [/quote]

    I found somwhere somthing like

    string imagePath = nm.getProperty("umbracoFile").Value.ToString();

    is this going to give me that ????

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 18, 2009 @ 08:34
    Dirk De Grave
    1

    Hi lpastor,

    [code]string imagePath = nm.getProperty("umbracoFile").Value.ToString();[/code]

    will get the image path in /media/id/filename.ext format

    Regards,
    /Dirk

  • lpastor 140 posts 19 karma points
    Feb 18, 2009 @ 09:53
    lpastor
    0

    thanks chief =d>

  • lpastor 140 posts 19 karma points
    Feb 18, 2009 @ 10:01
    lpastor
    0

    One question ..

    is there a way to found a full path of image ..

    as you sad I'm going to get
    /media/id/filename.ext format

    but I need a full path c:\inetpubz\umbraco303\media\id\filename.ext format

    because I want to be sure is this file exist on drive?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 18, 2009 @ 10:04
    Dirk De Grave
    0

    Hi,

    Media files are always stored on disk! in .net, use Server.MapPath() to get filename on disk

    Regards,
    /Dirk

  • bob baty-barr 1180 posts 1294 karma points MVP
    Oct 09, 2009 @ 23:52
    bob baty-barr
    0

    i am getting an error the type or namespace media cannot be found... what references or 'using' statements am i missing??? i am so NEW to this -- sorry

  • skiltz 501 posts 701 karma points
    Oct 10, 2009 @ 00:10
    skiltz
    0

     

     

     

     

     

     

     

     

    public static string GetImagePath(int

    mediaId)

    {

     

     

    // Get the path to the image

     

     

    XPathNodeIterator xImage = umbraco.library.GetMedia(mediaId, true

    );

     

     

    XPathNodeIterator nodes = xImage.Current.Select("/node/data[@alias='umbracoFile']"

    );

     

    string path = string

    .Empty;

     

     

    while

    (nodes.MoveNext())

    {

    path = nodes.Current.Value;

     

     

    break

    ;

     

    }

     

     

    return

    path;

  • bob baty-barr 1180 posts 1294 karma points MVP
    Oct 10, 2009 @ 00:21
    bob baty-barr
    0

    okay, so Visual Studio has lots of tricks i have to learn :) I was able to fix that error by simply hitting 'Ctrl .' and it gave me a list of refrences that i 'MIGHT' be trying to use but have not included... so i simply clicked on the one i wanted and VIOLA -- everything passess error tests :)

    this is gonna be a fun winter :)

Please Sign in or register to post replies

Write your reply to:

Draft