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 571523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:30:58+00:00 2026-05-13T13:30:58+00:00

I’m working on an ASP.NET (C#) web project that is using master pages. I’m

  • 0

I’m working on an ASP.NET (C#) web project that is using master pages.

I’m looking for an easy way to display a random customer quote each time a page is loaded.

Since this is a fairly simple web project I’d like to stay away from storing the quotes in a database. Currently there is no database connections required for the project so I’d like to keep it as simple as possible — perhaps storing the quotes in an XML file them using an XmlTextReader to read the file?

Any advice is appreciated.

Thanks

Edit: I will need to store and pull both a quote and a customer name for the quote.

  • 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-05-13T13:30:59+00:00Added an answer on May 13, 2026 at 1:30 pm

    It could be something as simple as this with LINQ:

    XElement xml = new XElement("quotes",
        new XElement("quote",
            new XElement("customer", "Customer #1"),
            new XElement("text", "Quote #1")),
        new XElement("quote",
            new XElement("customer", "Customer #2"),
            new XElement("text", "Quote #2")),
        new XElement("quote",
            new XElement("customer", "Customer #3"),
            new XElement("text", "Quote #3")),
        new XElement("quote",
            new XElement("customer", "Customer #4"),
            new XElement("text", "Quote #4")),
        new XElement("quote",
            new XElement("customer", "Customer #5"),
            new XElement("text", "Quote #5"))
    );
    
    //XElement xml = XElement.Load("filename"); // use file instead of above
    var result = xml.Elements()
                    .OrderBy(r => System.Guid.NewGuid())
                    .Select(element => new { 
                            Customer = element.Element("customer").Value,
                            Quote = element.Element("text").Value
                        })
                    .First();
    
    Console.WriteLine("{0} : {1}", result.Customer, result.Quote);    
    

    Your file would be structured like this:

    <quotes>
      <quote>
        <customer>Customer #1</customer>
        <text>Quote #1</text>
      </quote>
      <quote>
        <customer>Customer #2</customer>
        <text>Quote #2</text>
      </quote>
      <quote>
        <customer>Customer #3</customer>
        <text>Quote #3</text>
      </quote>
      <quote>
        <customer>Customer #4</customer>
        <text>Quote #4</text>
      </quote>
      <quote>
        <customer>Customer #5</customer>
        <text>Quote #5</text>
      </quote>
    </quotes>
    

    You would load it using XElement xml = XElement.Load("filename");

    With the xml variable above, the previous code is used the same way (commented out code).

    The Guid works but you could also have a static Random variable defined in a class: public static Random rand = new Random(); then change the code to:

    int count = xml.Elements().Count();
    var randomQuote = xml.Elements()
                         .OrderBy(i => rand.Next(0, count))
                         .Select(element => new { 
                            Customer = element.Element("customer").Value,
                            Quote = element.Element("text").Value
                          })
                         .First();
    
    Console.WriteLine("{0} : {1}", result.Customer, result.Quote); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.