GET and POST Request using HttpClient(C#)

GET and POST Request using HttpClient

GET and POST Request using HttpClient – Requesting data is one of the most common things in client projects. That include GET request to get specific data from server and post request to insert data into the server. There are two ways to implement this request it can be done using WebClient or HttpClient.

But this post is to show you how to use HttpClient for GET and POST Http request in C#. This will show you how simple it is to implement an Http request using HTTPClient.

HttpClient can be added using NugetPackage Manager(System.Net.Http).

GET using HTTPClient

This is how to implement GET request:

That is how simple it is to perform GET request.

POST using HttpClient

As you can see it is very similar to GET. You will also notice that we just added PostAsync and parameter to execute Post request.

HttpClient reference can be added using Nuget Package Manager of Visual Studio. And easily implemented using C#.

HttpClient: Happy Coding!

How to use WebClient in C# (System.Net.WebClient)

System.Net.WebClient
Using System.Net.WebClient class in consuming Web API.

System.Net.WebClient – The easiest way to download and upload data from and to a Web API is using Web Client. Here’s a few codes  to implement Web Client in 4 different method.

  • using System.Net;

Method: GET

Method: POST

Method: DELETE

Method: PUT


 

Reading PDF File (ItextSharp) in CSharp

Reading PDF File

Reading PDF File – I started my day searching a solution on how to read PDF  file and finally I was able to search for a solution . Here is a solution from stack overflow.
I am posting this to be able to help readers from this blog who have also searching for this problem.

Credit to stackoverflow:

Link: https://stackoverflow.com

Here’s a code found on this link which helps me a lot.

If you are using Visual Studio , you can add reference to ItextSharp using Manage Nuget Packages.To open Manage Nuget Packages, go to your solution explorer and right-click on your project name then scroll down for Manager Nuget Packages. To search for ItextSharp, simply search for ItextSharp then if the search result appears select the first option and click the  install button on the right side of the result.

Below is the image of ItextSharp from Manage Nuget Packages option. Reading PDF File

After successfully adding this reference you can now use it by adding this reference from your code.

  • using iTextSharp.text.pdf;
  • using iTextSharp.text.pdf.parser;

And now, you can already use iTextSharp from your code.

Thank you for reading!

Hopes that this simple solution can help you.

Happy coding!!

Reporting-Creating ReportViewer Report

Reporting

1. Reporting – Create a new windows application project in your visual studio 2013 then add report viewer to your project.

Reporting

Add ReportViewer

2. Dock report viewer to your form.

Reporting

Dock ReportViewer

3. Add Dataset to your project by simply right clicking on your project name and selecting Add-New Item

Reporting

Add New Item

4. Select data from the left pane and search for Dataset from the middle pane

Reporting

Add Dataset

5. Open Dataset you just added and add DataTable. See image below.

Reporting

Create DataTable

6. Add a column to your table.

Reporting

Add Column

7. Add Report to your project (RDLC file). Right-click again on your project name in your solution explorer and select Add->New Item, then select Reporting from the left pane and choosing Report from the middle pane.

Reporting

Add RDLC Report

8. Open your RDLC report then add List tools from your toolbox located on the left side of your RDLC designer.

Reporting

Add List

9. Choose Dataset for your List Table. In my case it is Dataset1.

Reporting

Choose DataSource

10. Add a column to your list by simply right clicking on any cell and selecting Insert Column.

Reporting

Add Column

11. Manually add column name to your List Table from your DataTable. See image below.

Reporting

Add Column name

12. This is my final view of the design for my RDLC report.

 

Reporting

Final RDLC Design

13. To add Data to our list and display it in our reportviewer from our form. Copy the code below. I write my code inside form load event .

Note:
ReportViewer.Report1.rdlc

• ReportViewer -> Name of my project
• Report1.rdlc -> Name of my rdlc report
• DataSet1 -> Dataset Name

14. Then run your project by simply clicking F5 on your keyboard.

Reporting

Final View

Than you for reading!!

Happy Coding!!

LinQ Tutorial on DataTable – C#

LinQ Tutorial
LinQ Tutorial

This LINQ tutorial will show you some basic codes on implementing LINQ in C#.LINQ is an acronym for Language Integrated Query, which is descriptive for where it’s used and what it does. The Language Integrated part means that LINQ is part of programming language syntax. To have an overall view of the definition of LINQ please refer to this site I find csharp-station.com. Below are basic codes for implementing LINQ on a DataTable.

For more tutorial visit this link ASP.NET MVC Developement.

CopyToDataTable();

Note:

  • Employee -> DataTable Name

Select  All

Note:

  • Employee -> DataTable Name

Select Specific column from DataTable

 

Note:

  • Name -> Table Column Name
  • Address -> Table Column Name
  • Employee -> DataTable Name

Count()

  Note:

  • Name -> Table Column Name
  • Address -> Table Column Name
  • Employee -> DataTable Name

 

Count();

 Note:

  • Name -> Table Column Name
  • Employee -> DataTable Name
  • data -> Variable

 

ToList()

Note:

  • Name -> Table Column Name
  • Address -> Table Column Name

SUM()

Note:

  • NUmberOfEmployee-> Table Column Name
  • data -> variable
  • Employee -> DataTable Name

Group BY & order by

 

 

Import Excel to Datagridview – C#

Import Excel – This project is intended to read excel using Microsoft.Office.interop.Excel namespace.There are a lot of ways to read an excel file in C# but for beginners like me this might be a help. Below is a simple way on how to read and import data in DataGridView.

Let’s Start:

  1. Create a new project by going to File->New->Project

    Import Excel

    New project

  2. From New Project window Name your project as Upload_Data_From_Excel.(You can also name it to your preference).Then click “OK” to proceed. See image below.

    Import Excel

    Name Project (Upload_Data_From_Excel)

  3. After you have successfully created your project. Add controls to your form.
  • Add button for upload click event.
  • Add OpenFileDialog for browsing files
  • DatagridView for viewing of data

 Design it to whatever you like.

Import Excel

Create design

  1. Rename your button. To rename click on the button you added to your form and navigate to its property located below your solution explorer. In my case I name it as btn_Upload.

    Import Excel

    Change button name

  2. Now navigate to your solution explorer and right click on Reference and choose Add Reference to add Microsoft.Office.Interop.Excel .

    Import Excel

    Add Reference

  3. From reference manager window expand Assemblies and click Extensions from the left pane and search for Micorosft.Office.Interope.Excel from the middle pane.

    Import Excel

    Add Microsoft Office Interop

  4. To see if reference was successfully added go to your project solution explorer and expand Reference then look for Microsoft.Office.Interop.Excel.

    Import Excel

    Check Reference if Added

  5. After we verify and successfully added Microsoft.Office.Interop.Excel. Open your form design and double click on btn_Upload button to add button click event.

    Import Excel

    Double Click on button upload

  6. Copy and paste the code below to your btn_Upload Click Event

  1. To test, run your application by pressing ctrl + f5 without debugging or f5 for debugging mode.

    Import Excel

    Run Project

  2. Click on upload button and select your excel file.
Import Excel

Open File

Note: Data on excel file should be in table format

 

Final output:

Excel File:

Import Excel

Excel File

Project Output:

 

Import Excel

Final Output

Full Code:

Thank you for reading!

Happy Coding!!

 


Post you may like:

[pt_view id=”2384ae03it”]

WSDL Web Service Testing tool

WSDL Web Service Testing Tools

Description:

This simple testing tool is use for testing WSDL Web Service from Land Bank and DBP(Development Bank of the Philippines)  for remittance transaction.

Language: C#

Development Environment: Visual Studio 2013

 

Note: This tool is for portfolio purposes only. This is not for sale.

 

 

1 2