I'm trying to retrieve image/attachment url from custom list, while I am fetching image url and passing to img tag then it returns true rather Image URL,like src="true" and i want it like src="http://abc.png"
private const string TitleColumn = "Title";
private const string Attchment = "Attachments";
var webUrl = SPContext.Current.Web.Url;
using (var site = new SPSite(webUrl))
{
using (var web = site.OpenWeb())
{
try
{
var List = web.Lists["SimpleList"];
var spQuery = new SPQuery
{
Query = "</Query><ViewFields><FieldRef Name=" + TitleColumn + "/><FieldRef Name=" + Attchment + "/>"
};
var Items = List.GetItems(spQuery);
if (Items != null && Items.Count > 0)
{
foreach (SPListItem item in Items)
{
var ImageLink = new SPFieldUrlValue(item[Attchment].ToString());
imageTag.Attributes.Add("src", ImageLink.Url);
imageDiv.Controls.Add(imageTag);//image added to image div
}
}
}
catch (Exception ex) { }
}
}
This approach works SSOM. How can I get the image url in sandbox solution SharePoint online CSOM?
Attchment, then put it likenew SPFieldUrlValue(item["Attchment"].ToString());