C# Code Snippets
Collection of C# code snippets
Recent articles in C# Code Snippets
- Populate ComboBox using DataTable. (C-Sharp) C# code snippet CreateDropDownMenu to populate ComboBox dropdown menu with given DataTable.
- C# Code Snippet - AddSlashes StripSlashes Escape String. (C-Sharp) C# code snippet AddSlahes tool allows quote a string with slashes (Escape String). Stripslashes snippet un-quotes a quote string by removing slashes.
- C# Code Snippet - Access current environment directories and logical drives. (C-Sharp) C# code snippets to access current environment directories such as current directory, system directory and logical drives.
- C# Code Snippet - Convert Unix timestamp. (C-Sharp) C# code snippets convert date/time between DateTime and Unix timestamp. Most .Net base applications never use Unix timestamp, but if you want to create a application to interact with other application or sites, maybe built in PHP or Java, use these methods to convert Unix timestamp.
- C# Code Snippet - Upload file to FTP Server. (C-Sharp) C# code snippet upload file to FTP Server. This method login to FTP server using username and password and upload the local file to given FTP location.
- C# Code Snippet - Validate (int) Integer. (C-Sharp) C# code snippets return the validated int value by checking validity of the given int and checking the int value range within the given minimum and maximum int range.
- C# Code Snippet - Find starting and ending date for given date. (C-Sharp) C# code snippets return the Ending Date and Starting Date for given date. Simply pass DateTime value that need to find date and snippets will return starting and ending date as DateTime.
- C# Code Snippet - Get local computer host name. (C-Sharp) C# code snippet get the host name from the local machine.
- C# Code Snippet - Get local computer IP address. (C-Sharp) C# code snippet get the IP address from the local machine. For computers with multiple IP addresses with one or more NIC cards can use IP address object list to obtain all the IP addresses.
- C# Code Snippet - Compile C# or VB source code run-time. (C-Sharp) C# code snippet compile C# or VB source code run-time from a text string or external text file and build the executable. Programmatically compile code using C#/VB compiler.
- C# Code Snippet - Save object to file. (C-Sharp) C# code snippet save object to external file. This function can be use to serialize objects into byte array and save them in external file.
- C# Code Snippet - Load object from binary file. (C-Sharp) C# code snippet open an external binary data file and convert it to object. This function can be use to deserialize those byte array data (Serialized) from external file to their original objects.
- C# Code Snippet - Byte array to object. (C-Sharp) C# code snippet convert byte array to object. This function useful to convert back byte array data to its original object representation. This function can be use to deserialize those byte array data (Serialized) to their original objects.
- C# Code Snippet - Object to byte array. (C-Sharp) C# code snippet convert object to byte array. This method useful to store binary data in files. This function can be use to convert any object to byte array and store them in database.
- C# Code Snippet - Save byte array to file. (C-Sharp) C# code snippet save byte array in to an external file. This function useful to store binary data in files. This function can be use when retrieving binary data from database and save it to an external file.
- C# Code Snippet - Convert file to byte array. (C-Sharp) C# code snippet convert external file to byte array. Converting file into byte array important to store binary file in database, send to other systems using remoting.
- C# Code Snippet - Execute Shell Commands from .Net. (C-Sharp) C# code snippet creates a command process and then invokes the command that we want to execute. The result of the command and any errors occurred during execution is stored in a string variables. This is a great method to execute your DOS commands from .Net.
- C# Code Snippet - Download File from URL. (C-Sharp) C# code snippet download file from URL and save it on local drive. These code snippets discuss both asynchronous file download method and DownloadFile method (to block thread while waiting for the download).
- C# Code Snippet - Download Image from URL. (C-Sharp) C# code snippet download image from URL. This function download image using web response stream.
- C# Code Snippet - Download HTML Web Page. (C-Sharp) C# code snippet download web page HTML source contents.
- C# Code Snippet - Send Email Using SMTP Server. (C-Sharp) C# code snippet connects to SMTP Email Server and send email message. SendEmail send email using SMTP email server.
Recent articles in C# Code Snippets
- C# Code Snippet - Insert/Update Image To SQL Server. (C-Sharp) C# code snippet connects to SQL server and executes SQL statement and update/insert binary image data in database table. InsertUpdateImage update/insert image into database using open database connection, insert/update SQL statement, binary image and image format.
- C# Code Snippet - Get Identity Column Value from SQL Server. (C-Sharp) C# code snippet connects to SQL server and executes SQL statement and returns the identity value. ExeSQLReturnLong execute SQL statement using ExecuteScalar method and return identity value as a long. ExeSQLReturnObject execute SQL statement using ExecuteScalar method and return identity value as an object.
- C# Code Snippet - ExecuteNonQuery against the SQL Server Database. (C-Sharp) C# code snippet connects to SQL server and executes a SQL statement and returns the number of rows affected. ExecuteNonQuery returns number of rows affected using open database connection and SQL statement.
- C# Code Snippet - Check Record Exists in SQL Server Database. (C-Sharp) C# code snippet connects to SQL server and executes SQL statement to determine whether the given record exists in the database. RecordExists returns logical (True/False) using open database connection and SQL statement.
- C# Code Snippet - Get Image from sql server. (C-Sharp) C# code snippet connects to SQL server and executes SQL statement and returns the Image data. ScalarToImage returns an Image using open database connection and SQL statement.
- C# Code Snippet - Get Scalar using open connection. (C-Sharp) C# code snippet connects to SQL server and executes SQL statement and returns the first column of the first row in the result set returned by the query as a object. ExecuteScalar returns an object using open database connection and SQL statement.
- C# Code Snippet - Get XmlReader using open connection. (C-Sharp) C# code snippet connects to SQL server and executes SQL statement and return XmlReader. ExecuteXmlReader returns XmlReader using open database connection and SQL statement.
- C# Code Snippet - Get DataTable using open connection. (C-Sharp) C# code snippet connects to SQL server and executes SQL statement and return DataTable. GetDataTable returns DataTable using open database connection and SQL statement.
- C# Code Snippet - Get First Row As Object Array From SqlDataReader. (C-Sharp) C# code snippet execute a SQL statement using open database connection and return all the columns data in SqlDataReader for first row. GetSqlDataReaderFirstRow execute and close SqlDataReader and returns first data row as a dictionary object array.
- C# Code Snippet - Get Data From SqlDataReader using open connection. (C-Sharp) C# code snippet connects to SQL server and executes SQL statement and return SqlDataReader. GetSqlDataReader returns SqlDataReader using open database connection and SQL statement.
- C# Code Snippet - Get Data From SqlDataReader. (C-Sharp) C# code snippet connects to SQL server and executes SQL statement and return SqlDataReader. FunctionSqlDataReader returns SqlDataReader for given database connection string and SQL statement.
- C# Code Snippet - Remove White Spaces. (C-Sharp) C# code snippet to remove all white spaces from a string. TrimWhiteSpace strip all white spaces from a given.
- C# Code Snippet - Remove HTML Tags. (C-Sharp) C# code snippet to remove all HTML TAGS from a string. StripHTML strip all HTML tags from a given string and return plain text.
- C# Code Snippet - Extract Numeric values. (C-Sharp) C# code snippet to extracts all the numeric values from a string. ExtractNumbers returns string array of numeric values successful matches by iteratively applying a regular expression pattern to the input string.
- C# Code Snippet - Extract Emails. (C-Sharp) C# code snippet to extracts all the Emails from a string. ExtractEmails returns string array of Emails successful matches by iteratively applying a regular expression pattern to the input string.
- C# Code Snippet - Extract URLs. (C-Sharp) C# code snippet to extracts all the URLs from a string. ExtractURLs returns string array of URLs successful matches by iteratively applying a regular expression pattern to the input string.
- C# Code Snippet - Validate whole number. (C-Sharp) C# code snippet to validate given whole number. IsWholeNumber function validates positive integers with zero inclusive. Function return TRUE if valid whole number found, if not function will return FALSE.
- C# Code Snippet - Validate Integer. (C-Sharp) C# code snippet to validate given integer. IsInteger function validate integer both positive and negative. Function return TRUE if valid integer found, if not function will return FALSE.
- C# Code Snippet - Validate Email Address. (C-Sharp) C# code snippet to validate given email address. IsValidEmail function validate email address. Function return TRUE if valid email address found, if not function will return FALSE.
- C# Code Snippet - Returns current UNIX timestamp. (C-Sharp) C# code snippet to return current UNIX timestamp. UnixTimeNow() returns current UNIX timestamp.