Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi, I am new to Umbraco so I might be doing something wrong here but seems fairly straight forward.
I have a user control with a repeater on it. It displays text and an image. When each item binds it calls a function to get the image for the ID.
<td valign="top" style='width: 235px; height: 235px padding: 10px; background-image: url(<%# getImage(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "Recipe Image"))) %>);'>
The function getImage() returns this value: /media/16056/ice_cream_cookie_sandwich.jpg20121540112jpg
public string getImage(int ImageID) { var media = umbraco.library.GetMedia(ImageID, false); if (media != null && media.Current != null) { media.MoveNext(); return media.Current.Value; } return ""; }
Any ideas why the filename has the extra numbers appended to it? I could substring these but have to believe there is a better way. Thanks
Andrew
in your var statement for media... add /umbracoFile -- see if that get's you the right path.
Thanks, that helped me along the right path. I ended up search for both your tip and the getmedia and found this
http://forum.umbraco.org/yaf_postst4929_Getmedia-in-usercontrol.aspx
Here is what I am now using:
public string getImage(int ImageID) { XPathNodeIterator xn = umbraco.library.GetMedia(ImageID, false); xn.MoveNext(); XPathNodeIterator xn2 = xn.Current.Select("data[@alias='umbracoFile']"); xn2.MoveNext(); return xn2.Current.Value; }
Here's an update for the latest schema
var xpNodeIter = umbraco.library.GetMedia(ImageID,false); xpNodeIter.MoveNext(); var xpNodeIter2 = xpNodeIter.Current.Select("umbracoFile"); xpNodeIter2.MoveNext(); var imageUrl = xpNodeIter2.Current.Value;
is working on a reply...
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.
Continue discussion
Image path from umbraco.library.GetMedia is wrong
Hi, I am new to Umbraco so I might be doing something wrong here but seems fairly straight forward.
I have a user control with a repeater on it. It displays text and an image. When each item binds it calls a function to get the image for the ID.
<td valign="top" style='width: 235px; height: 235px padding: 10px; background-image: url(<%# getImage(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "Recipe Image"))) %>);'>
The function getImage() returns this value: /media/16056/ice_cream_cookie_sandwich.jpg20121540112jpg
public string getImage(int ImageID)
{
var media = umbraco.library.GetMedia(ImageID, false);
if (media != null && media.Current != null)
{
media.MoveNext();
return media.Current.Value;
}
return "";
}
Any ideas why the filename has the extra numbers appended to it? I could substring these but have to believe there is a better way. Thanks
Andrew
in your var statement for media... add /umbracoFile -- see if that get's you the right path.
Thanks, that helped me along the right path. I ended up search for both your tip and the getmedia and found this
http://forum.umbraco.org/yaf_postst4929_Getmedia-in-usercontrol.aspx
Here is what I am now using:
public string getImage(int ImageID)
{
XPathNodeIterator xn = umbraco.library.GetMedia(ImageID, false);
xn.MoveNext();
XPathNodeIterator xn2 = xn.Current.Select("data[@alias='umbracoFile']");
xn2.MoveNext();
return xn2.Current.Value;
}
Here's an update for the latest schema
var xpNodeIter = umbraco.library.GetMedia(ImageID,false);
xpNodeIter.MoveNext();
var xpNodeIter2 = xpNodeIter.Current.Select("umbracoFile");
xpNodeIter2.MoveNext();
var imageUrl = xpNodeIter2.Current.Value;
is working on a reply...
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.