tag:blogger.com,1999:blog-39099211299701832742024-03-20T21:25:49.731-07:00DeveloperGgabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-3909921129970183274.post-88101771045452701182013-11-24T23:55:00.001-08:002013-11-24T23:55:36.144-08:00How we can get the installed voices using c#?<div dir="ltr" style="text-align: left;" trbidi="on">
This sample code will get the installed voices using C# SpeechSynthesizer and will load in to a combo box.<br />
<br />
using (SpeechSynthesizer synth = new SpeechSynthesizer())<br />{<br />
foreach (InstalledVoice voice in synth.GetInstalledVoices())<br /> {<br /> VoiceInfo info = voice.VoiceInfo;<br /> cmbVoices.Items.Add(info.Description + ", " + info.Gender + ", " + info.Age);<br /> installedVoices.Add(info);<br /> }<br />
if (cmbVoices.Items.Count > 0)<br /> {<br /> cmbVoices.SelectedIndex = 0;<br /> }<br />}
<br />
<div>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- developer only image -->
<ins class="adsbygoogle"
style="display:inline-block;width:336px;height:280px"
data-ad-client="ca-pub-0384370072978340"
data-ad-slot="9406738592"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</div>
Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com0tag:blogger.com,1999:blog-3909921129970183274.post-5957782598455612662013-11-12T00:21:00.001-08:002013-11-12T00:25:58.689-08:00What is White framework?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<b><span style="font-size: 22.0pt; line-height: 115%;"><br />What is White framework?<o:p></o:p></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
White framework is an open-source framework which provides a
handful of features to automate UI applications. By using White framework we
can simulate a user effectively. For
example, if we want to perform some stereo type actions too many times like
Launch an application, Click on a button, select a value, etc.. it might be awkward.
If there is no decision making required then it has much worse situation. In
these kinds of situations, we can avoid a human being from doing this. Instead
we can have automation tool to simulate the human being.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
White framework is basically a Test Automation tool, but we
can use this to do the automation also. In simple words we can launch an
application, can find buttons and other controls, can simulate mouse moves and
clicks, activate controls, etc… That means everything which can be possible
using Windows APIs.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
White framework is developed using .NET 3 runtime. This uses
windows UI automation library and Windows messages. If a developer uses white
framework he does not worry about the PInvoke related activities. We can say
White framework is a wrapper above the UI automation library and Windows
messages.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
White framework can be used to automate applications which
are developed using Win32, WinForms, WPF, Silverlight and SWT (Java) platforms.
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 30.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 7.5pt; mso-outline-level: 2;">
<b><span style="font-size: 22.0pt;">White
framework Architecture </span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhj1khSh9g1x0AP1PSTsg3lAe4sa5gX9zMTUUNYLNiRg5KS40jFpBJrUy0_4n3qvIR0NW280ufsvwlncq736Fkze641VFEs6Lxq0rS3qfiZpcFcvjpfb6K_7USWwNryMmxegP7gBYIiju-o/s1600/Untitled.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhj1khSh9g1x0AP1PSTsg3lAe4sa5gX9zMTUUNYLNiRg5KS40jFpBJrUy0_4n3qvIR0NW280ufsvwlncq736Fkze641VFEs6Lxq0rS3qfiZpcFcvjpfb6K_7USWwNryMmxegP7gBYIiju-o/s320/Untitled.jpg" width="320" /></a></div>
<div class="MsoNormal" style="background: white; line-height: 30.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 7.5pt; mso-outline-level: 2;">
<b><span style="font-size: 22.0pt;"><br /></span></b></div>
<div class="MsoNormal" style="background: white; line-height: 30.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 7.5pt; mso-outline-level: 2;">
<b><span style="font-size: 22.0pt;">Helpful Links</span></b></div>
<div class="MsoNormal" style="background: white; line-height: 30.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 7.5pt; mso-outline-level: 2;">
<br /></div>
<div class="MsoNormal">
Source code can be found here: <a href="https://github.com/TestStack/White">https://github.com/TestStack/White</a><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
Documentation can be found here: <a href="http://teststack.azurewebsites.net/white/index.html">http://teststack.azurewebsites.net/white/index.html</a><o:p></o:p></div>
</div>
<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- developer only image -->
<ins class="adsbygoogle"
style="display:inline-block;width:336px;height:280px"
data-ad-client="ca-pub-0384370072978340"
data-ad-slot="9406738592"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com0tag:blogger.com,1999:blog-3909921129970183274.post-70633536065370718002013-05-12T22:48:00.000-07:002013-05-12T22:48:16.903-07:00Basics Of Attributes in .Net FrameworkThe Attributes are the declarative informations used to instruct the .Net Runtime. The attributes can work with types, fields, methods and properties. These informations are stored with the metadata file. By using the Attributes the developer can control the CLR. So we will get a dynamic behaviour from the CLR.<br /><br />Eg:- <strong>Serializable </strong>is an Attribute.<br /><br />Usage of Attributes in VB.Net(Sample):<br /><pre><br /><Serializable()> _<br /> Public Class Employee<br /> Public Name As String<br /> Public Designation As String<br /> End Class<br /><br /></pre><br /><br />Usage of Attributes in C#.Net(Sample):<br /><br /><pre><br />[Serializable()]<br />public class Employee<br />{<br /> public string Name;<br /> public string Designation;<br />}<br /></pre><br /><br />Note: All the attributes are classes that derived from <strong>System.Attribute</strong> class.<br /><br /><br />.Net framework has a lot of attributes that can be used for controlling XML serialization, Web services, COM interoperability etc.. And .Net provides the oppertunity to create custom attributes.
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com17tag:blogger.com,1999:blog-3909921129970183274.post-41825603187079437322013-05-12T22:47:00.000-07:002013-05-12T22:47:53.463-07:00Different Methods to Load Assembly Dynamically in .Net<div dir="ltr" style="text-align: left;" trbidi="on">
<ol><br />
<li>Assembly.LoadFrom : Loads an assembly given its file name or path. Loads the assembly from the specified path, this will not search for the assembly in other directories. If an assembly with the same identity is already loaded, LoadFrom returns the loaded assembly even if a different path was specified. </li>
<br />
<li>Assembly.LoadFile : Loads the contents of an assembly file on the specified path.</li>
<br />
<li>Assembly.ReflectionOnlyLoad :</li>
<br />
<li>Assembly.Load : This method takes the name of the assembly, and the runtime searches for the assembly in different locations. These locations include local directory and global assembly cache. </li>
<br />
<li>Assembly.LoadWithPartialName :</li>
</ol>
<br />
<br />
<br />
<i>This is an incomplete article. I will be back with more details.</i></div>
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com13tag:blogger.com,1999:blog-3909921129970183274.post-5843569199102690242013-05-10T04:30:00.001-07:002013-05-12T22:45:43.711-07:00Add blog to Google search<div dir="ltr" style="text-align: left;" trbidi="on">
You can add your blog to google search by submitting your URL to <a href="http://blogsearch.google.com/ping">http://blogsearch.google.com/ping</a>. Here you need to give <url>/atom.xml
<br />
Once it is listed by google, you need to continuously update the blog with good articles. Also need to add relevant tags.
This will make the blog to be listed in the searches in the toplist.
<br /></div>
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer */
google_ad_slot = "7423268198";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com1tag:blogger.com,1999:blog-3909921129970183274.post-719515191650035402013-04-24T04:57:00.003-07:002013-05-12T22:46:09.514-07:00How to send Email from SQL Server with attached csv file<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Please see the below sample code which will send email which will have an csv attachement.
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<br />
<br />
<br />
<span class="Apple-style-span" style="background-color: #ead1dc;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Exec [msdb].[dbo].[sp_send_dbmail] </span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"><span class="Apple-tab-span" style="white-space: pre;"> </span>@profile_name = '<db mail="" name="" profile="">',</db></span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"><span class="Apple-tab-span" style="white-space: pre;"> </span>@recipients = 'emailid',</span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"><span class="Apple-tab-span" style="white-space: pre;"> </span>@body = '</span><span class="Apple-style-span" style="background-color: #ead1dc;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Hello Sir,</span><span class="Apple-style-span" style="background-color: #ead1dc;">Please find the attached</span><span class="Apple-style-span" style="background-color: #ead1dc;"> details...',</span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"><span class="Apple-tab-span" style="white-space: pre;"> </span>@body_format ='HTML',</span></div>
<span class="Apple-style-span" style="background-color: #ead1dc;"><span class="Apple-tab-span" style="white-space: pre;"> </span>@subject = 'Subject',</span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"> @attach_query_result_as_file = 1, </span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"> @query_result_header = 1,</span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"> @query_result_no_padding = 1,</span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"> @query = 'SET NOCOUNT ON; SELECT EmployeeName, Address </span><span class="Apple-style-span" style="background-color: #ead1dc;">FROM EmployeeDetails',</span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"> @query_result_separator = '<span class="Apple-tab-span" style="white-space: pre;"> </span>',</span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"> @exclude_query_output = 1,</span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"> @query_attachment_filename = 'EmployeeDetails.csv'</span><br />
<span class="Apple-style-span" style="background-color: #ead1dc;"><br /></span>
<span class="Apple-style-span" style="background-color: #ead1dc;"><br /></span>
</div>
<br/>
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer */
google_ad_slot = "7423268198";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com6tag:blogger.com,1999:blog-3909921129970183274.post-83045706157155662332009-09-30T03:39:00.000-07:002013-05-12T22:47:18.982-07:00Web Farm and ASP.NET<div dir="ltr" style="text-align: left;" trbidi="on">
This is an abstract of the Web Farming in ASP.NET. Just like “Capsule”. Before discussing about Web Farm, we need to get some basic knowledge about Server Farming.<br />
<br />
<strong>What is a Cluster Computer or Server Farm?</strong><br />
<br />
Cluster Computer (Server Farm) is virtually a SINGLE computer system, but logically it includes multiple computers. That means, there are multiple computers, but it works as a single unit. These computers are usually connected by Local Area Network. The Load Balancing logic decides how/which computer in the Cluster to do the task.<br />
<br />
<strong>Load Balancer</strong><br />
<br />
Load Balancer can be Software or a dedicated Hardware, but its function is same to forward the request to actual Server. The Load Balancer will decide which server should be used for getting optimal performance. The decision will be based on the configured scheduling algorithm. Example for scheduling algorithm: - Round Robin, Random, Weighted Round Robin etc..<br />
<br />
<strong>What is Web Farm?</strong><br />
<br />
A major use of Server Farm is for hosting web sites. In this case we will call the server farm as Web Farm. By using web farm for hosting web site we can make sure the availability and performance of the web site.<br />
<br />
<strong>How it works?</strong><br />
<br />
The web farm is a collection of web servers, but all are hosted with same websites. If a user requests an HTML page in the website (Eg:- <em>http://testserver.com/home.html</em>), this will come to the Load Balancer. Then it will forward this request to anyone of the web server. That means all the requests to the website are routed through the Load Balancer. So we cannot say the user will be served by the same web server for all his requests.<br />
<br />
<strong>Web Farm & ASP.NET</strong><br />
<br />
Simply a website is stateless. That means it will forget all about the previous page request. For example, User A requests home.html, then Aboutus.html. Here the web site cannot identify both requests are from the same user. Each request will be treated as an independent request.<br />
<br />
Microsoft ASP.NET has an advance feature, it provides Session State Management. That means it keeps memory of the page requests. So it can identify the requests from the same user. <br />
<br />
So the problem arises in the Web Farm.<br />
<br />
Assume, we are browsing a shopping web site for purchasing a Laptop. The <em>Products.html</em> page contains all the models of Laptop and “Purchase” button against each Laptop. While clicking on the “Purchase” button the users will be redirected to <em>CreditCarddetails.html </em>page and collects the details. Here the website keeps the Product selected in the first page in his memory for later processing. If this happens in a web farm, there will be a problem. For instance, the first request will be to Webserver1 and second will be to Webserver2. So Webserver2 will not get the information collected in the first request.<br />
<br />
<strong>Solutions For this Problem</strong><br />
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<br />
There are too many solutions for this problem. These are the commonly used solutions<br />
<br />
1. Use SQL Server or State Server for keeping state information.<br />
Here the state information will be kept in a shared Database or a shared service. So all the web servers can access this and can recollect its memory even though the previous request was to another web server.<br />
<br />
2. Persistence/Stickiness.<br />
This is usually done through client side page redirecting. The first request will be through the load balancer, while processing the first request the URL will be replaced with new URL. This new URL is the URL of an individual web server not the Load Balancer. The main problem is, the underlying web servers are visible to the network.</div>
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com5tag:blogger.com,1999:blog-3909921129970183274.post-2042560728657303152008-02-12T22:17:00.000-08:002013-05-12T22:48:51.594-07:00FileSystemWatcher: Monitor for File changes using C#.Net<div dir="ltr" style="text-align: left;" trbidi="on">
This example will show messages if there is any file change in the specified folder. But i added a file filter condition for text files(*.txt). So it will monintor only for txt files. The changes like create new file, rename a file, accessing files etc.. will be notified by a message Box.<br />
<br />
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
The following code snippet will create a file watcher and initialize its properties, then enable it for monitoring.<br />
<br />
<span style="color: #660000; font-size: 85%;">FileSystemWatcher watcher = new FileSystemWatcher(); <span style="color: #000099;">// Declares the FileSystemWatcher object</span>watcher.Path = @"D:\MyDownloads"; <span style="color: #000099;">// We have to specify the path which has to monitor</span><br />watcher.NotifyFilter = NotifyFilters.LastAccess NotifyFilters.LastWrite NotifyFilters.FileName notifyFilters.DirectoryName; <span style="color: #000099;">// This property specifies which are the events to be monitored</span>watcher.Filter = "*.txt"; <span style="color: #000099;">// Only watch text files.</span><span style="color: #000099;">// Add event handlers.</span><br />watcher.Changed += new FileSystemEventHandler(OnChanged);<br />watcher.Created += new FileSystemEventHandler(OnChanged);<br />watcher.Deleted += new FileSystemEventHandler(OnChanged);<br />watcher.Renamed += new RenamedEventHandler(OnRenamed);<br /><span style="color: #000099;">// Begin watching.</span><br />watcher.EnableRaisingEvents = true;</span><br />
<span style="color: #660000; font-size: 85%;"></span><br />
<span style="color: black; font-size: 85%;">The following code for event handlers:</span><br />
<span style="color: #660000; font-size: 85%;"><br /><span style="color: #000099;">// Define the event handlers.</span><br />private static void OnChanged(object source, FileSystemEventArgs e)<br />{<br /><span style="color: #000099;">// Specify what is done when a file is changed, created, or deleted.</span><br />MessageBox.Show("File: " + e.FullPath + " " + e.ChangeType);<br />}<br />private static void OnRenamed(object source, RenamedEventArgs e)<br />{<br /><span style="color: #000099;">// Specify what is done when a file is renamed.</span><br />MessageBox.Show("File: "+ e.OldFullPath+" renamed to "+ e.FullPath);<br />}</span></div>
Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com12tag:blogger.com,1999:blog-3909921129970183274.post-50263770736956128782008-02-12T08:04:00.000-08:002013-05-12T22:49:10.752-07:00Path class - VB.Net, C#.Net<div dir="ltr" style="text-align: left;" trbidi="on">
The Path class provides methods for manipulating a file system path.<br />
Path Methods<br /><br />ChangeExtension: Takes a path and returns a new path with the file name's extension changed. (Note that only the path string changes, not the actual file name extension.)<br />Combine: Combines two compatible path strings.<br />GetDirectoryName: Returns the name of the directory in the specified path.<br />GetExtension: Returns the name of the file extension in the specified path.<br />GetFileName: Returns the name of the file in the specified path.<br />GetFileNameWithoutExtension: Returns the file name without the extension in the<br />specified path.<br />GetFullPath: Returns a full path to the specified path. This method can be used to resolve relative paths.<br />GetPathRoot: Returns the root directory name in the specified path.<br />GetRandomFileName: Generates a random file name.<br />GetTempFileName: Generates a temporary file in the file system and returns the full path to the file.<br />GetTempPath: Returns the path to the temporary file directory for the current user or system.<br />HasExtension: Indicates whether a specified path's file name has an extension.<br />IsPathRooted: Indicates whether the specified path includes a root directory.</div>
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com15tag:blogger.com,1999:blog-3909921129970183274.post-47045526129668438682008-02-12T07:54:00.000-08:002013-05-12T22:49:35.640-07:00DriveInfo - Listing Drives in C#.NetExample:<br />DriveInfo[] mydrives = DriveInfo.GetDrives();<br /><br />foreach (DriveInfo mydrive in mydrives)<br />{<br />Console.WriteLine("Drive: {0}", mydrive.Name);<br />Console.WriteLine("Type: {0}", mydrive.DriveType);<br />}<br /><br />Note:<br />- GetDrives() is a static( shared in VB.Net) method.<br /><br />- DriveType enumeration has the following values:<br />CDRom - An optical drive. It can be CD-ROM, DVD, and so on.<br />Fixed - A fixed disk.<br />Network - A network mapped drive.<br />NoRootDirectory - A drive that does not have a root directory.<br />Ram - A RAM drive.<br />Removable - A drive that has removable media.<br />Unknown - The drive could not be determined
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com1tag:blogger.com,1999:blog-3909921129970183274.post-85313731019602025772008-02-12T07:41:00.000-08:002013-05-12T22:49:59.196-07:00DirectoryInfo class: Listing files in the specified directory - VB.Net, C#.NetThe DirectoryInfo class provides the basic functionality to access and manipulate a single directory in the file system.<br /><br />Properties:<br />Parent<br />Root<br />Methods:<br />Create<br />CreateSubDirectory<br />GetDirectories<br />GetFiles<br />GetFileSystemInfo<br />MoveTo<br /><br />Example: This exaple will list all files in the specified directory<br /><br />DirectoryInfo myDir = new DirectoryInfo(@"H:\movies");<br /><br />Console.WriteLine("Directory: {0}", myDir.FullName);<br /><br />foreach (FileInfo myfile in myDir.GetFiles())<br />{<br />Console.WriteLine("File: {0}", myfile.Name);<br />}
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com1tag:blogger.com,1999:blog-3909921129970183274.post-7052657458964540662008-02-12T07:21:00.000-08:002013-05-12T22:50:16.068-07:00How to copy, move files in C# .NetExample:<br />Use system.IO namespace<br /><br />FileInfo myfile = new FileInfo(@"H:\myphoto.jpg");<br /><br />if (myfile.Exists)<br />{<br />myfile.CopyTo(@"H:\myphoto.bak",true );<br />myfile.MoveTo(@"H:\photos\photo.jpg");<br />}<br /><br />- If the second parameter is true, the existing file will be replaced.<br />- If we specify an invalid path in MoveTo() it will throw DirectoryNotFoundException.
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com0tag:blogger.com,1999:blog-3909921129970183274.post-88370297964414244742008-02-12T07:12:00.000-08:002013-05-12T22:50:37.731-07:00How to Get Information about File in c#.NetExample:<br /><br />FileInfo myfile = new FileInfo(@"H:\myphoto.jpg");<br /><br />if (myfile.Exists)<br />{<br />Console.WriteLine("File name : {0}", myfile.Name);<br />Console.WriteLine("Path : {0}", myfile.FullName);<br />Console.WriteLine("Creation Time: {0}", myfile.CreationTime);<br />Console.WriteLine("Length : {0}", myfile.Length);<br />}<br /><br />Note: "@" this symbol is used in string type to turn off escape processing. i.e If escape processing is turned on compiler will look for valid escape characters, if there is any invalid escape symbol it will throw compilation error.
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com0tag:blogger.com,1999:blog-3909921129970183274.post-25040398609719703972007-08-14T03:20:00.000-07:002013-05-12T22:51:29.237-07:00Just For Ajax<div dir="ltr" style="text-align: left;" trbidi="on">
<div align="justify">
Before starting the AJAX, I would like to tell some common problems that I could face in websites as a user. I have only dial up connection. And I never got more than 45 Kbps yet.<br />
<br />
1. I need to wait a long time in front of computer for getting next information. This may be next page or some information to some control those are already rendered. I can tell a small example. Just imagine a registration form. First it will ask to select a country. After selecting a country, page will submit this information to the server. Then it will reload the same page with state codes. This is very feasible to select a state code. But there is a huge time loss between the two selections. <em>Can we avoid this irritating facility? </em><br />
<em><br /></em>2. Imagine the page contains a large amount of data (it may include users filled information also). After we selecting the country the system will put all information in to the view state and submits. Then it will come again to the browser after a round trip. What a stupid data transfer just for one information. This is a good example for wasting memory and network bandwidth. <em>Can we avoid this?</em><br />
<br />
Yes. The answer for these two questions is AJAX.<br />
<br />
With the Ajax we can change the above imagination.<br />
<br />
We will never feel the dynamic loading of state codes. There is no page submission, refreshing. It will send only the country info to the server and it will load the state code without a page submission. This is very efficient, because there is no interrupt between the country selection and state selection. And no need to round trip of all data. Only the necessary information needs to send to the server.<br />
<br />
I think now you got the advantages of the AJAX.<br />
<br />
So we can discuss some basics of AJAX but not too much technical.<br />
<br />
AJAX stands for <strong>Asynchronous JavaScript and XML</strong>.<br />
<br />
If you have some basic knowledge in HTML, XML and JavaScript then you can start coding with AJAX support. Ajax uses the standards of HTML, XML, CSS and JavaScript. This is a browser technology so we don't need to install other packages for coding. But Ajax frameworks like Ajax.NET, Echo, Xajax are available for easy coding.<br />
<br />
<a href="http://abendas.googlepages.com/ajax_eg.htm" target="_blank">Click here for an Ajax example</a>. I am using the "<span style="color: #ff6666;">Please enter 1, 2, 3</span>" section of this example to explain remaining part.<br />
<br />
<strong>How Ajax works?</strong><br />
<br />
This uses very simple way for data transfer. First it will create <strong>XMLHttpRequest</strong> object, then it can send and receive data from web server without refreshing the page. This uses asynchronous data transfer between browser and web server.<br />
<br />
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
The following browsers support the Ajax: </div>
<div align="justify">
<br />
<span style="color: #990000;"><span style="color: #660000;">Internet Explorer 5.0+<br />Safari 1.2<br />Mozilla 1.0 / Firefox<br />Opera 8+<br />Netscape 7</span></span><br />
Let us look how to create <em>XMLHttpRequest</em> object using JavaScript.<br />
<br />
<span style="color: #990000;">function createXHR()<br />{<br />var request = false;<br />try {<br />request = new ActiveXObject("Msxml2.XMLHTTP");<br />}<br />catch (err2) {<br />try {<br />request = new ActiveXObject("Microsoft.XMLHTTP");<br />}<br />catch (err3) {<br />try {<br />request = new XMLHttpRequest();<br />}<br />catch (err1)<br />{<br />alert("Your browser does not support AJAX!");<br />request = false;<br />}<br />}<br />}<br />return request;<br />}</span><br />
This JavaScript function uses the try-catch logic to identify the browser and creates the object.<br />
<br />
"Msxml2.XMLHTTP" and "Microsoft.XMLHTTP" are for Internet Explorer.<br />
"MLHttpRequest()" for Firefox, Opera 8.0+ and Safari<br />
<br />
<br />
Now we can use the created object to access the web server.<br />
<br />
Ajax uses four properties for its working. </div>
<div align="justify">
<br />
<strong>onreadystatechange</strong> : This property holds the function that will execute for a response from webserver for a request. </div>
<div align="justify">
<br />
<strong>readyState</strong>: This property holds the status of the request.<br />
These are the status values<br />
<br />
<em>0 - The request is not initialized<br />1 - The request has been set up<br />2 - The request has been sent<br />3 - The request is in process<br />4 - The request is complete</em><br />
<strong>responseText</strong>: This property will contain the text that coming from the web server.<br />
<br />
<strong>responseXML</strong>: This property retrieves the response body from server as an XML Document Object Model (DOM) object. </div>
<div align="justify">
<em>But responseXML was introduced in Internet Explorer 7.</em><br />
<br />
The following function sends and receives data.<br />
<br />
<span style="color: #990000;">function GetInfo()<br />{<br />var xmlHttp;<br />var url;<br />xmlHttp = createXHR();<br />xmlHttp.onreadystatechange=function()<br />{<br />if(xmlHttp.readyState==4)<br />{<br />document.all.tdForRender.innerHTML=xmlHttp.responseText;<br />}<br />}<br />if(document.myForm.query.value==1)<br />{<br />url = "http://abendas.googlepages.com/getcode1.htm";<br />}else if(document.myForm.query.value==2)<br />{<br />url = "http://abendas.googlepages.com/getcode2.htm";<br />}else if(document.myForm.query.value==3)<br />{<br />url = "http://abendas.googlepages.com/getcode3.htm";<br />}<br />else<br />{<br />document.all.tdForRender.innerHTML="Please enter 1,2 or 3"<br />return false;<br />}<br />xmlHttp.open("GET",url,true);<br />xmlHttp.send(null);<br />return true;<br />}<br /></span>Some details about this code</div>
<div align="justify">
<br />
<em><span style="color: #660000;">xmlHttp = createXHR();</span></em><br />
This will call the function to create the object.<br />
<br />
<span style="color: #660000;"><em>xmlHttp.onreadystatechange=function()<br />{</em></span><em><span style="color: #660000;"><br />if(xmlHttp.readyState==4)<br />{<br />document.all.tdForRender.innerHTML=xmlHttp.responseText;<br />}<br />}</span></em><br />
This inner function will execute for a response from server after the request.<br />
<br />
<em><span style="color: #660000;">xmlHttp.readyState==4</span></em><br />
We used this code to limit this only for complete status and xmlHttp.responseText contains the response as string.<br />
<br />
<em><span style="color: #660000;">xmlHttp.open("GET",url,true);</span></em><br />
This code sends the request to the web server. The open function opens a connection with the server. This has three attributes. First parameter is for the method (GET, POST). By using GET we can send data with the url. The POST will use send() method to send data.<br />
<br />
The second parameter is URL for the file. And the third parameter specifies mode (Asynchronous/Synchronous). This argument will be true if the request is asynchronous and false if it is synchronous. The synchronous mode will suspend all activities till a response is received. So I think we should use asynchronous mode for Ajax applications.<br />
<br />
<em><span style="color: #660000;">xmlHttp.send(null);</span></em><br />
This will send the data in parameter to the server. We can use null if there is no data. And this send() is required only if we are using POST method.<br />
<br />
Follows a simple html code.<br />
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<br />
<span style="color: #cc9933;"><form name="myForm"><br /><script><br />function createXHR()<br />{<br />var request = false;<br />try {<br />request = new ActiveXObject("Msxml2.XMLHTTP");<br />}<br />catch (err2) {<br />try {<br />request = new ActiveXObject("Microsoft.XMLHTTP");<br />}<br />catch (err3) {<br />try {<br />request = new XMLHttpRequest();<br />}<br />catch (err1)<br />{<br />alert("Your browser does not support AJAX!");<br />request = false;<br />}<br />}<br />}<br />return request;<br />}<br />function test()<br />{<br />var xmlHttp;<br />var url;<br />xmlHttp = createXHR();<br />xmlHttp.onreadystatechange=function()<br />{<br />if(xmlHttp.readyState==4)<br />{<br />document.all.tdForRender.innerHTML=xmlHttp.responseText;<br />}<br />}<br />if(document.myForm.query.value==1)<br />{<br />url = "http://abendas.googlepages.com/getcode1.htm";<br />}else if(document.myForm.query.value==2)<br />{<br />url = "http://abendas.googlepages.com/getcode2.htm";<br />}else if(document.myForm.query.value==3)<br />{<br />url = "http://abendas.googlepages.com/getcode3.htm";<br />}<br />else<br />{<br />document.all.tdForRender.innerHTML="Please enter 1,2 or 3"<br />return false;<br />}<br />xmlHttp.open("GET",url,true);<br />xmlHttp.send(null);<br />return true;<br />}<br /></script><br /><br /><table border=1><br /><tr><br /><td>Please enter 1,2 or 3<br /><input type="text" onkeypress="clearr();" onkeyup="test();" name="query" size=1 maxlength=1/><br /></td><br /></tr><br /><tr><br /><td id="tdForRender"><br />You can see image here<br /></td><br /></tr><br /></table><br /></form></span></div>
</div>
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com0tag:blogger.com,1999:blog-3909921129970183274.post-42434481968676937832007-07-03T21:42:00.000-07:002013-05-12T22:52:04.449-07:00Exception Handling In .Net - Power Point PresentationHi<br /><br />
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
Please see the Power point presentation here:
<a href="http://abendas.googlepages.com/exception.pps">Click Here for the Presentation</a>.
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com2tag:blogger.com,1999:blog-3909921129970183274.post-50706466172561083272007-05-22T03:56:00.000-07:002013-05-12T22:53:48.873-07:00VB.NET - CType & DirectCast<div dir="ltr" style="text-align: left;" trbidi="on">
I was just wondering why .Net provides two type conversion functionalities for us even though both are casting to targeted type. But now I could understand that they are different.<br />
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<br />
<ol>
<li><span style="font-size: 130%;"><strong>CType</strong></span><span style="font-size: 85%;">CType is more flexible than DirectCast. Because CType can convert one type to another. For example Integer to String, String to Integer, Object to Integer etc... But there should be an implicit conversion available. For example,<br /><br />Dim a As String = "2"<br />Dim b As Integer<br />b=a<br /><br />This will work if the Option Strict is OFF. Because implicit casting functionality for converting string to integer is available in .Net. That's why we can use CType to cast from string to integer .<br /><br />Example:<br /><br />Dim t As String = "5"<br />Dim s As Integer = CType(t, Integer)<br /><br />Now I would like to tell working of CType. CType will use vb run time routines for this. So this happens at run time. For instance i have to convert an integer to string. .Net will create a reference type variable for string. Then it will copy that integer to the new instance of string. Then it will return that string.<br />Here .Net uses run time resources. The integer is a value type. So Boxing is needed for converting to reference type(String). This will hit efficiency.</span></li>
<li><span style="font-size: 85%;"><strong><span style="font-size: 130%;">DirectCast</span></strong>Example:<br /><br /><br />Dim t As String = "5"<br />Dim w As Integer = DirectCast(t, Integer) This will not work<br /><br />But,<br /><br /><br />Dim t As String = "5"<br />Dim w As String = DirectCast(t, String)<br /><br />This will work. That means the type of source variable should be same as casting type at run time.<br />One more example:<br /><br /><br />Dim t As Object<br />t = 5<br />Dim w As Integer = DirectCast(t, Integer) This will work. But the following will not work. It will throw System.InvalidCastException<br /><br />Dim t As Object<br />t = "5"<br />Dim w As Integer = DirectCast(t, Integer)<br /><br />So we should know the type of the object at coding time.<br /><br />DirectCast is faster than CType, because this is not using runtime VB helper functions. And there is no boxing, because DirectCast accepts only reference types as operands.</span></li>
<li><span style="font-size: 85%;"><strong><span style="font-size: 130%;">Is DirectCast more efficient than CType?</span></strong>Yes.<br /><br />---- DirectCast is not using run time helper functions for conversion.<br />---- No boxing in DirectCast<br />---- So DirectCast is two times faster than CType.<br /><br />But, there is a problem. The programmer need to ensure the run time type of the operand before using the DirectCast. If type may not match .Net will through Invalid cast exception. This is a big problem.</span><span style="font-size: 130%;"></span></li>
</ol>
</div>
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com164tag:blogger.com,1999:blog-3909921129970183274.post-84127321721104316672007-05-04T01:28:00.000-07:002013-05-12T22:54:41.556-07:00How Do We Speed Up Our VB.Net Web Applications<ol><li><strong>Use Return statement to return value from functions<br /></strong>The compiler can produce better code in some cases if you use the new Return statement to return a value from a function, instead of assigning the value to the variable named after the function itself (as you did in VB6).</li><li><strong>When comparing strings in a case-insensitive way, try using String.CompareOrdinal instead of the String.Compare method or the = and <> operators</strong>.<br />The Compare method compares strings in a local-aware fashion, so it has to convert the Unicode code of each character into a numeric value that reflects its position in the current culture's alphabet. For example, the Compare method considers the "b" lowercase character to come immediately after the "A" uppercase char and before the "B" uppercase char, even though the "A" and "B" characters are contiguous in the Unicode character set. This conversion activity takes time and consume CPU cycles, so you'll find that VB.NET is less efficient than VB6 at comparing strings. Using the = operator and other comparison operators doesn't help at all, because they map to the Compare method behind the scenes, so these operators suffer from the same performance loss.<br /><br />If you are only interested in checking whether two strings contain the same characters (in a case-sensitive comparison), you can speed up your code by using the CompareOrdinal shared method. This method is 3-4 times faster than the Compare method (or the = operator) because it just scans the two strings and compare the Unicode numeric code of each character.</li><li><strong>StringBuilder is faster than & and +</strong><br />Try this<br /><br />dim Var1<br />Var1= "This "<br />Var1= Var1& "is old "<br />Var1= Var1& "string "<br />Var1= Var1& "concatenation."<br /><br /><br />four variables are actually created. One on each line, and then memory is reallocated for the overlying variable which is created. Poor memory management.<br /><br /><br />If you perform your string concatenation in the same way:<br /><br />Dim someString As New String()<br />someString &= "This "<br />someString &= "is old "<br />someString &= "string "<br />someString &= "concatenation."<br /><br /><br />you still suffer the same performance degradation.<br /><br />However, we have been provided with a new class in .NET called the stringBuilder. And it dynamically allocates the memory block to the same object (the stringBuilder, itself, not the string)... expanding it on each concat so that you gain better performance. It resides in the system.text namespace and here's how you use it:<br /><br />Imports System.Text<br /><br />Dim newStringBuilder As New StringBuilder()<br />newStringBuilder.Append("This ")<br />newStringBuilder.Append("is new ")<br />newStringBuilder.Append("string ")<br />newStringBuilder.Append("concatenation.")<br /><br />Dim myString As New String(newStringBuilder.toString())<br /><br /><br />So that they're really two separate objects, and the string builder takes care of memory management while you're building the string, and then you just call the .toString() method of the stringBuilder to output the result to the new string object, thereby only calling the new string() once, and avoiding the pitfalls of its inefficiencies.</li><li><strong>Speed up searches and replace string operations by using regular expressions</strong>. For example, this code displays all the individual words in a sentence:<br />' This code requires the following imports<br />' Imports System.Text.RegularExpressions<br /><br />Dim s As String = "Hi there, how are you?"<br />Dim re As New Regex("\w+")<br />Dim m As Match<br />For Each m In re.Matches(s)<br />Console.WriteLine(m.Value)<br />Next</li><li><strong>Move as much code as possible outside of loops</strong></li><li><strong>Use Loop Unrolling if possible</strong> Loop unrolling can eliminate some compare and jump instructions. (Compare and jump instructions are used to create loops, you don't see them in visual basic, its behind the scenes stuff that you learn in ASM.) It also takes advantage of the ability of modern cpus that can fetch several instructions at a time. In a nutshell you get a good speed boast by unrolling loops. But there is something we need to know about loop unrolling. The largest bottleneck on modern computers is memory. So the designers of CPU's like Intel and AMD addressed this problem by using a cache on their cpus. This is basically a memory location that is accessed much faster by the CPU then standard memory. You want your unrolled loop to fit in that cache, if it doesn't then it could slow down your code. So you may want to experiment with gettickcount when you unroll you're loop. Example Loop:<br />Code:<br />For i = 1 To 100<br />b = somefun(b)<br />Next i<br />unrolled Example:<br />Code:<br />For i = 1 To 100 step 2<br />b = somefun(b)<br />b = somefun(b)<br />Next i</li><li><strong>Avoid dividing if possible</strong>. A divide instruction is one of the most if not the most expensive instruction you can perform on a CPU. It is faster to multiply then divide!<br />Code:<br />B = 19 / 2<br />is slower then<br />Code:<br />b = 19 * 0.5</li><li><strong>In a nested conditional branch such as select case and nested if statements, put the things that are most likely to be true first in the nest, with the least likely things last.</strong></li><li><strong>Reduce common expressions</strong>. Sometimes you have two different variables that use part of the same calculation. Instead of doing the entire calculation for both variables, eliminate the redundant calculation.Example:<br />Code:<br />x = a * b + c<br />y = a * b + d<br />is slower then<br />Code:<br />t = a * b<br />x = t + c<br />y = t + d<br />That is especially true if your using a redundant expensive calculation in a loop.</li><li><strong>Use long or integer for calculations</strong>. A long is a 32 bit number and is more natural on 32 bit processors. Avoid other variables such as double, single, etc</li><li><strong>Use inline functions inside of loops</strong>. Instead of calling a function, stick the code in the loop. This will make you're program larger if you repeat it in enough loops and should only be done in critical places. The reason is due to the over head of calling a function. Before the program calls a function, it has to push some things onto the stack. At the very least it will push the instruction pointer (IE: Return Address). Memory access is slow so we want to avoid that in critical places.</li><li><strong>Avoid using properties in loops</strong>. Properties are accessed a lot slower then variables, so use variables instead:<br />Code:<br />for i = 1 to 50<br />text1.text = text1.text + b(i)<br />next i<br />is slower then<br />Code:<br />for i = 1 to 50<br />strbuffer = strbuffer + b(i)<br />next i<br />text1.text = strbuffer. This is applicable to user defined properties also.</li><li><strong>Load all the data you need from the disk</strong>. Instead of loading one file at a time, load all of them at once. This will avoid future delay for the user.</li><li><strong>Make good use of the timer control</strong>. You can do background processing while waiting on a user. Use this time to prefetch data, calculations that are need, etc. </li><li><strong>Minimize dot notation in your objects </strong>Each dot you use in a object makes visual basic do a call.<br />Code:<br />Myobject.one.two.three<br />is slower then<br />Code:<br />Myobject.one</li><li><strong>Allocate enough memory at once</strong>.
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>When you create a dynamic array and you want to add elements that haven't been allocated yet, make sure you allocate enough for all of them instead of doing it one at a time. If you don't know how many you need, times what you have allocated by 2. Allocating memory is a expensive process</li><li><strong>Avoid built in functions in loops</strong>. If you have a algorithm that is looped that requires the len of your string. Make sure you cache the size of your string in a buffer and not call the function len() with each iteration of the loop:<br />Code:<br />for i = 1 to 100<br />sz = len(string)<br />'Do processing<br />next i<br />instead<br />Code:<br />sz = len(string)<br />for i = 1 to 100<br />'Do Processing with sz<br />next i</li><li><br />Dim x as integer,a as integer<br />x=listbox.count-1<br />for a= 0 to x<br />next a<br />This code id faster than<br /><br />Dim a as integer<br />for a= 0 to listbox.count-1<br />next a<br />because the value would have to be calculated for each iteration of the loop in the second instance, which takes time.</li><li><strong>Reduce number of database access</strong></li><li><strong>Do not rely on exceptions in your code</strong>. Since exceptions cause performance to suffer significantly, you should never use them as a way to control normal program flow. If it is possible to detect in code a condition that would cause an exception, do so. Do not catch the exception itself before you handle that condition. Common scenarios include checking for null, assigning a value to a <a href="http://msdn2.microsoft.com/en-us/library/system.string(VS.71).aspx">String</a> that will be parsed into a numeric value, or checking for specific values before applying math operations.</li><li><strong>Use the common language runtime's garbage collector and automatic memory management appropriately</strong>. Be careful about allocating too much memory per request because the garbage collector will have to do more work more often. Also, do not have unnecessary pointers to objects, since they will keep the objects alive, and try to avoid having objects with Finalize methods, since they will entail more work at a later time. In particular, never free resources in a call to Finalize, since the resource could consume memory until the garbage collector runs it. This last problem often ruins performance in Web server environments, since it can be easy to exhaust the availability of a given resource while waiting for Finalize to run.</li><li>Use the <strong>HttpServerUtility.Transfer</strong> method to redirect between pages in the same application. Using this method in a page, with Server.Transfer syntax, avoids unnecessary client-side redirection.</li><li><strong>Use SQL Server stored procedures for data access</strong>.
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div> Of all the data access methods provided by the .NET Framework, SQL Server–based data access is the recommended choice for building high-performance, scalable Web applications. When using the managed SQL Server provider, you can get an additional performance boost by using compiled stored procedures instead of ad hoc queries. </li><li><strong>To navigate to a URL without posting the form, use a HyperLink control; to post the form and then navigate, use a LinkButton</strong>। To the Web page visitor, a HyperLink control and a LinkButton control look identical. However, there is a significant difference in functionality.The HyperLink control immediately navigates to the target URL when the user clicks on the control. The form is not posted to the server.The LinkButton control first posts the form to the server, then navigates to the URL. If you need to do any server-side processing before going to the target URL, use a LinkButton. On the other hand, if there is no server-side processing necessary, don't waste a round trip and use the HyperLink control.</li><li><strong>Keep Option Strict and Option Explicit on</strong> By keeping Option Strict and Option Explicit On there is a performance advantage. Option Explicit On forces explicit declaration of variable. If there is no explicit declaration compiler generates code for boxing. So the value types variables move to heap as reference type. This will hit performance.<br />The Option Strict On forces explicit type casting. The implicit type casting will result late binding. This is very expensive. By keeping option strict on the programmer has to use explicit casting and this will result early binding. But, for backward compatibility VB.NET keeps Option Strict Off as default. Make sure Option Strict and Explicit on before coding.</li><li><strong>Avoid excessive round trips to server by providing client-side scripting</strong> Most of things like input validations can move to client-side from server-side. Most applications typical use of server side is for data storing and retrieving. So move the code that can do in client side. Then we can avoid excessive round trips to server</li><li><strong>Use Page.IsPostback to avoid extra work</strong> Some works like controls initializations, data fetch etc are requires performing only once. Avoid this by using Page.IsPostbak</li><li><strong>Disable Session State when not in use</strong> Not all applications or pages require per-user session state. If it is not required, disable it completely. This is easily accomplished using a page-level directive, such as the following: EnableSessionState="false" in page directive.</li></ol>
<div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0384370072978340";
/* developer only image */
google_ad_slot = "9406738592";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>Ggabenhttp://www.blogger.com/profile/06898040206204713611noreply@blogger.com2