简体   繁体   中英

get image url from SharePoint genericlist with CSOM

I am trying to get the image url from a list but dont now how. the usual search on google didnt help. This is my code so far:

         using(var context = MySession.Current.spcontext.CreateAppOnlyClientContextForSPHost())
        {
            List<Produkt> produkter = new List<Produkt>();
            ListItemCollection listFromSharePoint = _foodRepo.RetriveList(context, PRODUKTER);
            foreach(ListItem items in listFromSharePoint)
            {
                Produkt oneItem = new Produkt();

                oneItem.bild = (string)items["Bild"];  <--Column name is "Bild" but how to get the url?
                produkter.Add(oneItem);
            }
            ViewBag.Produkter = produkter;
        }

image of what I want:

在此处输入图片说明

everything loads from sharepoint, but dont know how to reach the url. any ideas?

When accessing the itemvalues, they are always an object which has to be casted to the correct class:

using (ClientContext ctx = new ClientContext(url))
{
    Web web = ctx.Web;
    List list = web.Lists.GetById(listId);
    ListItem item = list.GetItemById(itemId);
    ctx.Load(item);
    ctx.ExecuteQuery();
    FieldUrlValue fieldValue = (FieldUrlValue)item["Bild"]; //<-- casting!
    string bildUrl = fieldValue.Url; //<-- here you can access the values
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM