C# FileSystemWatcher
A console sample that uses FileSystemWatcher to log a timestamp every time a file changes.
using System;
using System.IO;
namespace ConsoleApplication1
{
class ProgramArticles, code snippets and news worth sharing.
A console sample that uses FileSystemWatcher to log a timestamp every time a file changes.
using System;
using System.IO;
namespace ConsoleApplication1
{
class ProgramGenerate a set of SELECT statements that search every text column in the database for a given string.
select
'select distinct ''' + tab.name + '.' + col.name + ''' from
[' + tab.name + '] where [' + col.name + '] like ''%TEXT_TO_SEARCH%'' union '
from sys.tables tab
join sys.columns col on (tab.object_id = col.object_id)
join sys.types types on (col.system_type_id = types.system_type_id)Build a comma separated string from the values of a table column with a single COALESCE query.
DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr + ''',''', '') + ColumnName
FROM TableName
SELECT @listStrHandle the MouseDown event of a WinForms RichTextBox to select the whole line under the mouse.
Private Sub RichTextBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles RichTextBox1.MouseDown
Dim box = DirectCast(sender, RichTextBox)
Dim index = box.GetCharIndexFromPosition(e.Location)
Dim line = box.GetLineFromCharIndex(index)
Dim lineStart = box.GetFirstCharIndexFromLine(line)
Dim lineEnd = box.GetFirstCharIndexFromLine(line + 1)A PowerShell script that finds every user in Active Directory, adds them to a SharePoint 2010 group and syncs their profile details.
$spgroupname = "Group Name"
$sitename = "http://sitename"
$domain = $env:USERDOMAIN
$spsite = New-Object Microsoft.SharePoint.SPSite($sitename)
$rootweb = $spsite.RootWebRun code when a popup window opened with window.open is closed, using the onbeforeunload event.
var popupWindow = window.open(url);
popupWindow.onbeforeunload = function() {
//Do processing
return null;Remove duplicate strings from a List in C#, the old way with Sort and RemoveAt and the shorter way with Distinct.
List<string> strlist = new List<string>();
//Fill the list with random values
strlist.Sort();
Int32 index = 0;
while (index < strlist.Count - 1)
{A simple XOR based encrypt and decrypt routine in JavaScript, for demonstration only.
function Encrypt()
{
var actual = "stringtoencrypt";
var key = 100; //Any integer value
var result = "";
for (var i = 0; i < actual.length; i++)Use LINQ GroupBy to count how many times each value appears in an integer array.
private Dictionary<int, int> GetArrayDuplicates(int[] arrayToSearch)
{
Dictionary<int, int> counts = arrayToSearch.GroupBy(arrayItem => arrayItem)
.ToDictionary(groupedItem => groupedItem.Key,
groupedItem => groupedItem.Count());
return counts;Two ways to start a C# application automatically at Windows startup: the Startup folder or a Run registry key.
private void RegisterStartupApplication()
{
RegistryKey regKey = Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
regKey.SetValue("MyApplicationsName", Application.ExecutablePath);
}Minimise all windows from C#, the same as clicking Show Desktop on the taskbar, using the Shell32 COM library.
Shell32.ShellClass shell = new Shell32.ShellClass();
shell.MinimizeAll();Fix Visual Studio 2010 not reopening your documents from the last session by resetting all settings.