Sunday, October 15, 2006
Resizing & Scaling images in .NET
e 4GuysFromRolla Scott Mitchell Displaying a List of Scaled Images
e 4GuysFromRolla Scott Mitchell True Image Resizing, Part 1
e 4GuysFromRolla Scott Mitchell True Image Resizing, Part 2 : About thumbnail
e SmartThumbnail.Net Component
Posted by
Dillone Hailei Wang 王海磊
at
10/15/2006 11:12:00 AM
Manipulating Image with .NET
e Rob's Image Shrinker : Scaling image file.
e Flickr-ing about with .NET
e Generating ASP.NET Images on the Fly
Posted by
Dillone Hailei Wang 王海磊
at
10/15/2006 10:39:00 AM
Authentication in an ASP.NET application
@ The Membership service convered all the details of authentication for an applications, whereas the Role Management service covers authorization.
@ To allow forms authentication in your web application, the 1st step is to turn on this Membership service in the web.config file.
Posted by
Dillone Hailei Wang 王海磊
at
10/15/2006 01:48:00 AM
Labels: ASP.NET, Authentication, Membership, Security
How to display HTML/XML tags code in webpage?
Method 1: Use the <xmp>tage to surround the HTML or XML code to be displayed as plain text. For example:
Method 2: Convert the <> to <>.
To display a simple link as code: <a href="http://www.simplelink.com">Here</a>
Would show as : <a href="http://www.simplelink.com">Here</a>
@ Simple Code Encoder SUPER great tool, i.e.
<system.web>
<urlMappings enabled="true">
<add url="~/About.aspx" mappedUrl="~/Site_Common/About.aspx"/>
<add url="~/Legal.aspx" mappedUrl="~/Site_common/Legal.aspx"/>
</urlMappings>
</system.web>
Posted by
Dillone Hailei Wang 王海磊
at
10/15/2006 12:12:00 AM
Labels: Hack
Saturday, October 14, 2006
URL Mapping in ASP.NET 2.0
When URL mapping is useful?
URL mapping comes handy in number of situations:
- You want to hide a big URL from the end user and present an easy to remember shorter URL
- You want to pass query string parameters to a page but do not want them to be displayed to the user
- You have changed web form names after the application is deployed
How this works?
In ASP.NET 2.0 there is a configuration section called urlMappings that maps one URL to the other. The following markup shows how this section can be used:
The enabled attribute of
The
The url attribute of
The mappedUrl attribute species the URL that is actually served in place of the URL specified by url attribute.
You can specify as many URL mappings as you wish using multiple
Posted by
Dillone Hailei Wang 王海磊
at
10/14/2006 11:47:00 PM
About Microsoft .NET Framework 3.0
The Microsoft .NET Framework version 3.0 (formerly known as WinFX) is the new managed-code programming model for Windows. It combines the power of .NET Framework 2.0 with new technologies for building applications that have a visually compelling user experience, seamless communication across technology boundaries, and support for a wide range of business processes.
All of the classes that represent the new components (WPF, WF, WCF, and CardSpace) are part of the System namespace. The core classes of the .NET platform, such as the common language runtime (CLR) and base class libraries (BCL) remain as they are in .NET Framework 2.0.
How .NET Framework 3.0 Relates to .NET Framework 2.0 and Earlier
The .NET Framework 3.0 adds new technologies to the .NET Framework 2.0, which makes the .NET Framework 3.0 a superset of the .NET Framework 2.0. You can think of .NET Framework 3.0 as an "additive" release to the .NET Framework 2.0, as contrasted with a generational release where software is revised across the board. (For example, the .NET Framework 2.0 was a generational release over the .NET Framework 1.0.)
Because .NET Framework 3.0 is an additive release and uses the core run-time components from .NET Framework 2.0, it is completely backward compatible with the earlier version. Your existing .NET Framework 2.0 based-applications will continue to run without any modifications and you can safely continue your investments using the technologies that shipped with .NET Framework 2.0.
Installing the .NET Framework 3.0
The .NET Framework 3.0 is installed by default on Microsoft Windows Vista. On Microsoft Windows Server code-named "Longhorn", you can install the .NET Framework as a Windows Feature using Roles Management tools. On Windows XP and Windows Server 2003, installing .NET Framework 3.0 also adds any .NET Framework 2.0 components that are not already installed.
If .NET Framework 2.0 is already installed, the .NET Framework 3.0 installer adds only the files for Windows Presentation Foundation (WPF), Windows Workflow Foundation (WF), Windows Communication Foundation (WCF), and Windows CardSpace.
Components shared with .NET Framework 2.0 are installed in the following location:%windir%\Microsoft.NET\Framework\V2.0.50727
Components that are new to .NET Framework 3.0 are installed in the following location: %windir%\Microsoft.NET\Framework\V3.0
All components of the .NET Framework 3.0 reference assemblies are installed in the following location: %programfiles%\Reference Assemblies\Microsoft\Framework\v3.0
Uninstalling .NET Framework 3.0 will not remove the components shared with .NET Framework 2.0. To remove those components, you must first uninstall .NET Framework 3.0 and then separately uninstall .NET Framework 2.0.
Version Numbers for .NET Framework Assemblies
The .NET Framework 3.0 shares many components with .NET Framework 2.0, and the common language runtime (CLR) and base class libraries are the same as those in .NET Framework 2.0. Therefore, these shared components stay at version 2.0.
The version number 3.0 applies to all runtime and reference assemblies for Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), Windows Workflow Foundation (WF), and Windows CardSpace.
^ 基本上对我没有什么影响,因为我目前只关心Internet Application。所以,用好ASP.NET 2.0就是首要的。集中力量,先不去管.NET Framework 3.0的其他部分。
Posted by
Dillone Hailei Wang 王海磊
at
10/14/2006 05:40:00 PM
Labels: .NET Framework
Friday, October 13, 2006
SQL Subqueries
INSERT INTO TableA (PosID, PosValue, DataDate) SELECT PosID, PosValue, DataDate FROM TableB WHERE DataDate = '2006-10-6' AND PosID = 'TAEE1'
^ 把Values (A,B,C)部分替换成一个SELECT A,B,C语句便可。
UPDATE TableA SET PosValue = (SELECT PosValue FROM TableB WHERE
DataDate = '2006-10-6' AND PosID = 'TAEE1' ) WHERE PosID = 'TAEE1' AND DataDate = '2006-10-6'
^
SELECT OUID, (SELECT ID, OUName FROM Accounts_OU WHERE ID = A.OUID ORDER BY ID) AS OUName FROM BizMgtStationOrder A WHERE PipeLineID = " & XXX & " ORDER BY OUID"
d Subquery Fundamentals
A subquery is a SELECT query that returns a single value and is nested inside a SELECT, INSERT, UPDATE, or DELETE statement, or inside another subquery. A subquery can be used anywhere an expression is allowed. In this example a subquery is used as a column expression named MaxUnitPrice in a SELECT statement.
SELECT Ord.OrderID, Ord.OrderDate,
(SELECT MAX(OrdDet.UnitPrice)
FROM Northwind.dbo.[Order Details] AS OrdDet
WHERE Ord.OrderID = OrdDet.OrderID) AS MaxUnitPrice
FROM Northwind.dbo.Orders AS Ord
A subquery is also called an inner query or inner select, while the statement containing a subquery is also called an outer query or outer select.
Many Transact-SQL statements that include subqueries can be alternatively formulated as joins. Other questions can be posed only with subqueries. In Transact-SQL, there is usually no performance difference between a statement that includes a subquery and a semantically equivalent version that does not. However, in some cases where existence must be checked, a join yields better performance. Otherwise, the nested query must be processed for each result of the outer query to ensure elimination of duplicates. In such cases, a join approach would yield better results. This is an example showing both a subquery SELECT and a join SELECT that return the same result set:
/* SELECT statement built using a subquery. */
SELECT ProductName
FROM Northwind.dbo.Products
WHERE UnitPrice =
(SELECT UnitPrice
FROM Northwind.dbo.Products
WHERE ProductName = 'Sir Rodney''s Scones')
/* SELECT statement built using a join that returns
the same result set. */
SELECT Prd1.ProductName
FROM Northwind.dbo.Products AS Prd1
JOIN Northwind.dbo.Products AS Prd2
ON (Prd1.UnitPrice = Prd2.UnitPrice)
WHERE Prd2.ProductName = 'Sir Rodney''s Scones'
A subquery nested in the outer SELECT statement has the following components:
A regular SELECT query including the regular select list components.
A regular FROM clause including one or more table or view names .
An optional WHERE clause.
An optional GROUP BY clause.
An optional HAVING clause.
The SELECT query of a subquery is always enclosed in parentheses. It cannot include a COMPUTE or FOR BROWSE clause, and may only include an ORDER BY clause when a TOP clause is also specified.
A subquery can be nested inside the WHERE or HAVING clause of an outer SELECT, INSERT, UPDATE, or DELETE statement, or inside another subquery. Up to 32 levels of nesting is possible, although the limit varies based on available memory and the complexity of other expressions in the query. Individual queries may not support nesting up to 32 levels. A subquery can appear anywhere an expression can be used, if it returns a single value.
If a table appears only in a subquery and not in the outer query, then columns from that table cannot be included in the output (the select list of the outer query).
Statements that include a subquery usually take one of these formats:
WHERE expression [NOT] IN (subquery)
WHERE expression comparison_operator [ANY ALL] (subquery)
WHERE [NOT] EXISTS (subquery)
In some Transact-SQL statements, the subquery can be evaluated as if it were an independent query. Conceptually, the subquery results are substituted into the outer query (although this is not necessarily how Microsoft® SQL Server™ actually processes Transact-SQL statements with subqueries).
There are three basic types of subqueries, those that:
Operate on lists, introduced with IN or those that a comparison operator modified by ANY or ALL.
Are introduced with an unmodified comparison operator and must return a single value.
Are existence tests introduced with EXISTS.
Posted by
Dillone Hailei Wang 王海磊
at
10/13/2006 05:47:00 PM
Wednesday, October 11, 2006
Label and Label Cloud / Tag and Tag Cloud
Posted by
Dillone Hailei Wang 王海磊
at
10/11/2006 02:31:00 PM
Labels: Hack, Website Feature
Making and sending HTML email
@ The Process of Creating and Sending an E-mail Message: To create and send an e-mail message, follow these steps:
- Create a MailMessage object. MailMessage and other mail-related classes are in the System.Net.Mail namespace.
- If you did not specify the recipients in the MailMessage constructor, add them to the MailMessage object.
- If you need to provide multiple views (such as plain text and HTML), create AlternateView objects and add them to the MailMessage object.
- If necessary, create one or more Attachment objects and add them to the MailMessage object.
- Create an SmtpClient object, and specify the SMTP server.
- If the SMTP server requires clients to authenticate, add credentials to the SmtpClient object.
- Pass your MailMessage object to the SmtpClient.Send method. Alternatively, you can use SmtpClient.SendAsync to send the message asynchronously.
How to create a MailMessage
^ 一定要首先创建空的MailMessage,然后把MailMessage.To、MailMessage.From、MailMessage.Subject、MailMessage.Body四个property依次添加到MailMessage中。还可以添加MailMessage.Cc和MailMessage.Bcc。
^ 因为每次发送邮件不一定会发给多少个人,所以写程序时不区分发给单人还是多人的情况。把所有得到的收件人地址都放进一个MailAddressCollection中。
@ BCC stands for "blind carbon copy".
@ The problem with BCC is that spam filters frequently block messages that do not have the recipient's email address in the From header, Therefore, if you use BCC, the message will very likely be filtered.
How to create HTML email?
@ To create an HTML email message, supply HTML-tagged content for MailMessage.Body and set MailMessage.IsBodyHtml attribute to True.
Dim OneMailMessage = New MailMessage
String OneMailMessageHtmlBody = "XHTML codes ..."
OneMailMessage.IsBodyHtml = True
OneMailMessage.Body = OneMailMessageHtmlBody
@ Most email clients will ignore the head section, and will ignore any client-side scripts, and will not automatically download images from Web sites.
@ To embed images into an HTML message so that they appear when the user clicks the message (without requiring the user to explicitly choose to download images): first creat an HTML message using AlternateView and then add images using LinkedResource classes.
^ 因为有的邮件客户端或者服务器会阻止图片内容,或者只支持普通文本格式的邮件,或者用户设定只接受文本邮件,所以需要提供alternate view以根据情况显示邮件内容。
e 4guysfromrolla.com Sending Email in ASP.NET 2.0e 4guysfromrolla.com Sending Email in ASP.NET 2.0: HTML-Formatted Emails, Attachments, and Gracefully Handling SMTP Exceptions
e Complete FAQ for the System.Net.Mail namespace found in .NET 2.0
Posted by
Dillone Hailei Wang 王海磊
at
10/11/2006 02:28:00 PM
Labels: ASP.NET, Email, Hack, Website Feature
Globalization: Culture, Region, Date, Number
@ How to detect a user's current culture information?
Using the CurrentCulture property of the executing thread's CurrentThread property. i.e.,
Dim UserCulture As CultureInfo = Thread.CurrentThread.CurrentCulutre
Console.WriteLine("The current culture of this application is : " & UserCulutre.Name)
@ How to set the current culture?
Just specify a different value to the CurrentCulture property of the CurrentThread property of the Thread class. i.e.,
Thread.CurrentThread.CurrentCulutre = New CultureInfo("es-VE")
@ The RegionInfo class provides specific information about a particular country or region.
@ The DateTimeFormatInfo class provides a comprehensive set of methods and properties to handle and respond to the dates of different culutres.
Dim UserCulture As CultureInfo = New CultureInfo("zh-CN")
Dim Days() As String = UserCulture.DateTimeFormat.DayNames
For Each Day As String In Days
Console.WriteLine("Culture : " & UserCulture.Name)
Console.WriteLine("Day Name : " & Day)
Next
Posted by
Dillone Hailei Wang 王海磊
at
10/11/2006 01:38:00 PM
Labels: .NET Framework, Globalization
Shared Method V.S. Instance Method
@ Shared means "shared between all instances of a class", which is also called static.
Posted by
Dillone Hailei Wang 王海磊
at
10/11/2006 01:34:00 PM
Labels: Language
Tuesday, October 10, 2006
Declarative Language V.S. Imperetive Language
@ The ASP.NET markup language (that is, the ASPX language) is increasingly being recognized as a declarative programming language.
@ Declarative programming is quite a different programming model.
@ When you program with an imperative language, you reach a desired goad by providing the specific operations required to reach the goal. (That is, you tell the computer how to reach your goal.)
@ When you program with a declarative language, you specify your goal and a compiler or interpreter uses its predefined algorithms to determine the appropriate operations to reach that goal. (That is, the computer find a way to reach your goal.)
^ 这就像我曾经说过的,我只在乎是否实现了一个function,而不在乎这个function是怎么被实现的。
e The Right Way to do Ajax is Declaratively
e Declarative V.S. Imperative Programming
e Declarative programming
e del.icio.us/tag/declarative
Posted by
Dillone Hailei Wang 王海磊
at
10/10/2006 06:31:00 PM
Labels: ASP.NET, Language, Programming
Manipulating Microsoft Office
Excel How to
Office Wiki
Joe Andreshak (MS) http://blogs.officezealot.com/joe/
Clinick's Clinic http://weblogs.asp.net/andrewclinick/
John Durant (MS) http://blogs.msdn.com/johnrdurant
Mark Harrison (MS) http://blog.markharrison.co.uk/
Laura John (MS) http://blogs.msdn.com/lauraj
Eric Lippert (MS) http://blogs.msdn.com/ericlippert
Andrew May (MS): http://blogs.msdn.com/andrew_may
Chris Kunicki http://blogs.officezealot.com/chris
Charles Maxson http://blogs.officezealot.com/charles
Office Zealot Blogz http://www.officezealot.com/BlogHome.aspx
Frank Rice (MS) http://blogs.msdn.com/frice
Peter's Blog: http://blog.jausovec.net/
Peter Torr: http://weblogs.asp.net/ptorr/
Posted by
Dillone Hailei Wang 王海磊
at
10/10/2006 11:32:00 AM
Labels: Interoperation, Microsoft Office
About VB.NET Procedure / Method
@ A procedure is a block of Visual Basic statements enclosed by a declaration statement (Function, Sub, Operator, Get, Set) and a matching End declaration. All executable statements in Visual Basic must be within some procedure.
@ Types of Procedures
Visual Basic uses several types of procedures:
· Sub Procedures perform actions but do not return a value to the calling code.
· Event-handling procedures are Sub procedures that execute in response to an event raised by user action or by an occurrence in a program.
· Function Procedures return a value to the calling code. They can perform other actions before returning.
· Property Procedures return and assign values of properties on objects or modules.
· Operator Procedures define the behavior of a standard operator when one or both of the operands is a newly-defined class or structure.
· Generic Procedures in Visual Basic define one or more type parameters in addition to their normal parameters, so the calling code can pass specific data types each time it makes a call.
Posted by
Dillone Hailei Wang 王海磊
at
10/10/2006 10:15:00 AM
Labels: .NET Framework, Language, Object Oriented, VB.NET
Reflection到底是个啥东西?
@ Code in the CLR is packaged in an assembly. Even though it is often thought of as a file, an assembly is actually a logical container for different parts of the data the CLR needs to execute code.
@ These parts of data of an assembly include: Assembly metadata, Type metadata, Intermediate Language code, and Resources.
@ Assembly Metadata includes data that defined the assembly, such as the name, version, strong name, and culture information. Assembly metadata is also called manifest.
@ Type Metadata is the information describes what a type looks like, including the namespace, class name, members (methods, properties, constructors, etc.), and parameters.
@ Most of the time, all these parts of an assembly are compiled into a single file.
@ Assemblies are containers for modules, and modules are containers for types.
^ 我啥时候会用的上Reflection呀?
e C-sharp reflection: Save development time throughout the project life-cycle
Posted by
Dillone Hailei Wang 王海磊
at
10/10/2006 10:13:00 AM
Labels: .NET Framework, Programming, Reflection
Web API V.S. Web Services
@ Web APIs are application programming interfaces that can be called over standard Internet protocols.
@ It is helpful to think of a Web API as a series of Web services, each of which has one or more procedures that can be called using the Internet.
@ Web APIs are typically a related collection of Web services.
Posted by
Dillone Hailei Wang 王海磊
at
10/10/2006 10:11:00 AM
Labels: Web API, Web Service
Monday, October 09, 2006
Saturday, October 07, 2006
Page.IsPostBack
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Page.IsPostBack是用来检查目前网页是否为第一次加载,
'当使用者第一次浏览这个网页时page.ispostback 会传回false,不是第一次浏览这个网页时就传回true;
'所以当我们在page_load 事件中就可以使用这个属性来避免做一些重复的动作。
'此处,如果是第一次加载,则要执行下列代码,否则就不执行,所以要保证If true Then
If Not Page.IsPostBack Then
......
End If
End Sub
Posted by
Dillone Hailei Wang 王海磊
at
10/07/2006 04:34:00 PM
The constructor method of VB.NET
A constructor is a method that runs when a new instance of the class is created.
In Visual Basic, the constructor method is always named Sub New:Class Person
Private CreateTime As Date
Sub New()
' Display a diagnostic message.
Console.WriteLine("A new instance of Person is being created.")
' Remember when this instance was created.
CreateTime = Now
' Perform other initialization chores.
…
End Sub
End Class
Posted by
Dillone Hailei Wang 王海磊
at
10/07/2006 11:42:00 AM
Labels: .NET Framework, Language, Object Oriented, VB.NET
Exporting Data to Excel
Original Address: http://www.developer.com/net/asp/article.php/3633891
A common request of users is to be able to download data for use in Microsoft Excel. This is actually fairly easy to accomplish without a lot of extra work.
I do most of my database work with DataTable objects, as I don't need the overhead of a DataSet. I also have a Database wrapper class that is able to easily retrieve data from a SQL Server database. Once I use my function to get my DataTable, I can start exporting the data. For this example, however, I'll use the traditional SqlDataAdapter method to retrieve the data initially.
There are a few tricks to making this work.
First, you have to create an ASPX page with no HTML content in it. The only thing that should be in the ASPX page is the Page directive at the top.
The second trick is to clear the existing content and send down a new content type. For Excel, you use a content type of application/vnd.ms-excel. This tells your Web browser to expect something that can be handled within Excel.
The third trick is to send down the data tab-delimited per column and a newline at the end of each row.
After that, Excel does the rest of the work for you.
Posted by
Dillone Hailei Wang 王海磊
at
10/07/2006 10:46:00 AM
Labels: ASP.NET, Interoperation, Microsoft Office
Tuesday, October 03, 2006
ASP.NET Inline Data-Binding Syntax
@ One-way data binding:
Eval("", "")
第一部分是Item的名称;第二部分是一个Formatter。
@ Two-way data binding:
<%# Bind("Name", "{0:mm dd yyyy}") ) %>
第一部分是Item的名称;第二部分是一个Formatter。
Posted by
Dillone Hailei Wang 王海磊
at
10/03/2006 05:31:00 PM
Labels: ASP.NET, Hack, Server Control
Sunday, October 01, 2006
.NET Framework Application Domain
@ How to create an Application Domain?
@ To create an AppDomain, call static AppDomain.CreateDomain("YourAppDomain") method.
@ To load an assembly in an application domain, call AppDomain.ExecuteAssembly("TheAssemblyName.exe") method.
@ To unload an application domain, call static AppDomain.Unload(YourAppDomainReference) method.
Dim OneAppDomain As AppDomain = AppDomain.CreateDomain("MyFirstDomain")
Console.WriteLine(" Host domain: " + AppDomain.CurrentDomain.FriendlyName)
Console.WriteLine("Child domain: " + OneAppDomain.FriendlyName)
@ Create an application domain anytime you want to launch an assembly.
Posted by
Dillone Hailei Wang 王海磊
at
10/01/2006 11:33:00 AM
Labels: .NET Framework