简体   繁体   中英

How to catch image url using c#

I am making a web application.

In main page I want to show some items in Sharepoint List.

So I saved content data(Included text and image source url) and tried to show it.

But I don`t know how to catch image source url.

My Code is Like this.

string itemBody = string.Empty;
//listItemCol is SPListItemCollection
itemBody = listItemCol[i]["Body"] == null ? "" : listItemCol[i]["Body"].ToString();

I checked itemBody, and it contained this data.

<div class="ExternalClass0E1F6FC2B36A47AEB474512CAE7D8B6E">
   <p><img alt="group-news__thumb.jpg" src="/SiteAssets/Lists/Announcement/AllItems/group-news__thumb.jpg" style="margin&#58;5px;" />&#160;</p>
   <p>News TEST</p>
   <p>&#160;</p>
</div>

How can I get that image source using c#? Please help me

You can try this.

int stratIndex = itemBody.IndexOf("src=\"");
int endIndex = itemBody.IndexOf("\"", stratIndex + 5);
string result = itemBody.Substring(stratIndex + 5, endIndex - stratIndex - 5);

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