Question Printing text file contents on a console using HTTPClient

Joined
Oct 13, 2016
Messages
9
Programming Experience
1-3
How do you print a Text file on a console application with formatting like below in HTTPClient in C# Language?

Here is how my textFile looks like:

Hi|Fine!


Here is all my code:

C#:
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
    Task t = new Task(DownloadPageAsync);
    t.Start();
    Console.WriteLine("Downloading page...");
    Console.ReadLine();
    }

    static async void DownloadPageAsync()
    {

    // The file is located on the App_Data folder
    string page = "/App_Data/Text1.Txt";

    // ... Use HttpClient.
    using (HttpClient client = new HttpClient())
    using (HttpResponseMessage response = await client.GetAsync(page))
    using (HttpContent content = response.Content)
    {
        // ... Read the string.
        string result = await content.ReadAsStringAsync();

        // ... Display the result.
        if (result != null &&
        result.Length >= 50)
        {
        Console.WriteLine(result.Substring(0, 50) + "...");
        }
    }
    }
}
 
Text is text. How you got that text is irrelevant to what you do with it. Search the web for how to print text and that is how you will print your text, whether you downloaded it using an HttpClient or hard-coded it in a constant. You will be using a PrintDocument, handling its PrintPage event and calling Graphics.DrawString.
 
jmcilhinney

Text is text. How you got that text is irrelevant to what you do with it. Search the web for how to print text and that is how you will print your text, whether you downloaded it using an HttpClient or hard-coded it in a constant. You will be using a PrintDocument, handling its PrintPage event and calling Graphics.DrawString.

Is there a way to implement that in HTTPClient? Am really stuck!
 
It's like you didn't even read my previous post. The HttpClient is completely irrelevant. You're printing text. Where that comes from makes exactly zero difference to how you print it. I've already told you that you will use a PrintDocument, handle its PrintPage event and call Graphics.DrawString. There would be literally loads of examples of that around the web so if you're stuck it's simply bercause you haven't bothered to look.
 

Latest posts

Back
Top Bottom