Daily Archives: May 13, 2021

C# || How To Get A List Of Files At A Given Path Directory Using C#

The following is a module with functions which demonstrates how to get a list of files at a given directory path using C#.

The function demonstrated on this page returns a list of System.IO.FileInfo, which contains information about the files in the given directory.


1. Get Files In Directory

The example below demonstrates the use of ‘Utils.Methods.GetFilesInDirectory‘ to get a list of files at a given path directory.

The optional function parameter lets you specify the search option. This lets you specify whether to limit the search to just the current directory, or expand the search to the current directory and all subdirectories when searching for files.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C# || How To Get The Computer & User Client IP Address Using C#

The following is a module with functions which demonstrates how to get the computers and user client request IPv4 IP address using C#.

The function demonstrated on this page returns the IPv4 address of the calling user. When under a web environment, it returns the clients System.Web.HttpContext.Current.Request IP address, otherwise it returns the IP address of the local machine (i.e: server) if there is no request.

The following function uses System.Web to determine the IP address of the client.

Note: To use the function in this module, make sure you have a reference to ‘System.Web‘ in your project.

One way to do this is, in your Solution Explorer (where all the files are shown with your project), right click the ‘References‘ folder, click ‘Add Reference‘, then type ‘System.Web‘ in the search box, and add the reference titled System.Web in the results Tab.


1. Get IP Address

The example below demonstrates the use of ‘Utils.Methods.GetIPv4Address‘ to get the IPv4 address of the calling user.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C# || How To Copy DataTable DataRow From One DataRow To Another Using C#

The following is a module with functions which demonstrates how to copy a DataTable DataRow from one DataRow to another using C#.

The function demonstrated on this page is an extension method, which copies all matching columns from the source DataRow to the destination DataRow. If no matching column exists between the two rows, the data at that column is skipped. This allows to safely copy a single row from one DataTable to other.


1. Copy DataRow

The example below demonstrates the use of ‘Utils.Collections.Extensions.CopyTo‘ to copy all matching columns from a source row to a destination row.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C# || How To Generate, Create & Read A QR Code Using C#

The following is a module with functions which demonstrates how to generate, create and read a QR code using C#.

The functions demonstrated on this page has the ability to create and encode a string to a QR code byte array, and another function to read and decode a byte array QR code to a string.

The following functions use ZXing.Net to create and read QR codes.

Note: To use the functions in this module, make sure you have the ‘ZXing.Net‘ package installed in your project.

One way to do this is, in your Solution Explorer (where all the files are shown with your project), right click the ‘References‘ folder, click ‘Manage NuGet Packages….‘, then type ‘ZXing.Net‘ in the search box, and install the package titled ZXing.Net in the results Tab.


1. Create QR Code – Encode

The example below demonstrates the use of ‘Utils.QRCode.Create‘ to create a QR code byte array from string data.

The optional function parameters allows you to specify the QR code height, width and margin.


2. Read QR Code – Decode

The example below demonstrates the use of ‘Utils.QRCode.Read‘ to read a QR code byte array and decode its contents to a string.


3. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


4. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.