Getmedia in usercontrol Options
isbel
Posted: Wednesday, May 14, 2008 11:46:13 PM
Rank: Newbie

Joined: 5/14/2008
Posts: 1
Hi

A webusercontrol makes this call to get the path to a document:

Private iter As XPathNodeIterator
iter = umbraco.library.GetMedia(1113, False)
strPath = iter.Current.SelectSingleNode("/node/data [@alias='umbracoFile']").InnerXml

When debugging in VS or running the installed macro in the localhost I get this result:

Position=0, Current="Root"
InnerXML : "<error>No media is maching '1113'</error>"

The id is valid and tested using a XSLT macro returns the expected path:

...
<xsl:value-of select="umbraco.library:GetMedia(1113, 'false')/data [@alias = 'umbracoFile']"/>
...

Thanks for all your help!
imayat12
Posted: Thursday, May 15, 2008 1:27:07 PM

Rank: Addict

Joined: 7/19/2006
Posts: 542
Location: Preston, UK
isbel,

here is some c# code that does something similar :

Code:


XPathNodeIterator xn = umbraco.library.GetMedia(1113, false);
xn.MoveNext();

string url = "";
XPathNodeIterator xn2 = xn.Current.Select("data[@alias='umbracoFile']");
xn2.MoveNext()
url = xn2.Current.Value;



I have not tested the above code but i have something similar full code is

Code:


        /// <summary>
        /// for given node id get the url
        /// </summary>
        /// <param name="NodeID">NodeID could be node or media</param>
        /// <returns></returns>
        public static string GetNodeURL(string NodeID) {
            int nodeid = int.Parse(NodeID);
            string url = umbraco.library.NiceUrl(nodeid);
            //assume its media
            if (url.Length == 0) {
               
                XPathNodeIterator ni = umbraco.library.GetMedia(nodeid, false);
                while (ni.MoveNext())
                {
                    XPathNavigator navCurrent = ni.Current;
                    url = getURL(navCurrent);
                }
            }
            return url;
        }

        /// <summary>
        /// for media node get url by traversing the data node
        /// </summary>
        /// <param name="current"></param>
        /// <returns></returns>
        private static string getURL(XPathNavigator current)
        {
            // Clone navigator to move off axis.

            XPathNavigator member = current.Clone();
            string url = "";
            XPathNodeIterator xn = member.Select("data[@alias='umbracoFile']");
            while (xn.MoveNext())
            {

                url = xn.Current.Value;
            }

            return url;

        }




hope this helps.

Level 2 certified. If it aint broke dont fix.
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.