Copy data from DataView to DataTable using C#
Copying data from DataView to DataTable is easily done in C#, by using the code below: DataTable dt = dv.ToTable(); Related Snippets
Copying data from DataView to DataTable is easily done in C#, by using the code below: DataTable dt = dv.ToTable(); Related Snippets
The snippet below will get you the drive type where a specified file/folder is. static void Main(string[] args) { System.IO.FileInfo file = new System.IO.FileInfo("M:\\"); // File or Directory System.IO.DriveInfo _driveInfo = new System.IO.DriveInfo(file.FullName); Console.WriteLine("Drive: " + _driveInfo.Name); if (_driveInfo.IsReady) { Console.WriteLine("The drive type is: " + _driveInfo.DriveType.ToString()); } Console.ReadLine(); } Output More C# Snippets
Here is a code snippet to get the application path of a Windows Forms application in C#. string programPath = System.Windows.Forms.Application.ExecutablePath; More C# Snippets
Below is a function that shuffles an array or a list. It accepts a list or array to be shuffled/rearranged as an argument and returns a shuffled copy of the object passed. public E ShuffleArrayAndList<E>(IList<E> arr) { Random random = new Random(); E result = arr[arr.Count]; E tmpArray = arr[arr.Count]; if (arr.Count > 1) {... » read more
A function to remove duplicate values from an array using PHP. function removeDuplicateValues($array) { $newArray = array(); while (list($key, $value) = each($array)) { $newArray[$value] = 1; } return array_keys($newArray); } Related Snippets
The code below copies a folder content ( or directory) into a newly created subfolder( or subdirectory). <?php $myDir = opendir('/myDir'); mkdir('/myDir/newDir'); while (false !== ($file = readdir($myDir))) { if (($file != '.') && ($file != '..')) { if (is_dir('/myDir/' . $file)) { $this->recurseCopy('/myDir/' . $file, '/myDir/newDir/' . $file); } else { copy('/myDir/' . $file,... » read more
Below is a PHP function that validates an email address and returns the result as a boolean. This function uses the PHP built-in function filter_var and the filter FILTER_VALIDATE_EMAIL <?php //php 7.0.8 function ValidateEmail($email) { $email = 'myEmail@myDomain.com'; $isValid = filter_var($email, FILTER_VALIDATE_EMAIL); if ($isValid) { return true; } else { return false; } } ?> Easy isn’t?... » read more
A function that will return the local IP address. <?php function GetIPAddress() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ipAddress = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ipAddress = $_SERVER['REMOTE_ADDR']; } echo "You IP address is $ipAddress"; } ?> Related Snippets
A PHP function to return the current page URL. <?php function getCurrentURL() { $CurrentURL = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"]; $CurrentURL .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : ""; $CurrentURL .= $_SERVER["REQUEST_URI"]; return $url; } ?> Happy Coding!!! Related Snippets
An easy way to shuffle an array using JavaScript: var arr = [1,2,3,4,5]; var newArr; newArr = arr.sort(function() { return 0.5 - Math.random() }); alert(newArr); Related Snippets
A snippet to return the php physical file name that is called from: <?php $fileName = basename($_SERVER['PHP_SELF']); echo fileName; ?> Happy coding!!! Related Snippets
A snippet to get an image height and width using PHP built-in function getimagesize and list: <?php list($width, $height) = getimagesize("myImage.png"); echo "Image width is " . $width; echo "<br>"; echo "Image height is " . $height; ?> Happy Coding! Related Snippets
To remove the last character of a string, using Javascript: var input = 'butterflyy'; var result = input.substring(0, input.length-1); alert(result); Happy Coding!! Related Snippets
A code snippet to take all number off a string using JavaScript <script> var MyString = "Tutorials1P2anel3"; stringOnly = MyString.replace(/[0-9]/g, ''); alert(stringOnly); </script> You can replace the alert with anything else that would fit your coding needs. Related Snippets
A Javascript function to check email validation. Returns boolean. function ValidateEmail(email) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if (!reg.test(email)) return false; return true; } Happy Coding! Related Snippets