skhurams
skhurams

Reputation: 2145

How to change all imageTag src path in CsQuery

How can I change all images "src" in a html string in CSQuery?

Here is my code:

 CQ HtmlContainingImg = html;
   CQ imgTagList =  HtmlContainingImg["IMG"];
  foreach (var img in imgTagList)
   { 
   string imgsrc = img.Attributes["src"];
    if (!IsAbsoluteUrl(imgsrc))
    {
    //img.Attributes["src", Setting.FelApplicationPath + Setting.folderPath + imgsrc];// this line gives error
   // even tried  img.Attributes["src"]= Setting.FelApplicationPath + Setting.folderPath + imgsrc;

      }
   }

Upvotes: 0

Views: 407

Answers (2)

skhurams
skhurams

Reputation: 2145

this worked for me

 CQ HtmlContainingImg = html;
    foreach (var img in HtmlContainingImg["IMG"])
       {
         string imgsrc = img.Attributes["src"];
         if (!IsAbsoluteUrl(imgsrc))
           {
  img.Attributes["src"]= Setting.FelApplicationPath + Setting.folderPath + imgsrc;
             }
       }
 html=  HtmlContainingImg.Render(); // I was missing this line

Upvotes: 1

Asim Shaikh
Asim Shaikh

Reputation: 169

Try img.SetAttribute("src",Setting.FelApplicationPath + Setting.folderPath + imgsrc);

Upvotes: 0

Related Questions