<?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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>theDeSilva.com&#187; .NET</title>
	<atom:link href="http://www.thedesilva.com/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thedesilva.com</link>
	<description>Andrew de Silva</description>
	<lastBuildDate>Wed, 10 Mar 2010 21:48:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using cmd.exe with VB.NET &#8211; Process.Start</title>
		<link>http://www.thedesilva.com/2010/01/using-cmd-exe-with-vb-net-process-start/</link>
		<comments>http://www.thedesilva.com/2010/01/using-cmd-exe-with-vb-net-process-start/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 00:04:14 +0000</pubDate>
		<dc:creator>Andrew de Silva</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[Process.start]]></category>
		<category><![CDATA[system diagnostics]]></category>
		<category><![CDATA[VB]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://www.thedesilva.com/?p=190</guid>
		<description><![CDATA[<img src="http://www.thedesilva.com/img/category_icon//VisualStudio_small.png" width="60" height="60" alt="" title=".NET" /><br/>Here&#8217;s a quick function to show the use of System.Diagnostic.Process which will allow you to start another application using VB.NET. The example below is used to call svnadmin to create a new repository ( Subversion ) by grabbing the repository name. The function also checks to see whether the directory exist on the file system [...]]]></description>
			<content:encoded><![CDATA[<img src="http://www.thedesilva.com/img/category_icon//VisualStudio_small.png" width="60" height="60" alt="" title=".NET" /><br/><p>Here&#8217;s a quick function to show the use of System.Diagnostic.Process which will allow you to start another application using VB.NET. The example below is used to call svnadmin to create a new repository ( Subversion ) by grabbing the repository name. The function also checks to see whether the directory exist on the file system and if it doesn&#8217;t it will start the command prompt svnadmin to create the folder. However if the folder does exist it will nag at you.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;">&nbsp;
<span style="color: #0600FF;">Sub</span> createRepo<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Dim</span> repoName <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> repoNameInput.<span style="color: #0000FF;">Text</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> dirExist <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Boolean</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
&nbsp;
        <span style="color: #0600FF;">If</span> System.<span style="color: #0000FF;">IO</span>.<span style="color: #0600FF;">Directory</span>.<span style="color: #0000FF;">Exists</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;C:\svn_repository\&quot;</span> <span style="color: #008000;">&amp;</span> repoName<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            dirExist <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
            result.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&lt;font color=&quot;</span><span style="color: #808080;">&quot;red&quot;</span><span style="color: #808080;">&quot;&gt;Repository Already Exist !&lt;/font&gt;&quot;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
        <span style="color: #0600FF;">If</span> <span style="color: #000000;">&#40;</span>repoName.<span style="color: #0000FF;">Length</span> &lt;&gt; <span style="color: #FF0000;">0</span> <span style="color: #804040;">And</span> dirExist <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #0600FF;">Dim</span> myProcess <span style="color: #FF8000;">As</span> Process <span style="color: #008000;">=</span> Process.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;cmd.exe&quot;</span>, <span style="color: #808080;">&quot;/k svnadmin create C:\svn_repository\&quot;</span> <span style="color: #008000;">&amp;</span> repoName<span style="color: #000000;">&#41;</span>
&nbsp;
            myProcess.<span style="color: #0000FF;">WaitForExit</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">10000</span><span style="color: #000000;">&#41;</span>
            <span style="color: #008080; font-style: italic;">' if the process doesn't complete within</span>
            <span style="color: #008080; font-style: italic;">' 10 seconds, kill it</span>
&nbsp;
            <span style="color: #0600FF;">If</span> <span style="color: #804040;">Not</span> myProcess.<span style="color: #0000FF;">HasExited</span> <span style="color: #FF8000;">Then</span>
                myProcess.<span style="color: #0600FF;">Kill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
            result.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Respository Created: &quot;</span> _
                <span style="color: #008000;">&amp;</span> myProcess.<span style="color: #0000FF;">ExitTime</span> <span style="color: #008000;">&amp;</span> _
                Environment.<span style="color: #0600FF;">NewLine</span> <span style="color: #008000;">&amp;</span> _
                <span style="color: #808080;">&quot;Exit Code (Troubleshooting Purpose): &quot;</span> <span style="color: #008000;">&amp;</span> _
                myProcess.<span style="color: #0000FF;">ExitCode</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

<p>You will have to import the following library to have the Process.Start to work.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Diagnostics</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.thedesilva.com/2010/01/using-cmd-exe-with-vb-net-process-start/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB.NET Database query return result as XML</title>
		<link>http://www.thedesilva.com/2010/01/vb-net-database-query-return-result-as-xml/</link>
		<comments>http://www.thedesilva.com/2010/01/vb-net-database-query-return-result-as-xml/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 20:00:31 +0000</pubDate>
		<dc:creator>Andrew de Silva</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[data source]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[DataSet]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.thedesilva.com/?p=186</guid>
		<description><![CDATA[<img src="http://www.thedesilva.com/img/category_icon//VisualStudio_small.png" width="60" height="60" alt="" title=".NET" /><br/>A simple VB.NET page that takes a ID variable and return the result as XML page. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 [...]]]></description>
			<content:encoded><![CDATA[<img src="http://www.thedesilva.com/img/category_icon//VisualStudio_small.png" width="60" height="60" alt="" title=".NET" /><br/><p>A simple VB.NET page that takes a ID variable and return the result as XML page.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;">&nbsp;
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">IO</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Xml</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Data</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">SqlClient</span>
&nbsp;
Partial <span style="color: #0600FF;">Class</span> writeXML
    <span style="color: #0600FF;">Inherits</span> System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>.<span style="color: #0000FF;">Page</span>
&nbsp;
&nbsp;
    Protected <span style="color: #0600FF;">Sub</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Load</span>
        GetXML<span style="color: #000000;">&#40;</span>Request.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;pid&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Function</span> sqlConnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> SqlConnection
        <span style="color: #0600FF;">Dim</span> oCn <span style="color: #FF8000;">As</span> SqlConnection <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> SqlConnection<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Data Source=xxxx\xxxx; Initial Catalog=tableName; User Id=dbUSERNAME; Password=dbPASSWORD&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Return</span> oCn
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span>
&nbsp;
    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> GetDataSet<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> strSQL <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> DataSet
&nbsp;
        <span style="color: #008080; font-style: italic;">'1. Create a connection</span>
        <span style="color: #0600FF;">Dim</span> myConnection <span style="color: #FF8000;">As</span> SqlConnection <span style="color: #008000;">=</span> sqlConnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'2. Create the command object, passing in the SQL string    </span>
        <span style="color: #0600FF;">Dim</span> myCommand <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> SqlCommand<span style="color: #000000;">&#40;</span>strSQL, myConnection<span style="color: #000000;">&#41;</span>
&nbsp;
        myConnection.<span style="color: #0600FF;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'3. Create the DataAdapter</span>
        <span style="color: #0600FF;">Dim</span> myDataAdapter <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> SqlDataAdapter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        myDataAdapter.<span style="color: #0000FF;">SelectCommand</span> <span style="color: #008000;">=</span> myCommand
&nbsp;
&nbsp;
        <span style="color: #008080; font-style: italic;">'4. Populate the DataSet and close the connection</span>
        <span style="color: #0600FF;">Dim</span> myDataSet <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> DataSet<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        myDataAdapter.<span style="color: #0000FF;">Fill</span><span style="color: #000000;">&#40;</span>myDataSet<span style="color: #000000;">&#41;</span>
        myConnection.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'Return the DataSet</span>
        <span style="color: #FF8000;">Return</span> myDataSet
&nbsp;
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span>
&nbsp;
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> GetXML<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> id <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> sqlCommand <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
&nbsp;
        sqlCommand <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;SELECT column1, column2  &quot;</span>
        sqlCommand <span style="color: #008000;">&amp;=</span> <span style="color: #808080;">&quot;FROM tableName &quot;</span>
        sqlCommand <span style="color: #008000;">&amp;=</span> <span style="color: #808080;">&quot;WHERE id = '&quot;</span> <span style="color: #008000;">&amp;</span> id <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;';  &quot;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> retrievedDataSet <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> DataSet
        retrievedDataSet <span style="color: #008000;">=</span> GetDataSet<span style="color: #000000;">&#40;</span>sqlCommand<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> xmlDocument <span style="color: #FF8000;">As</span> XmlDocument <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> XmlDocument
        xmlDocument.<span style="color: #0000FF;">LoadXml</span><span style="color: #000000;">&#40;</span>retrievedDataSet.<span style="color: #0000FF;">GetXml</span><span style="color: #000000;">&#41;</span>
&nbsp;
&nbsp;
        Response.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        Response.<span style="color: #0000FF;">ContentType</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;text/xml&quot;</span>
        Response.<span style="color: #0000FF;">ContentEncoding</span> <span style="color: #008000;">=</span> Encoding.<span style="color: #0000FF;">UTF8</span>
        Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span>xmlDocument.<span style="color: #0000FF;">InnerXml</span><span style="color: #000000;">&#41;</span>
        Response.<span style="color: #0000FF;">Flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        Response.<span style="color: #0600FF;">End</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.thedesilva.com/2010/01/vb-net-database-query-return-result-as-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resize image using VB.NET</title>
		<link>http://www.thedesilva.com/2010/01/resize-image-using-vb-net/</link>
		<comments>http://www.thedesilva.com/2010/01/resize-image-using-vb-net/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 19:35:39 +0000</pubDate>
		<dc:creator>Andrew de Silva</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[image height]]></category>
		<category><![CDATA[image width]]></category>
		<category><![CDATA[resize image]]></category>
		<category><![CDATA[VB]]></category>

		<guid isPermaLink="false">http://www.thedesilva.com/?p=178</guid>
		<description><![CDATA[<img src="http://www.thedesilva.com/img/category_icon//VisualStudio_small.png" width="60" height="60" alt="" title=".NET" /><br/>Here&#8217;s a quick function to resize image using VB.NET 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Sub ResizeImage&#40;ByVal dir As String, ByVal fileName As String, ByVal percentResize As Double&#41; 'following code resizes picture [...]]]></description>
			<content:encoded><![CDATA[<img src="http://www.thedesilva.com/img/category_icon//VisualStudio_small.png" width="60" height="60" alt="" title=".NET" /><br/><p>Here&#8217;s a quick function to resize image using VB.NET</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Sub</span> ResizeImage<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> <span style="color: #0600FF;">dir</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>, <span style="color: #FF8000;">ByVal</span> fileName <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>, <span style="color: #FF8000;">ByVal</span> percentResize <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Double</span><span style="color: #000000;">&#41;</span>
        <span style="color: #008080; font-style: italic;">'following code resizes picture to fit</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> bm <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> Bitmap<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;C:\&quot;</span> <span style="color: #008000;">&amp;</span> <span style="color: #0600FF;">dir</span> <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;\&quot;</span> <span style="color: #008000;">&amp;</span> fileName<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> <span style="color: #0600FF;">width</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span> <span style="color: #008000;">=</span> bm.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">-</span> <span style="color: #000000;">&#40;</span>bm.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">*</span> percentResize<span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">'image width. </span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> height <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span> <span style="color: #008000;">=</span> bm.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">-</span> <span style="color: #000000;">&#40;</span>bm.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">*</span> percentResize<span style="color: #000000;">&#41;</span>  <span style="color: #008080; font-style: italic;">'image height</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> thumb <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> Bitmap<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">width</span>, height<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> g <span style="color: #FF8000;">As</span> Graphics <span style="color: #008000;">=</span> Graphics.<span style="color: #0000FF;">FromImage</span><span style="color: #000000;">&#40;</span>thumb<span style="color: #000000;">&#41;</span>
&nbsp;
        g.<span style="color: #0000FF;">InterpolationMode</span> <span style="color: #008000;">=</span> Drawing2D.<span style="color: #0000FF;">InterpolationMode</span>.<span style="color: #0000FF;">HighQualityBicubic</span>
&nbsp;
        g.<span style="color: #0000FF;">DrawImage</span><span style="color: #000000;">&#40;</span>bm, <span style="color: #FF8000;">New</span> Rectangle<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #0600FF;">width</span>, height<span style="color: #000000;">&#41;</span>, <span style="color: #FF8000;">New</span> Rectangle<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, bm.<span style="color: #0600FF;">Width</span>, _
bm.<span style="color: #0000FF;">Height</span><span style="color: #000000;">&#41;</span>, GraphicsUnit.<span style="color: #0000FF;">Pixel</span><span style="color: #000000;">&#41;</span>
&nbsp;
        g.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        bm.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">'image path.</span>
        thumb.<span style="color: #0000FF;">Save</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;C:\&quot;</span> <span style="color: #008000;">&amp;</span> <span style="color: #0600FF;">dir</span> <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;\&quot;</span> <span style="color: #008000;">&amp;</span> fileName, _
System.<span style="color: #0000FF;">Drawing</span>.<span style="color: #0000FF;">Imaging</span>.<span style="color: #0000FF;">ImageFormat</span>.<span style="color: #0000FF;">Jpeg</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">'can use any image format </span>
&nbsp;
        thumb.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

<p>To use the code all you have to do is to pass in the directory of the image , the file name and the percentage of increase / decrease that you would like. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.thedesilva.com/2010/01/resize-image-using-vb-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Save File Stream using VB.NET</title>
		<link>http://www.thedesilva.com/2010/01/save-file-stream-using-vb-net/</link>
		<comments>http://www.thedesilva.com/2010/01/save-file-stream-using-vb-net/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 18:14:36 +0000</pubDate>
		<dc:creator>Andrew de Silva</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.thedesilva.com/?p=165</guid>
		<description><![CDATA[<img src="http://www.thedesilva.com/img/category_icon//VisualStudio_small.png" width="60" height="60" alt="" title=".NET" /><br/>Here is a simple VB.NET that would allow you to post a file stream from Flex. The class below saves the file into a location on your server. To use it you can simply use HTTP POST and pass in the directory save location using the query string dir. I used a catch try block [...]]]></description>
			<content:encoded><![CDATA[<img src="http://www.thedesilva.com/img/category_icon//VisualStudio_small.png" width="60" height="60" alt="" title=".NET" /><br/><p>Here is a simple VB.NET that would allow you to post a file stream from Flex.  The class below saves the file into a location on your server. To use it you can simply use HTTP POST and pass in the directory save location using the query string dir. I used a catch try block to log all error since I&#8217;m streaming this and will not see the error. You will find the code to the error logging <a href="http://www.thedesilva.com/2009/08/write-error-log-using-vb-net/">here</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;">&nbsp;
<span style="color: #0600FF;">Imports</span> System
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">IO</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Data</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Configuration</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Collections</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Web</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Security</span>
&nbsp;
&nbsp;
Partial <span style="color: #0600FF;">Class</span> FlexUpload
    <span style="color: #0600FF;">Inherits</span> System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>.<span style="color: #0000FF;">Page</span>
&nbsp;
    <span style="color: #FF8000;">Private</span> filePath <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
    <span style="color: #FF8000;">Private</span> fileStream <span style="color: #FF8000;">As</span> FileStream
    <span style="color: #FF8000;">Private</span> streamWriter <span style="color: #FF8000;">As</span> StreamWriter
&nbsp;
    Protected <span style="color: #0600FF;">Sub</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Load</span>
        <span style="color: #0600FF;">Dim</span> fileName <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
        <span style="color: #0600FF;">Dim</span> <span style="color: #0600FF;">dir</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> Request.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;dir&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> saveToFolder <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;C:\&quot;</span> <span style="color: #008000;">&amp;</span> <span style="color: #0600FF;">dir</span> <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;\&quot;</span>
&nbsp;
        <span style="color: #0600FF;">If</span> <span style="color: #008000;">File</span>.<span style="color: #0000FF;">Exists</span><span style="color: #000000;">&#40;</span>saveToFolder<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #008000;">File</span>.<span style="color: #0000FF;">Delete</span><span style="color: #000000;">&#40;</span>saveToFolder<span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
        <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">Directory</span>.<span style="color: #0000FF;">Exists</span><span style="color: #000000;">&#40;</span>saveToFolder<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #008080; font-style: italic;">' do nothing directory exist</span>
        <span style="color: #FF8000;">Else</span>
            <span style="color: #0600FF;">Directory</span>.<span style="color: #0000FF;">CreateDirectory</span><span style="color: #000000;">&#40;</span>saveToFolder<span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
        <span style="color: #0600FF;">Try</span>
            <span style="color: #0600FF;">Dim</span> i <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span>
&nbsp;
            <span style="color: #FF8000;">For</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">To</span> Request.<span style="color: #008000;">Files</span>.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span>
                fileName <span style="color: #008000;">=</span> System.<span style="color: #0000FF;">IO</span>.<span style="color: #0000FF;">Path</span>.<span style="color: #0000FF;">GetFileName</span><span style="color: #000000;">&#40;</span>Request.<span style="color: #008000;">Files</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">FileName</span><span style="color: #000000;">&#41;</span>
                Request.<span style="color: #008000;">Files</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">SaveAs</span><span style="color: #000000;">&#40;</span>saveToFolder <span style="color: #008000;">&amp;</span> fileName<span style="color: #000000;">&#41;</span>
            <span style="color: #FF8000;">Next</span>
&nbsp;
        <span style="color: #0600FF;">Catch</span> ex <span style="color: #FF8000;">As</span> Exception
            WriteLog<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Error :&quot;</span> <span style="color: #008000;">&amp;</span> DateTime.<span style="color: #0600FF;">Now</span> <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot; &quot;</span> <span style="color: #008000;">&amp;</span> ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Try</span>
&nbsp;
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">' Error Logging Functions </span>
     <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> OpenFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Dim</span> strPath <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
        strPath <span style="color: #008000;">=</span> MapPath<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;~&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;\Error.log&quot;</span>
        <span style="color: #0600FF;">If</span> System.<span style="color: #0000FF;">IO</span>.<span style="color: #008000;">File</span>.<span style="color: #0000FF;">Exists</span><span style="color: #000000;">&#40;</span>strPath<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            fileStream <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> FileStream<span style="color: #000000;">&#40;</span>strPath, FileMode.<span style="color: #0000FF;">Append</span>, FileAccess.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Else</span>
            fileStream <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> FileStream<span style="color: #000000;">&#40;</span>strPath, FileMode.<span style="color: #0000FF;">Create</span>, FileAccess.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
        StreamWriter <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> StreamWriter<span style="color: #000000;">&#40;</span>fileStream<span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> WriteLog<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> strComments <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
        OpenFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        StreamWriter.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>strComments<span style="color: #000000;">&#41;</span>
        CloseFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> CloseFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        StreamWriter.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        fileStream.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.thedesilva.com/2010/01/save-file-stream-using-vb-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write Error Log using VB.NET</title>
		<link>http://www.thedesilva.com/2009/08/write-error-log-using-vb-net/</link>
		<comments>http://www.thedesilva.com/2009/08/write-error-log-using-vb-net/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 21:19:17 +0000</pubDate>
		<dc:creator>Andrew de Silva</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[error log]]></category>
		<category><![CDATA[filestream]]></category>
		<category><![CDATA[streamwriter]]></category>
		<category><![CDATA[vbnet]]></category>
		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://www.thedesilva.com/?p=155</guid>
		<description><![CDATA[<img src="http://www.thedesilva.com/img/category_icon//VisualStudio_small.png" width="60" height="60" alt="" title=".NET" /><br/>There are times when you will need to write something to the screen to debug your VB.NET code and find it impossible as there are certain things that doesn&#8217;t really display a page. A web service don&#8217;t normally show a web page after it&#8217;s been called and it&#8217;s such a pain to debug errors if [...]]]></description>
			<content:encoded><![CDATA[<img src="http://www.thedesilva.com/img/category_icon//VisualStudio_small.png" width="60" height="60" alt="" title=".NET" /><br/><p>There are times when you will need to write something to the screen to debug your VB.NET code and find it impossible as there are certain things that doesn&#8217;t really display a page. A web service don&#8217;t normally show a web page after it&#8217;s been called and it&#8217;s such a pain to debug errors if you can&#8217;t really see what&#8217;s going wrong. Here&#8217;s a handy way to debug your code, write your error to an error log where you can view the log easily. Here are some code examples.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;">    <span style="color: #0600FF;">Imports</span> System
    <span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">IO</span>
    <span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Data</span>
&nbsp;
    <span style="color: #FF8000;">Private</span> filePath <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
    <span style="color: #FF8000;">Private</span> fileStream <span style="color: #FF8000;">As</span> FileStream
    <span style="color: #FF8000;">Private</span> streamWriter <span style="color: #FF8000;">As</span> StreamWriter
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> OpenFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Dim</span> strPath <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
        strPath <span style="color: #008000;">=</span> MapPath<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;~&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;\Error.log&quot;</span>
        <span style="color: #0600FF;">If</span> System.<span style="color: #0000FF;">IO</span>.<span style="color: #008000;">File</span>.<span style="color: #0000FF;">Exists</span><span style="color: #000000;">&#40;</span>strPath<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            fileStream <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> FileStream<span style="color: #000000;">&#40;</span>strPath, FileMode.<span style="color: #0000FF;">Append</span>, FileAccess.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Else</span>
            fileStream <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> FileStream<span style="color: #000000;">&#40;</span>strPath, FileMode.<span style="color: #0000FF;">Create</span>, FileAccess.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
        StreamWriter <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> StreamWriter<span style="color: #000000;">&#40;</span>fileStream<span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> WriteLog<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> strComments <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
        OpenFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        StreamWriter.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>strComments<span style="color: #000000;">&#41;</span>
        CloseFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> CloseFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        StreamWriter.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        fileStream.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

<p>Here&#8217;s how you would use the error log</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;">    <span style="color: #0600FF;">Try</span>
    <span style="color: #008080; font-style: italic;">'Do something</span>
&nbsp;
    <span style="color: #0600FF;">Catch</span> ex <span style="color: #FF8000;">As</span> Exception
        WriteLog<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Error :&quot;</span> <span style="color: #008000;">&amp;</span> <span style="color: #FF0000;">Date</span>.<span style="color: #0600FF;">Today</span>.<span style="color: #0000FF;">ToString</span> <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot; &quot;</span> <span style="color: #008000;">&amp;</span> ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Try</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.thedesilva.com/2009/08/write-error-log-using-vb-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
