<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>codehutch.com</title>
	<atom:link href="http://codehutch.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codehutch.com</link>
	<description>Online Code Repository</description>
	<pubDate>Thu, 01 Dec 2011 10:27:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>C#: Reverse a String</title>
		<link>http://codehutch.com/2011/12/c-reverse-a-string/</link>
		<comments>http://codehutch.com/2011/12/c-reverse-a-string/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 10:15:00 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[Code]]></category>

		<category><![CDATA[string reverse in C#]]></category>

		<guid isPermaLink="false">http://codehutch.com/?p=296</guid>
		<description><![CDATA[Reversing a string in C# is quite easy. The main concept is to treat the string as an array of characters, which is already built-in in C#, and transfer each character to new container in reverse order. Here are the samples of simple and straightforward functions on how to reverse a string in C#.
Manual reverse [...]]]></description>
			<content:encoded><![CDATA[<p>Reversing a string in C# is quite easy. The main concept is to treat the string as an array of characters, which is already built-in in C#, and transfer each character to new container in reverse order. Here are the samples of simple and straightforward functions on how to reverse a string in C#.</p>
<p>Manual reverse transfer using for-loop</p>
<blockquote><p>public static string ReverseByTransfer(string str)<br />
{<br />
int strlen = str.Length;<br />
char[] arr = new char[strlen];</p>
<p>for (int i = 1; i &lt;= strlen ; i++)<br />
{<br />
arr[i-1] = str[strlen - i];<br />
}</p>
<p>return new string(arr);<br />
}</p></blockquote>
<p>Convert string to character-array and use Array&#8217;s Reverse function</p>
<blockquote><p>public static string ReverseByConvert(string str)<br />
{<br />
char[] arr = str.ToCharArray();<br />
Array.Reverse(arr);<br />
return new string(arr);<br />
}</p></blockquote>
<p><strong><a href="http://codehutch.com/download-codes/">DOWNLOAD REVERSE STRING CODE</a></strong></p>
<p>===================</p>
]]></content:encoded>
			<wfw:commentRss>http://codehutch.com/2011/12/c-reverse-a-string/feed/</wfw:commentRss>
		</item>
		<item>
		<title>XOR Encryption</title>
		<link>http://codehutch.com/2011/11/xor-encryption/</link>
		<comments>http://codehutch.com/2011/11/xor-encryption/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 05:17:31 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[Code]]></category>

		<category><![CDATA[Logic]]></category>

		<guid isPermaLink="false">http://codehutch.com/?p=261</guid>
		<description><![CDATA[XOR (Exclusive OR, EOR, EXOR) is a logical operation which results to a true value if exactly one of the two operands has a value of true.
Sample XOR Table



INPUT
OUTPUT


A
B
A ^ B


0
0
0


0
1
1


1
0
1


1
1
0



Using this knowledge we can encrypt characters using their binary values. Take for example the string &#8220;ENCRYPT&#8221;. First, we take the ASCII Code of each [...]]]></description>
			<content:encoded><![CDATA[<p>XOR (Exclusive OR, EOR, EXOR) is a logical operation which results to a true value if exactly one of the two operands has a value of true.</p>
<p><strong>Sample XOR Table</strong></p>
<table style="text-align:center;" border="1">
<tbody>
<tr>
<td colspan="2">INPUT</td>
<td>OUTPUT</td>
</tr>
<tr>
<td>A</td>
<td>B</td>
<td>A ^ B</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
</tbody>
</table>
<p>Using this knowledge we can encrypt characters using their binary values. Take for example the string &#8220;ENCRYPT&#8221;. First, we take the <a title="ASCII Code" href="http://codehutch.com/ascii-codes/" target="_blank">ASCII Code</a> of each character in this string and convert each to their respective binary value.</p>
<blockquote><p>E - 69 - 1000101<br />
N - 78 - 1001110<br />
C - 67 - 1000011<br />
R - 82 - 1010010<br />
Y - 89 - 1011001<br />
P - 80 - 1010000<br />
T - 84 - 1010100</p></blockquote>
<p><em>Note: Small letters have different ASCII values.</em></p>
<p>Choose a random encryption key, say &#8220;X&#8221;. X has an ASCII Code of 88 and binary value of 1011000. If we perform XOR on &#8220;ENCRYPT&#8221; against &#8220;X&#8221;, we get:</p>
<blockquote><p>1000101 ^ 1011000 = 0001101 [29]<br />
1001110 ^ 1011000 = 0010110 [22]<br />
1000011 ^ 1011000 = 0011011 [27]<br />
1010010 ^ 1011000 = 0001010 [10]<br />
1011001 ^ 1011000 = 0000001 [1]<br />
1010000 ^ 1011000 = 0001000 [8]<br />
1010100 ^ 1011000 = 0001100 [12]</p></blockquote>
<p>Looking up these numbers in <a title="ASCII Code" href="http://codehutch.com/ascii-codes/" target="_blank">ASCII Code Table</a>, we get:</p>
<p><img src="http://codehutch.com/images/encrypt-result.png" alt="" /></p>
<p>Thus, the string &#8220;ENCRYPT&#8221; will be encrypted to:</p>
<p><img src="http://codehutch.com/images/final-encrypt.png" alt="" /></p>
<p><strong>Putting it in Codes [C#]<br />
</strong></p>
<p><strong>Encrypt:</strong></p>
<blockquote><p>public static string Encrypt(string orgStr, char keyChar)<br />
{<br />
string encrypted = &#8220;&#8221;;<br />
for (int i = 0; i &lt; orgStr.Length; i++)<br />
{<br />
encrypted += (char)(orgStr[i] ^ keyChar);<br />
}</p>
<p>return encrypted;<br />
}</p></blockquote>
<p><strong>Decrypt:</strong></p>
<blockquote><p>public static string Decrypt(string orgStr, char keyChar)<br />
{<br />
string decrypted = &#8220;&#8221;;<br />
foreach (char encChar in orgStr.ToCharArray())<br />
{<br />
decrypted += (char)(encChar ^ keyChar);<br />
}</p>
<p>return decrypted;<br />
}</p></blockquote>
<p><strong>Usage:</strong></p>
<blockquote><p>string encStr = Encrypt(&#8221;TEST&#8221;, &#8216;X&#8217;);<br />
Console.WriteLine(&#8221;Original String: TEST&#8221;);<br />
Console.WriteLine(&#8221;Encrypted String: &#8221; + encStr);<br />
Console.WriteLine(&#8221;Decrypted String: &#8221; + Decrypt(encStr, &#8216;X&#8217;));</p></blockquote>
<p><strong>Result:</strong></p>
<p><img src="http://codehutch.com/images/XOREncryption.png" alt="" /></p>
<p><strong><a href="http://codehutch.com/download-codes/">DOWNLOAD XOR ENCRYPTION CODE</a></strong></p>
<p>===================</p>
]]></content:encoded>
			<wfw:commentRss>http://codehutch.com/2011/11/xor-encryption/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Transact-SQL: Recursive User-defined Function</title>
		<link>http://codehutch.com/2011/10/recursive-user-defined-function-in-t-sql/</link>
		<comments>http://codehutch.com/2011/10/recursive-user-defined-function-in-t-sql/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 03:29:22 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[SQL]]></category>

		<category><![CDATA[Transact-SQL]]></category>

		<category><![CDATA[mssql sample script]]></category>

		<category><![CDATA[t-sql]]></category>

		<category><![CDATA[user-defined function]]></category>

		<guid isPermaLink="false">http://codehutch.com/?p=250</guid>
		<description><![CDATA[T-SQL can be a powerful tool for developers if exploited. It allows you to programatically manipulate your data on the &#8220;database-level&#8221;. This post will show a simple T-SQL script on how to create a recursive user-defined function [UDF] that can be used application-wide via a simple query. To demonstrate, we will use one of the [...]]]></description>
			<content:encoded><![CDATA[<p>T-SQL can be a powerful tool for developers if exploited. It allows you to programatically manipulate your data on the &#8220;database-level&#8221;. This post will show a simple T-SQL script on how to create a recursive user-defined function [UDF] that can be used application-wide via a simple query. To demonstrate, we will use one of the most common mathematical problems in which a recursive algorithm can be applied - solving for factorial.</p>
<p><strong>Create a UDF</strong></p>
<blockquote><p>Create Function [dbo].[Factorial]<br />
(<br />
@n int<br />
)<br />
Returns int</p>
<p>AS<br />
Begin</p>
<p>declare @factorial int</p>
<p>if @n = 0<br />
set @factorial = 1<br />
else<br />
set @factorial = @n * dbo.Factorial(@n - 1) &#8211;call it recursively</p>
<p>return @factorial</p></blockquote>
<p>You can then simply call it in any of your queries like:</p>
<blockquote><p>select dbo.Factorial(6) &#8211;returns 720</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://codehutch.com/2011/10/recursive-user-defined-function-in-t-sql/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Export XML into a comma-delimited (CSV) File</title>
		<link>http://codehutch.com/2011/10/export-xml-into-a-comma-delimited-csv-file/</link>
		<comments>http://codehutch.com/2011/10/export-xml-into-a-comma-delimited-csv-file/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 08:12:07 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Code]]></category>

		<category><![CDATA[VB .Net]]></category>

		<category><![CDATA[asp .net tutorial]]></category>

		<category><![CDATA[vb .net sample code]]></category>

		<guid isPermaLink="false">http://codehutch.com/?p=241</guid>
		<description><![CDATA[Here is a sample source code on how to read and load xml file via LINQ, extract the data [using a query] and export it to a CSV file.
The XML file (employee.xml)
&#60;xml&#62;
&#60;Employee id=&#8221;1&#8243;&#62;
&#60;Name&#62;John Doe&#60;/Name&#62;
&#60;Position&#62;President&#60;/Position&#62;
&#60;Salary&#62;$500,000&#60;/Salary&#62;
&#60;/Employee&#62;
&#60;Employee id=&#8221;2&#8243;&#62;
&#60;Name&#62;Jane Doe&#60;/Name&#62;
&#60;Position&#62;Vice President&#60;/Position&#62;
&#60;Salary&#62;$250,000&#60;/Salary&#62;
&#60;/Employee&#62;
&#60;Employee id=&#8221;3&#8243;&#62;
&#60;Name&#62;Jen Doe&#60;/Name&#62;
&#60;Position&#62;Manager&#60;/Position&#62;
&#60;Salary&#62;$50,000&#60;/Salary&#62;
&#60;/Employee&#62;
&#60;/xml&#62;


The code
&#8216;Libraries
Imports System
Imports System.IO
Imports System.Text
Imports System.Xml.Linq
Imports Microsoft.VisualBasic.FileIO
&#8216;=====================================
&#8216;Read/Load xml file
Dim employees As XElement = XElement.Load(&#8221;employee.xml&#8221;)
Dim outputData As New [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a sample source code on how to read and load xml file via LINQ, extract the data [using a query] and export it to a CSV file.</p>
<p><strong>The XML file (<span style="color: #ff0000;">employee.xml</span>)</strong></p>
<blockquote><p>&lt;xml&gt;<br />
&lt;Employee id=&#8221;1&#8243;&gt;<br />
&lt;Name&gt;John Doe&lt;/Name&gt;<br />
&lt;Position&gt;President&lt;/Position&gt;<br />
&lt;Salary&gt;$500,000&lt;/Salary&gt;<br />
&lt;/Employee&gt;<br />
&lt;Employee id=&#8221;2&#8243;&gt;<br />
&lt;Name&gt;Jane Doe&lt;/Name&gt;<br />
&lt;Position&gt;Vice President&lt;/Position&gt;<br />
&lt;Salary&gt;$250,000&lt;/Salary&gt;<br />
&lt;/Employee&gt;<br />
&lt;Employee id=&#8221;3&#8243;&gt;<br />
&lt;Name&gt;Jen Doe&lt;/Name&gt;<br />
&lt;Position&gt;Manager&lt;/Position&gt;<br />
&lt;Salary&gt;$50,000&lt;/Salary&gt;<br />
&lt;/Employee&gt;<br />
&lt;/xml&gt;<strong></strong></p>
<p><strong><br />
</strong></p></blockquote>
<p><strong>The code</strong></p>
<blockquote><p>&#8216;Libraries<br />
Imports System<br />
Imports System.IO<br />
Imports System.Text<br />
Imports System.Xml.Linq<br />
Imports Microsoft.VisualBasic.FileIO</p>
<p>&#8216;=====================================<strong></strong></p>
<p>&#8216;Read/Load xml file<br />
Dim employees As XElement = XElement.Load(&#8221;employee.xml&#8221;)<br />
Dim outputData As New StringBuilder</p>
<p>&#8216;query on loaded xml data and output as String Enumeration<br />
Dim xmlData = _<br />
From emp In employees.&lt;Employee&gt; _<br />
Select String.Format(&#8221;"&#8221;{0}&#8221;",&#8221;"{1}&#8221;",&#8221;"{2}&#8221;",&#8221;"{3}&#8221;"&#8221;, _<br />
emp.@id, _<br />
emp.&lt;Name&gt;.Value, _<br />
emp.&lt;Position&gt;.Value, _<br />
emp.&lt;Salary&gt;.Value)</p>
<p>&#8216;Traverse enum and append extracted data<br />
For Each row In xmlData<br />
outputData.AppendLine(row)<br />
Next</p>
<p>&#8216;Output as .txt file<br />
File.WriteAllText(&#8221;ParsedData.csv&#8221;, outputData.ToString)<strong></strong></p></blockquote>
<p><strong>The output as CSV file (<span style="color: #ff0000;">ParsedData.csv</span>)</strong></p>
<blockquote><p>&#8220;1&#8243;,&#8221;John Doe&#8221;,&#8221;President&#8221;,&#8221;$500,000&#8243;<br />
&#8220;2&#8243;,&#8221;Jane Doe&#8221;,&#8221;Vice President&#8221;,&#8221;$250,000&#8243;<br />
&#8220;3&#8243;,&#8221;Jen Doe&#8221;,&#8221;Manager&#8221;,&#8221;$50,000&#8243;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://codehutch.com/2011/10/export-xml-into-a-comma-delimited-csv-file/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using While Loop instead of Cursor</title>
		<link>http://codehutch.com/2011/10/using-while-loop-instead-of-cursor/</link>
		<comments>http://codehutch.com/2011/10/using-while-loop-instead-of-cursor/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 03:05:22 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[MS SQL]]></category>

		<category><![CDATA[Transact-SQL]]></category>

		<category><![CDATA[database guide]]></category>

		<category><![CDATA[mssql sample script]]></category>

		<guid isPermaLink="false">http://codehutch.com/?p=216</guid>
		<description><![CDATA[There are cases where using Cursor would do you more harm than good. It uses considerably large amount of resources in your server and not to mention that it can cause leaks if not used correctly (Eg. Open without corresponding Close). That&#8217;s why most T-SQL developer often suggest to avoid it whenever possible. Here is [...]]]></description>
			<content:encoded><![CDATA[<p>There are cases where using Cursor would do you more harm than good. It uses considerably large amount of resources in your server and not to mention that it can cause leaks if not used correctly (Eg. Open without corresponding Close). That&#8217;s why most T-SQL developer often suggest to avoid it whenever possible. Here is a sample code on how to travese a result set and get values of each row using a While Loop instead of a Cursor.</p>
<blockquote><p>
&#8211;identity INT (1,1) - surrogate PRIMARY KEY<br />
declare @tempTable table(id int identity(1,1),employeeName varchar(25),employeePosition varchar(25))</p>
<p>insert into @tempTable<br />
select &#8216;John&#8217;,'Manager&#8217;</p>
<p>insert into @tempTable<br />
select &#8216;Joe&#8217;,'Vice President&#8217;</p>
<p>insert into @tempTable<br />
select &#8216;Mary&#8217;,'Secretary&#8217;</p>
<p>declare @rowCount int<br />
select @rowCount = count(*) from @tempTable</p>
<p>declare @counter int<br />
select @counter = 1</p>
<p>while @counter &lt;= @rowCount<br />
begin</p>
<p>select * from @tempTable where id = @counter</p>
<p>select @counter = @counter + 1<br />
end</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://codehutch.com/2011/10/using-while-loop-instead-of-cursor/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to Lock a Routine in C#</title>
		<link>http://codehutch.com/2011/10/how-to-lock-a-routine/</link>
		<comments>http://codehutch.com/2011/10/how-to-lock-a-routine/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 01:46:37 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[Code]]></category>

		<category><![CDATA[c# sample code]]></category>

		<guid isPermaLink="false">http://codehutch.com/?p=210</guid>
		<description><![CDATA[This source code shows how to lock a certain routine so it cannot  be accessed/used by another process. To demonstrate this, we will use  Threads.
using System;
using System.Threading;
class ThreadLock
{
private int Tests = 0;
public void TestRun()
{
Thread t1 = new Thread(new ThreadStart(Exec));
t1.Name = &#8220;thread 1&#8243;;
Thread t2 = new Thread(new ThreadStart(Exec));
t2.Name = &#8220;thread 2&#8243;;
t1.Start();
t2.Start();
}
public void Exec()
{
while (Tests [...]]]></description>
			<content:encoded><![CDATA[<p>This source code shows how to lock a certain routine so it cannot  be accessed/used by another process. To demonstrate this, we will use  Threads.</p>
<blockquote><p>using System;<br />
using System.Threading;</p>
<p>class ThreadLock<br />
{</p>
<p>private int Tests = 0;</p>
<p>public void TestRun()<br />
{<br />
Thread t1 = new Thread(new ThreadStart(Exec));<br />
t1.Name = &#8220;thread 1&#8243;;<br />
Thread t2 = new Thread(new ThreadStart(Exec));<br />
t2.Name = &#8220;thread 2&#8243;;<br />
t1.Start();<br />
t2.Start();<br />
}</p>
<p>public void Exec()<br />
{<br />
while (Tests &lt; 5)<br />
{<br />
lock (this)<br />
{<br />
int count = Tests;<br />
count++;<br />
Console.WriteLine(count + &#8220;: &#8221; + Thread.CurrentThread.Name);<br />
Thread.Sleep(1000);<br />
Tests = count;<br />
}<br />
}<br />
}</p>
<p>static void Main(string[] args)<br />
{<br />
ThreadLock test = new ThreadLock();<br />
test.TestRun();<br />
}<br />
}</p></blockquote>
<p><strong>Result</strong><br />
<img src="http://codehutch.com/thread.png" alt="How to Lock a Routine in C#"></p>
]]></content:encoded>
			<wfw:commentRss>http://codehutch.com/2011/10/how-to-lock-a-routine/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Moving a File from one Folder/Directory to another</title>
		<link>http://codehutch.com/2011/10/moving-a-file-from-one-folderdirectory-to-another/</link>
		<comments>http://codehutch.com/2011/10/moving-a-file-from-one-folderdirectory-to-another/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 03:34:19 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Code]]></category>

		<category><![CDATA[VB .Net]]></category>

		<category><![CDATA[vb .net sample code]]></category>

		<guid isPermaLink="false">http://codehutch.com/?p=200</guid>
		<description><![CDATA[This is a sample function on how to move a file from one folder/directory to another while considering some factors such as:

 Is the file available? Or is it being used by another process?
 Does the file exists?
Does a file with the same filename exists in the destination folder?

Move File Function
&#8216;fromFile and toFile parameters consist [...]]]></description>
			<content:encoded><![CDATA[<p>This is a sample function on how to move a file from one folder/directory to another while considering some factors such as:</p>
<ul>
<li> Is the file available? Or is it being used by another process?</li>
<li> Does the file exists?</li>
<li>Does a file with the same filename exists in the destination folder?</li>
</ul>
<p><strong>Move File Function</strong></p>
<blockquote><p>&#8216;fromFile and toFile parameters consist of directory-path+filename+extension<br />
	Public Function MoveFile(ByVal fromFile As String, ByVal toFile As String) As Boolean</p>
<p>		&#8216;Check if File do exists<br />
		Dim fileExists As Boolean = System.IO.File.Exists(fromFile)</p>
<p>		&#8216;Check if File is being use by other process<br />
		Dim fileIsLock As Boolean = IsFileLocked(fromFile)</p>
<p>		&#8216;If file do exists and is not lock, begin transfer<br />
		If fileExists AndAlso Not fileIsLock Then</p>
<p>		&#8216;Check if file already exists in the destination folder<br />
		If System.IO.File.Exists(toFile) Then</p>
<p>			&#8216;delete file from destination folder and move new file [overwrite]<br />
			System.IO.File.Delete(toFile)<br />
			System.IO.File.Move(fromFile, toFile)<br />
			Return True</p>
<p>			&#8216;Of course you can always check the destination file information,<br />
			&#8216;and maybe decide whether to delete it or not and just rename the new file<br />
			&#8216;Example by getting file information<br />
			Dim destFile As New FileInfo(toFile)</p>
<p>			&#8216;Get size [in bytes]<br />
			If destFile.Length &gt; 0 Then<br />
			&#8216;decide what to do here if the destination file has some contents<br />
			&#8216;you might not want to overwrite it if it contains important data<br />
			End If</p>
<p>		Else<br />
			&#8216;If the file does not exists in the destination folder, just move<br />
			System.IO.File.Move(fromFile, toFile)<br />
			Return True<br />
		End If<br />
		Else<br />
			Return False<br />
		End If</p>
<p>	End Function
</p></blockquote>
<p><strong>Simple Function to check if file is locked</strong></p>
<blockquote><p>
	Public Function IsFileLocked(ByVal strFullFileName As String) As Boolean<br />
		Dim returnVal As Boolean = False<br />
		Dim fs As System.IO.FileStream = Nothing</p>
<p>		Try<br />
			fs = System.IO.File.Open(strFullFileName, IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite, IO.FileShare.None)<br />
		Catch ex As Exception<br />
			returnVal = True<br />
		Finally<br />
			If fs IsNot Nothing Then<br />
				fs.Close()<br />
			End If<br />
		End Try</p>
<p>		Return returnVal<br />
	End Function
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://codehutch.com/2011/10/moving-a-file-from-one-folderdirectory-to-another/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MSSQL: Split as an alternative to OpenXML</title>
		<link>http://codehutch.com/2011/09/mssql-split-as-an-alternate-to-openxml/</link>
		<comments>http://codehutch.com/2011/09/mssql-split-as-an-alternate-to-openxml/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 08:37:04 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[MS SQL]]></category>

		<category><![CDATA[Transact-SQL]]></category>

		<category><![CDATA[database guide]]></category>

		<category><![CDATA[mssql sample script]]></category>

		<guid isPermaLink="false">http://codehutch.com/?p=193</guid>
		<description><![CDATA[When working with MSSQL, there are cases where your simple stored procedure (SP) just won&#8217;t work when deployed to your live server even though it works perfectly on your local PC. I have encountered this problem a couple of days ago where my SP won&#8217;t work on Windows Azure SQL. I did some research and [...]]]></description>
			<content:encoded><![CDATA[<p>When working with MSSQL, there are cases where your simple stored procedure (SP) just won&#8217;t work when deployed to your live server even though it works perfectly on your local PC. I have encountered this problem a couple of days ago where my SP won&#8217;t work on Windows Azure SQL. I did some research and found out the as of now it does not support calling of OpenXML. And unfortunate, this function is needed in my SP. So instead of working on xml, I changed the parameter to string [delimited by a comma], split it and return as table. Here&#8217;s the code for the &#8220;split&#8221; function and how to use it in queries.<br />
Run the code below to create the Split function:</p>
<blockquote><p>
Create FUNCTION [dbo].[Split]<br />
(<br />
@InputArray NVARCHAR(max),<br />
@delimiter CHAR(1)<br />
)<br />
RETURNS @ReturnTable TABLE (ID INT,RValue NVARCHAR(150))<br />
AS</p>
<p>BEGIN<br />
DECLARE @TempArrayStr NVARCHAR(max)<br />
SET @TempArrayStr = @InputArray</p>
<p>DECLARE @i INT<br />
DECLARE @RValue NVARCHAR(max)<br />
DECLARE @counter INT = 1</p>
<p>SET @TempArrayStr = REPLACE (@TempArrayStr, &#8216; &#8216;, &#8221;)<br />
SET @i = CHARINDEX(@delimiter, @TempArrayStr)</p>
<p>WHILE (LEN(@TempArrayStr) &gt; 0)<br />
BEGIN<br />
IF @i = 0<br />
SET @RValue = @TempArrayStr<br />
ELSE<br />
SET @RValue = LEFT(@TempArrayStr, @i - 1)<br />
INSERT INTO @ReturnTable(ID,RValue) VALUES(@counter,@RValue)<br />
IF @i = 0<br />
SET @TempArrayStr = &#8221;<br />
ELSE<br />
SET @TempArrayStr = RIGHT(@TempArrayStr, LEN(@TempArrayStr) - @i)<br />
SET @i = CHARINDEX(@delimiter, @TempArrayStr)<br />
SET @counter = @counter + 1<br />
END<br />
RETURN<br />
END</p></blockquote>
<p>Sample usage:</p>
<blockquote><p>
declare @StringOfValues varchar(max)</p>
<p>set @StringOfValues = &#8216;value1,value2,value3,value4&#8242;</p>
<p>SELECT * FROM split(@StringOfValues, &#8216;,&#8217;)</p></blockquote>
<p><strong>Returns:</strong></p>
<p>ID  RValue</p>
<p><em>1    value1<br />
2    value2<br />
3    value3<br />
4    value4</em></p>
<blockquote><p>
SELECT * FROM split(@StringOfValues, &#8216;,&#8217;) where ID = 2</p></blockquote>
<p><strong>Returns:</strong></p>
<p>ID  RValue</p>
<p><em>2    value2</em></p>
]]></content:encoded>
			<wfw:commentRss>http://codehutch.com/2011/09/mssql-split-as-an-alternate-to-openxml/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Telerik Treview NodeClick Event</title>
		<link>http://codehutch.com/2011/05/telerik-treview-nodeclick-event/</link>
		<comments>http://codehutch.com/2011/05/telerik-treview-nodeclick-event/#comments</comments>
		<pubDate>Thu, 12 May 2011 04:29:01 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Code]]></category>

		<category><![CDATA[Telerik]]></category>

		<category><![CDATA[VB .Net]]></category>

		<category><![CDATA[asp .net tutorial]]></category>

		<category><![CDATA[telerik sample code]]></category>

		<guid isPermaLink="false">http://codehutch.com/?p=184</guid>
		<description><![CDATA[I&#8217;m currently using Telerik Treeview and I&#8217;m fascinated on how great its features are.  I have an example on NodeClick event.

Highlight parent/s when a node is clicked
The Treeview
&#60;telerik:RadTreeView ID=&#8221;MyTreeview&#8221; MultipleSelect=&#8221;true&#8221; OnNodeClick=&#8221;MyTreeviewClick&#8221; /&#62;
Note: MultipleSelect must be set to True
The Click routine
Protected Sub MyTreeviewClick(sender As Object, e As RadTreeNodeEventArgs)
SelectParent(e.Node)
End Sub
Highlight parent function
Protected Sub SelectParent(node As RadTreeNode)
If node.ParentNode [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently using Telerik Treeview and I&#8217;m fascinated on how great its features are.  I have an example on NodeClick event.<br />
<strong><br />
Highlight parent/s when a node is clicked</strong></p>
<p>The Treeview</p>
<blockquote><p>&lt;telerik:RadTreeView ID=&#8221;MyTreeview&#8221; MultipleSelect=&#8221;true&#8221; OnNodeClick=&#8221;MyTreeviewClick&#8221; /&gt;</p>
<p>Note: <strong>MultipleSelect </strong>must be set to <strong>True</strong></p></blockquote>
<p>The <strong>Click </strong>routine</p>
<blockquote><p>Protected Sub MyTreeviewClick(sender As Object, e As RadTreeNodeEventArgs)<br />
SelectParent(e.Node)<br />
End Sub</p></blockquote>
<p>Highlight parent function</p>
<blockquote><p>Protected Sub SelectParent(node As RadTreeNode)<br />
If node.ParentNode IsNot Nothing Then<br />
node.ParentNode.Selected = True<br />
End If<br />
End Sub</p></blockquote>
<p>If you want to highlight all parents of selected node, you can always call it recursively</p>
<blockquote><p>Protected Sub SelectParent(node As RadTreeNode)<br />
If node.ParentNode IsNot Nothing Then<br />
node.ParentNode.Selected = True<br />
<strong> SelectParents(node.ParentNode)</strong><br />
End If<br />
End Sub</p></blockquote>
<p><strong>Calling a routine on selected node</strong></p>
<p>You can use a variety of Nodes properties and functions. In this example I use node&#8217;s <strong>level property</strong> which returns the level [integer] of the the current node. This is helpful if you have static node levels. I&#8217;m calling my function ONLY on specific node level.</p>
<blockquote><p>Protected Sub MyTreeviewClick(sender As Object, e As RadTreeNodeEventArgs)<br />
If e.Node.Level = 2 Then<br />
//Do something here when any of the 2nd level node is clicked<br />
End If<br />
End Sub</p></blockquote>
<p>You can also use this to highlight parents <strong>only</strong> on selected node levels.</p>
<blockquote><p>Protected Sub MyTreeviewClick(sender As Object, e As RadTreeNodeEventArgs)<br />
If e.Node.Level = 2 Then<br />
<strong>SelectParent(e.Node)</strong><br />
End If<br />
End Sub</p></blockquote>
<p>Hope this helps <img src='http://codehutch.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://codehutch.com/2011/05/telerik-treview-nodeclick-event/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Extending Gridview Class</title>
		<link>http://codehutch.com/2011/03/extending-gridview-class/</link>
		<comments>http://codehutch.com/2011/03/extending-gridview-class/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 10:02:48 +0000</pubDate>
		<dc:creator>matt</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Code]]></category>

		<category><![CDATA[VB .Net]]></category>

		<category><![CDATA[vb .net sample code]]></category>

		<guid isPermaLink="false">http://codehutch.com/?p=178</guid>
		<description><![CDATA[When working on customized Gridview (especially when you&#8217;re planning to use it multiple times within your solution), you can always create your own class by extending the default Gridview.  So instead of putting all properties inside &#60;asp:GridView&#62; tag like this:
&#60;asp:GridView ID=&#8221;MyOwnGridViewID&#8221; runat=&#8221;server&#8221; CssClass=&#8221;MyOwnGridViewClass&#8221; AllowPaging=&#8221;true&#8221; PageSize=&#8221;25&#8243;&#62;
&#60;!&#8211; As well as other properties here &#8211;&#62;
&#60;/asp:GridView&#62;
You can simply call:
&#60;asp:MyOwnGridView [...]]]></description>
			<content:encoded><![CDATA[<p>When working on customized Gridview (especially when you&#8217;re planning to use it multiple times within your solution), you can always create your own class by extending the default Gridview.  So instead of putting all properties inside &lt;asp:GridView&gt; tag like this:</p>
<blockquote><p>&lt;asp:GridView ID=&#8221;MyOwnGridViewID&#8221; runat=&#8221;server&#8221; CssClass=&#8221;MyOwnGridViewClass&#8221; AllowPaging=&#8221;true&#8221; PageSize=&#8221;25&#8243;&gt;<br />
&lt;!&#8211; As well as other properties here &#8211;&gt;<br />
&lt;/asp:GridView&gt;</p></blockquote>
<p>You can simply call:</p>
<blockquote><p>&lt;asp:MyOwnGridView ID=&#8221;MyOwnGridViewID&#8221; runat=&#8221;server&#8221; /&gt;</p></blockquote>
<p>Here&#8217;s the code for your class (in VB):</p>
<blockquote><p>Public Class MyOwnGridView Inherits GridView</p>
<p>Public Sub New()<br />
Me.AllowPaging = true<br />
Me.CssClass = &#8220;MyOwnGridViewClass&#8221;<br />
Me.PageSize = &#8220;25&#8243;<br />
&#8230;etc<br />
End Sub</p>
<p>End Class</p></blockquote>
<p>The code is neat and easy to debug. <img src='http://codehutch.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://codehutch.com/2011/03/extending-gridview-class/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

