Monday, February 28, 2011

How to Build an RSS Feed with ASP.NET

http://net.tutsplus.com/tutorials/asp-net/how-to-build-an-rss-feed-with-asp-net/

PDF viewer, How to display PDF or MS Office documents in web page without installed client software

How to display PDF or MS Office documents in web page without installed client software?
Google Docs viewer
Example code:
<html><body>
<iframe src="http://docs.google.com/viewer?url=per.lacity.org%2Fexams%2Fchromeissue.pdf&embedded=true" width="600" height="780" style="border: none;"></iframe>
</body></html>

Sunday, February 27, 2011

Node.js, Javascript on server side

An interesting open source project:


An example of a web server written in Node which responds with "Hello World" for every request.
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');



http://nodejs.org/

Saturday, February 26, 2011

How to use Entity Framework for MySQL?

Install Connector/Net.



Connector/Net is a fully-managed ADO.NET driver for MySQL.
http://www.mysql.com/downloads/connector/net

Thursday, February 24, 2011

Inline tags and method for ASP.NET Globalization and Localization

Inline tags and method for ASP.NET Globalization and Localization
http://msdn.microsoft.com/en-us/library/ms228093(v=vs.80).aspx

Implicit localization: (Local resource Resx file)
<asp:Button ID="Button1" runat="server" Text="DefaultText"
    meta:resourcekey="Button1" />


Explicit localization: (Global resource file)
<asp:Button ID="Button1" runat="server"
    Text="<%$ Resources:WebResources, Button1Caption %>" />


By method:
GetLocalResourceObject
http://msdn.microsoft.com/en-us/library/ms149952.aspx

ASP.Net WebForms next version is coming

Timeline: in next 10-12 months
New features: Model binding, Entity Framework Code First; Jquery validation etc.

Scott chats with Damian Edwards about new features coming in ASP.NET WebForms, new techniques, controls, model binding, HTML 5 and more.


Wednesday, February 23, 2011

Tuesday, February 22, 2011

A very light-weight Database Access Layer, 400 lines

A very light-weight Database Access Layer,  400 lines

Datagrid example by JQuery template in ASP.NET MVC

Datagrid example by JQuery template in ASP.NET MVC

How to filter out space in textbox by JQuery?

How to filter out space in textbox by JQuery?
    $("#<%=TextBox.ClientID %>").keyup(function () {
        var trimspace = $("#<%=TextBox.ClientID %>").val().trim();
        $("#<%=TextBox.ClientID %>").val(trimspace);
    });

Sunday, February 20, 2011

How to deal with exception: "A potentially dangerous Request.Form value was detected from the client" in ASP.NET Webform

Cause: the content user posts in the textbox includes bracket: < >. "Request validation detects potentially malicious client input and throws this exception to abort processing of the request"

You can turn off this validation by:

  <location path="pagename.aspx">
    <system.web>
      <httpRuntime requestValidationMode="2.0" />
      <pages validateRequest="false" />
    </system.web>
  </location>

Reference:
http://msdn.microsoft.com/en-us/library/system.web.httprequestvalidationexception.aspx

Saturday, February 19, 2011

How to test your email function without SMTP server?

How to test your email function without SMTP server?
Add following setting into web,config. All of email will be sent to the fold you assigned.

<system.net>
    <mailSettings>
        <smtp deliveryMethod="SpecifiedPickupDirectory">
            <specifiedPickupDirectory pickupDirectoryLocation="c:\emailtest\" />
        </smtp>
    </mailSettings>
</system.net>

20 Useful jQuery Plugins Every Developer Should Know About

http://www.topdesignmag.com/20-useful-jquery-plugins-every-developer-should-know-about/

Friday, February 18, 2011

How to migrate from Blogger to BlogEngine.Net

How to migrate from Blogger to BlogEngine.Net
1. Backup in Blogger to xml file
2. Download blogger2blogml (Two bugs in project, one is Author'S URL, another is comment postid)
http://blogger2blogml.codeplex.com/
3. Run click-once application in BlogEngine.Net to import

Wednesday, February 16, 2011

NuGet, a helper for installing open source libraries in Visual Studio

NuGet, a helper for installing open source libraries in Visual Studio

Installation:
http://www.nuget.org/

Source code:
http://nuget.codeplex.com/

How to integrate Team foundation server in SQL Server Management Studio?

How to integrate  Team foundation server in SQL Server Management Studio?
Install Team Foundation Server MSSCCI Provider
URL for VS2010:

Tuesday, February 15, 2011

How to export data to Excel/CSV file in ASP.NET

How to export data to Excel/CSV file in ASP.NET 
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("content-disposition""attachment;filename=Attendees.csv");
            Response.Charset = "";
            Response.Write("Header\r\nContentetc.");
            Response.End();
        }

How to solve problem "GridView must be placed inside a form tag with runat=server"

This one happens when try to export gridview to an Excel file.
Direct solution: Override VerifyRenderingInServerForm
Add following code to your page

public override void VerifyRenderingInServerForm(Control control)
{
return;
}

Another solution is:
Use a blank page for the exporting

How to convert Generic list into CSV format?

How to convert Generic list into CSV format?
        public static string ListToCSV<T>(List<T> list)
        {
            string output = null;

            foreach (System.Reflection.PropertyInfo info in typeof(T).GetProperties())
            {
                output += ((output==null)?"": ",")+ info.Name;
            }
            output += "\r\n";
            foreach (T t in list)
            {
                string oneline = null;
                foreach (System.Reflection.PropertyInfo info in typeof(T).GetProperties())
                {
                    oneline +=  ((info.GetValue(t, null)==null)?"": info.GetValue(t, null)) +   ",";
                }
                output += oneline + "\r\n";
            }
            return output;
        }

How to convert generic list (List) into datatable

How to convert generic list (List<t>) into datatable
        public static System.Data.DataTable ListToDataTable<T>(List<T> list)
        {
            DataTable table = new DataTable();
 
            foreach (System.Reflection.PropertyInfo info in typeof(T).GetProperties())
            {
                table.Columns.Add(new DataColumn(info.Name, info.PropertyType));
            }
            foreach (T t in list)
            {
                DataRow row = table.NewRow();
                foreach (System.Reflection.PropertyInfo info in typeof(T).GetProperties())
                {
                    row[info.Name] = info.GetValue(t, null);
                }
                table.Rows.Add(row);
            }
            return table;
        }

Monday, February 14, 2011

CDN for JQuery, Microsoft Vs. Google, which one is better

Almost same.

Micosoft:
http://www.asp.net/ajaxlibrary/cdn.ashx

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.js" type="text/javascript"></script>
<script type="text/javascript">  </script>

Google CDN:
http://code.google.com/apis/libraries/devguide.html#jquery

Comparison:
Some of opinions in following article is out of date.
http://stackoverflow.com/questions/1447184/microsoft-cdn-for-jquery-or-google-cdn

A better open source project for zip file, DotNetZip

A better open source project for zip file, DotNetZip, http://dotnetzip.codeplex.com/
Feel better than SharpZipLib
http://www.sharpdevelop.net/OpenSource/SharpZipLib/

Sunday, February 13, 2011

Common performance issues on ASP.NET web sites

http://blogs.msdn.com/b/mcsuksoldev/archive/2011/01/19/common-performance-issues-on-asp-net-web-sites.aspx?cdn_id=2011-01-25-000

Friday, February 11, 2011

What is the best open source asp.net project for ecommerce?

What is the best open source asp.net project for ecommerce?
NopCommerce http://www.nopcommerce.com/
 ASP.NET WebForms
 NET4.0
 Entity Framework
 Moving to MVC
 Lot of features

Common Table Expression makes performance better, and easy to read

Common Table Expression makes performance better, and easy to read

http://msdn.microsoft.com/en-us/library/ms190766.aspx

Thursday, February 10, 2011

Microsoft All-In-One Code Framework, code samples and snippet library

Microsoft All-In-One Code Framework,  code samples and snippet library

http://1code.codeplex.com/

All code samples: http://support.microsoft.com/rss/en/rss.xml  

How to create database schema for Membership in asp.net?

Run:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe


ASP.NET SQL Server Registration Tool (Aspnet_regsql.exe)
http://msdn.microsoft.com/en-us/library/ms229862.aspx
How To: Use Membership in ASP.NET 2.0
http://msdn.microsoft.com/en-us/library/ff648345.aspx
Configuring ASP.NET 2.0 Application Services to use SQL Server 2000 or SQL Server 2005
http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx

How to design URL?

How to design URL? URL as UI
As a user-friendly website, URL design should meet following criteria:
-a domain name that is easy to remember and easy to spell
- short URLs
- easy-to-type URLs
- URLs that visualize the site structure
- URLs that are "hackable" to allow users to move to higher levels of the information architecture by hacking off the end of the URL
- persistent URLs that don't change
(From Jakob Nielsen  http://www.useit.com/alertbox/990321.html )

Wednesday, February 9, 2011

Get a lot of free space if clear up .itrace files in VS 2010

Get  a lot of free space if clear up .itrace files in VS 2010
.itrace file is about 40MB.  Under folder:
C:\ProgramData\Microsoft Visual Studio\10.0\TraceDebuggin

Itrace ifle captures the current state of the debugger at multiple points during a program’s execution.
Reference:

Monday, February 7, 2011

What is maximum upload file size in asp.net, and how to set up, MaxRequestLength

What is maximum upload file size in asp.net, and how to set up,  MaxRequestLength
You can change this setting in web.config:
<system.web>
  <httpRuntime  maxRequestLength="102400" executionTimeout="360"/>
</system.web>

If this attribute set to limited size, can be used to prevent denial of service attacks (DOS).

Default value:  4096 (4 MB).
Maxium size:  1048576 (1 GB) for .NET Framework 1.0/1.1 and 2097151 (2 GB) for .NET Framework 2.0.

Reference:
http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.maxrequestlength.aspx

Sunday, February 6, 2011

Understand Lambda and anonomous function by reading code

Example code for anonomous function
Before
button1.Click += new EventHandler(button1_Click);
void button1_Click (object sender, EventArgs e)
{
textbox1.Text = DateTime.Now.ToShortDateString();
}

After Lambda Code:
button1.Click += (s, e) => { textbox1.Text = DateTime.Now.TosShortDateString(); } ;

Understand LINQ by reading code (1)

Source
1. Add references:
using System.Data.Linq;
using System.Data.Linq.Mapping;

2. Connect to database:
DataContext db = new DataContext

3. Mapping table and class
[Table(Name = "Customers")]
public class Customer
{
}

4. Query:
Table<Customer> Customers = db.GetTable<Customer>();
IQueryable<Customer> custQuery =
from cust in Customers
where cust.City == "London"
select cust;
foreach (Customer cust in custQuery)
{
Console.WriteLine("ID={0}, City={1}", cust.CustomerID,
cust.City);
}

Saturday, February 5, 2011

How to publish a asp.net website in Windows 7

1. install the "IIS Metabase and IIS6 Configuration Compatibility" feature under Internet Information Services-Web Management Tools-IIS 6
2. FrontPage 2002 Server Extensions for IIS 7.0
http://www.iis.net/community/default.aspx?tabid=34&g=6&i=1630
3. Compile code to AnyCPU in Build option

Friday, February 4, 2011

How to remove one element from array in Javascript?

How to remove one element from array in Javascript?
myArray = ['a', 'b', 'c', 'd'];
myArray.splice (
0,1);
[
'b', 'c', 'd'];
Reference

Wednesday, February 2, 2011

Enable content expiration in IIS to optimize ASP.Net website

Enable content expiration in IIS to optimize ASP.Net website
Default setting is Off.

To set the expiration of Web site content

1.In IIS Manager, double-click the local computer; right-click the Web Sites folder, an individual Web site folder, a virtual directory, or a file; and then click Properties.
2.Click the HTTP Headers tab.
3.Select the Enable content expiration check box.
4.Click Expire immediately, Expire after, or Expire on, and type the appropriate expiration information in the corresponding boxes.




Tuesday, February 1, 2011

Entity framework does not support HierarchyID, and workaround

Entity framework does not support HierarchyID, and workaround
Answer from MS:
Posted by Microsoft on 5/12/2009 at 6:45 PM
This is on our list of features to be supported in future releases, unfortunately at this point we do not have a timeframe for when it will be added. Thank you


Workaround:
Import function from Store procedure in EF

jQuery 1.5 Released

Adjacent Traversal Performance
In this release we’ve also been able to improve the performance of some commonly-used traversal methods: .children(), .prev(), and .next().

Microsoft CDN: http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.min.js