Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:21:02+00:00 2026-06-10T11:21:02+00:00

I have a HTML inside a string variable, which contains some <img> tags. I

  • 0

I have a HTML inside a string variable, which contains some <img> tags. I want to replace the src attribute with data-realsrc attribute and put loading.gif in src attribute.

For example, if this is one of <img> tags:

<img src="Hello.jpg" />

I want to change it to:

<img data-realsrc="Hello.jpg" src="loading.gif" />

It should be applied to all <img> tags inside the HTML.

Please note that I want to do it server-side with c#.

How to do that?

What is the simplest way? What is the fastest way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:21:04+00:00Added an answer on June 10, 2026 at 11:21 am

    using HtmlAgilityPack

    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
    doc.LoadHtml(@"<img src=""Hello.jpg"" />");
    
    foreach (var img in doc.DocumentNode.Descendants("img"))
    {
        var realSource = img.Attributes["data-realsrc"];
    
        if (realSource != null)
            realSource.Value = img.Attributes["src"].Value;
        else
            img.Attributes.Add("data-realsrc", img.Attributes["src"].Value);
    
        img.Attributes["src"].Value = "loading.gif";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the deal. I have a string which contains a html <a><img /></a>
I have some HTML stored in a string which I parse using jQuery. The
I have the following variable which contains the following string. I would like to
In my app, I want to replace some variables inside an html file when
I have html with a submenu inside another submenu. What i want is on
I have an html td element with text inside. I want it so you
I have a HTML form that has certain fields which i am opening inside
I have PHP strings that have HTML inside of them, which I am storing
I have a div that contains some html and a lot of Javascript <div
I have a HTML-String and want to get the inner html of all tr's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.