Print text file contents on a console using HTTPClient | Bytes (2024)

Home Posts Topics Members FAQ

KelvinNyota

Print text file contents on a console using HTTPClient | Bytes (1) 5 New Member

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, but it is showing the result:

Expand|Select|Wrap|Line Numbers

  1. usingSystem;
  2. usingSystem.Net.Http;
  3. usingSystem.Threading.Tasks;
  4. classProgram
  5. {
  6. staticvoidMain()
  7. {
  8. Taskt=newTask(DownloadPageAsync);
  9. t.Start();
  10. Console.WriteLine("Downloadingpage...");
  11. Console.ReadLine();
  12. }
  13. staticasyncvoidDownloadPageAsync()
  14. {
  15. //ThefileislocatedontheApp_Datafolder
  16. stringpage="/App_Data/Text1.Txt";
  17. //...UseHttpClient.
  18. using(HttpClientclient=newHttpClient())
  19. using(HttpResponseMessageresponse=awaitclient.GetAsync(page))
  20. using(HttpContentcontent=response.Content)
  21. {
  22. //...Readthestring.
  23. stringresult=awaitcontent.ReadAsStringAsync();
  24. //...Displaytheresult.
  25. if(result!=null&&
  26. result.Length>=50)
  27. {
  28. Console.WriteLine(result.Substring(0,50)+"...");
  29. }
  30. }
  31. }
  32. }

Oct 13 '16 #1

Subscribe Reply

0 Print text file contents on a console using HTTPClient | Bytes (2) 1821 Print text file contents on a console using HTTPClient | Bytes (3)

Sign in to post your reply or Sign up for a free account.

Similar topics

4 2611

Moving text file contents into a std::string

by: Dave |last post by:

Hello all, The scheme shown below to move a text file's contents into a std::string works with one exception: it drops the carriage return and line feed characters. How may I, in a Standard-compliant way, read in a text file's contents and keep the carriage returns and line feeds? Thanks, Dave

C / C++

1 3161

I want to sort the text file contents using arrays in VB

by: sachin10 |last post by:

hi i m sachin, i m new to VB programming.i face some problem regarding the sorting of text file contents using arrays.text file have data in the format as below seq |consumerid|status1|status2|meter no1|meter no2|nameof consumer|routeno 234133210003040002222222222000003333333123098sasdcscasdsadsd9041 231433104000267232222278222000003333333123098shskdfkscasdsade9012 this is the format of text file.there are thosands of records in this...

Visual Basic 4 / 5 / 6

6 2941

[VB.Net] : Read Text File Contents with Regular Intervals

by: ak1dnar |last post by:

Hi, I have created Sub in VB.net application, Which reads a text file contents. Sub IPsetter() Dim fileName As String Dim realIParray As String() = Nothing Dim ipString As String

.NET Framework

2117

C# App To print text file at 0,0 (x,y) coordinate of the page

by: jigsmshah |last post by:

I need to print a text file .When i print it ,it is not printed exactly form 0,0 coordiante of the page. I mean the top most left corner.It is leaving some margin from top and from left.The code is an example from MSDN. I am using c# 2.0 and VS 2005.I have just chaged the X coordinate for the DrawString function.i am using it as 0 and the Y coordinate is calculated. This is just a test application, as i have to take the printing logic futher...

.NET Framework

2 4001

Print text file to a remote printer

by: Chronos |last post by:

Hi all, Is it possible to print text file to a remote printer in C#? If so, can you tell me how? Thanks, Chronos

C# / C Sharp

1 1612

Retrieving the text file contents line by line using JavaScript...

by: aryanraj |last post by:

Aryan Hi Everybody, I want to read the text file contents line by line and place the contents into a textarea, using the java script, is there any way to do it. Thanks in Advance, Aryan.

Javascript

3 2438

Perl and print text file selectively help!

by: itdaddy |last post by:

hey perl gurus! i am new to this forum cause i need help. I have done many scripts. but i want to use perl to do this: What I want to do is this. I have a QRP file that I can convert to a txt file field separated by commas or not. I want to pring each line that has an actual date to the right of the word 'DATE:' if it doesnt have a date do not print that line. Then the next thing i want my perl program to do is print each line that has...

Perl

2 1858

print text file into string

by: kim6987 |last post by:

Can any one show me how to write the code in C when I want to read the content of a text file and write it into a string? Thank you!

C / C++

1 1687

How to generate and print text file using c# in asp.net.. help please..

by: rajesh0303 |last post by:

Hi, Iam new to c# and I want to generate a text file with information calling from database and with pre texts ....sample text of file is. Here XX are the data from databse.. How can I do it? Need help please.... School No.: 99999XSchool Name: Total Pupils:

.NET Framework

11 4217

How to print text file from hash table one line at a time

by: JWest46088 |last post by:

I'm having difficulty trying to figure out how to print a text file from a hash table one line at a time. I have the text file read into the hash table and can print the text file all at once, but I can't seem to figure out how to do it one line at a time. Here is what I'm trying to do: I want the user to be able to print the text file one line at a time by clicking a button to see the next line. Example: If text_file1 first line is...

Perl

9621

What is ONU?

by: marktang |last post by:

ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...

General

9454

Changing the language in Windows 10

by: Hystou |last post by:

Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...

Windows Server

10106

Maximizing Business Potential: The Nexus of Website Design and Digital Marketing

by: jinu1996 |last post by:

In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...

Online Marketing

1 10046

The easy way to turn off automatic updates for Windows 10/11

by: Hystou |last post by:

Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...

Windows Server

9915

Discussion: How does Zigbee compare with other wireless protocols in smart home applications?

by: tracyyun |last post by:

Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...

General

8939

AI Job Threat for Devs

by: agi2029 |last post by:

Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...

Career Advice

6717

Couldn’t get equations in html when convert word .docx file to html file in C#.

by: conductexam |last post by:

I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...

C# / C Sharp

2 3611

How to add payments to a PHP MySQL app.

by: muto222 |last post by:

How can i add a mobile payment intergratation into php mysql website.

PHP

3 2852

Comprehensive Guide to Website Development in Toronto: Expert Insights from BSMN Consultancy

by: bsmnconsultancy |last post by:

In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

General

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisem*nts and analytics tracking please visit the page.

Print text file contents on a console using HTTPClient | Bytes (2024)
Top Articles
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 6606

Rating: 4.8 / 5 (58 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.