0

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;

      }
   }
halfer
  • 19,824
  • 17
  • 99
  • 186
skhurams
  • 2,133
  • 7
  • 45
  • 82
  • 2
    I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders May 14 '15 at 16:52
  • If it still uses HtmlAgilityPack under the hood than `imgsrc["src"].Value = "new value"` should do the trick – jessehouwing May 14 '15 at 18:10

2 Answers2

1

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
skhurams
  • 2,133
  • 7
  • 45
  • 82
0

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

Asim Shaikh
  • 159
  • 9