Wednesday, January 30, 2008

Optimizing ASP.NET and HTML pages

A comprehensive checklist will serve you well:

- Turn ViewState off on page and control levels when not needed

- Turn SessionState off:
"Session objects consume valuable resources. By turning off sessions, you can improve the performance and scalability of your ASP Web application. You can turn off session state either for the whole Web site or for specific ASP pages."
http://support.microsoft.com/kb/244465

- Alternatives to server controls include simple rendering, HTML elements, inline Response.Write calls, and raw inline angle brackets (<% %>).
(http://msdn2.microsoft.com/en-us/library/ms998549.aspx)

- Especially if not compressing html:
Remove or reduce white space. Removing white spaces can dramatically reduce the size of your pages. Less white space did have about a 5-10K impact on move.com home page when viewed on the browser File-Properties.

-Avoid long control names; especially ones that are repeated in a DataGrid or Repeater control. Control names are used to generate unique HTML ID names. A 10-character control name can easily turn into 30 to 40 characters when it is used inside nested controls that are repeated.

- Use Output caching for user controls , pages, etc. (%@OutputCache directive
)

- Use static properties instead of the Application object to store application state.
(http://msdn2.microsoft.com/en-us/library/ms998549.aspx)


- Use client side validation to avoid unnecessary server hits

-Avoid Creating Deep Hierarchies of Controls (see http://msdn2.microsoft.com/en-us/library/ms998549.aspx#scalenetchapt06_topic11)


Checklist: ASP.NET Performance:
http://msdn2.microsoft.com/en-us/library/ms998596.aspx

Thursday, January 3, 2008

flushing DNS in Windows and MAC OS

Windows:

ipconfig /flushdns


MAC (before Leopard):
sudo lookupd -flushcache

MAC - Leopard:
dscacheutil -flushcache

Thursday, August 2, 2007

Efficient .ASPX pages

A comprehensive checklist would be great. Slowing tickets could be assigned to violators and we could better arrive and agree on guidelines; otherwise, what is known may still be ignored or forgotten.

So its worth mentioning the following (and more):

- Turn ViewState off on page and control levels when not needed
- Turn SessionState off:
"Session objects consume valuable resources. By turning off sessions, you can improve the performance and scalability of your ASP Web application. You can turn off session state either for the whole Web site or for specific ASP pages."

http://support.microsoft.com/kb/244465

- Alternatives to server controls include simple rendering, HTML elements, inline Response.Write calls, and raw inline angle brackets (<% %>).

(http://msdn2.microsoft.com/en-us/library/ms998549.aspx)

- Especially if not compressing html:
Remove or reduce white space. Removing white spaces can dramatically reduce the size of your pages. Less white space did have about a 5-10K impact on move.com home page when viewed on the browser File-Properties.


-Avoid long control names; especially ones that are repeated in a DataGrid or Repeater control. Control names are used to generate unique HTML ID names. A 10-character control name can easily turn into 30 to 40 characters when it is used inside nested controls that are repeated.

- Use Output caching for user controls , pages, etc. (%@OutputCache directive
)


- Use static properties instead of the Application object to store application state.
(http://msdn2.microsoft.com/en-us/library/ms998549.aspx)

- Consider html size and preformance differences such as:
a label with onclick vs an href onclick
a Literal vs a label's final html



-Use Page.IsPostBack to Minimize Redundant Processing
- Use client side validation to avoid unecessary server hits

-Avoid Creating Deep Hierarchies of Controls (see http://msdn2.microsoft.com/en-us/library/ms998549.aspx#scalenetchapt06_topic11)




http://msdn2.microsoft.com/en-us/library/ms998596.aspx

Friday, May 4, 2007

Reading a .csv or a comma-delimited .txt file using SQL

Sample code for Reading a .csv or a comma-delimited .txt file using SQL:

Below:
1) StoragePath is the absolute path to the .csv file.
2) Substitute MyFileName.csv with your file name.

using System.Data.Odbc;
public void ReadData()
{
string StoragePath = @"c:\test";
string strSQL = "Select * from MyFileName.csv";
OdbcConnection conn = new OdbcConnection(
@"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ="+StoragePath);


conn.Open();

OdbcDataAdapter da = new OdbcDataAdapter(strSQL, conn);

DataSet ds = new DataSet();

da.Fill(ds);

conn.Close();
}

Sunday, April 29, 2007

Class does not support automation

Javascript: "Class does not support automation". Occurs when opening a popup.


Solution:

http://www.anetforums.com/posts.aspx?ThreadIndex=8917

regsvr32 Shdocvw.dll
regsvr32 Shell32.dll
regsvr32 Oleaut32.dll
regsvr32 Actxprxy.dll
regsvr32 Mshtml.dll
regsvr32 Urlmon.dll

Thursday, November 9, 2006

Calling a Windows or DOS Process from a Web Application

Your favorite program (graphics package, spell checker, translator, data converter) is written in Windows or DOS and you like to utilize it in your new web application. Suppose you like to generate your favorite pie chart (in real-time) using a DOS application and display the resulting pie image on your web page. When the Web user presses the submit button you will generate a new chart and display it to the user. This could be done seamlessly by invoking your DOS application using the System.Diagnostics.Process.Start() method or the more versatile System.Diagnostics.ProcessStartInfo class.

Lets start with the basic System.Diagnostics.Process.Start() method
It is simply a method call with conventional DOS space-seperated parametrs. For example in C#:

System.Diagnostics.Process.Start("MyImageProgram.bat", @"MyFile -g -r MyLastParam");

The first parameter is the program you want to run and the second parameter is a space-seperated list of parameter(s) to pass to the program.
Process.Start() waits forever for the process to execute. This could make your web site non-responsive.
System.Diagnostics.ProcessStartInfo gives you much more control to accomplish the same thing. For example, you could control the maximum amount of time to wait for the process completion.
Lets look at an example:


using System.Diagnostics;
using System.IO;

public void Main()
{
SyncCall(@"C:\MyWebSites\Images\MyImageProgram.bat", @"MyFile -g -r MyLAstParam");
}

private void SyncCall(string strProgramName, string syncParam)
{


System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(strProgramName);

// store your parameters
psi.Arguments = syncParam;< /FONT >

psi.UseShellExecute = false;< /FONT > // Specify for proper execution

System.Diagnostics.Process listFiles;
listFiles = System.Diagnostics.Process.Start(psi);< /FONT >

// optional for debugging. Grab the program console output
//System.IO.StreamReader myOutput = listFiles.StandardOutput;

// Wait a Maximum of 5000 milliseconds (5 seconds ) for the program execution.
listFiles.WaitForExit(5000);

// optional for debugging. Grab the program console output
/* string output;
if (listFiles.HasExited)
{
output = myOutput.ReadToEnd();
}
*/

}

Above, you specify the maximum amount to wait with the WaitForExit() method. If your program finishes faster than the amount of time you specified the system will not wait any longer and execution proceeds to the next line

(Also if your program outputs to the console you could grab the text using System.IO.StreamReader. Grabbing the text slows down execution. So it is only recommended for debugging.)

Above, after the image file is generated in real-time you could refer to it using an tag or server side tag.



Copyright @ Isaac Levy, Los Angeles, CA

Finding duplicates in a table using SQL

In Transact SQL duplicate rows for a table mytable based on column mycolumn may be found as follows:

SELECT myfield, COUNT(*)
FROM mytable
GROUP BY myfield
HAVING COUNT(*) > 1;