using System.Xml.Serialization; using System.Text; public class SerializeManager { public static XmlDocument Serialize(Type type, Object source) { MemoryStream stream = null; TextWriter writer = null; XmlDocument document = null; try { stream = new MemoryStream(); writer = new StreamWriter(stream, Encoding.Unicode); XmlSerializer serializer = new XmlSerializer(type); serializer.Serialize(writer, source); int count = (int)stream.Length; byte[] array = new byte[count]; stream.Seek(0, SeekOrigin.Begin); stream.Read(array, 0, count); UnicodeEncoding utf = new UnicodeEncoding(); document = new XmlDocument(); document.LoadXml(utf.GetString(array).Trim()); } catch { throw; } finally { if (stream != null) stream.Close(); if (writer != null) writer.Close(); } return document; } }
Wednesday, July 01, 2009
Generic Serialization Method - Microsoft C#.NET
Generic Clone Method C#.NET
Using reflection, this method copies each property of the source object to target object.
public virtual void Clone(Object source) { if (source == null) throw new ArgumentNullException("Source"); if (source.GetType() != this.GetType()) throw new ArgumentException("Type Mismatch"); foreach (PropertyInfo p in source.GetType().GetProperties()) if (p.CanRead && p.CanWrite) p.SetValue(this, p.GetValue(source, null), null); }
Wednesday, May 06, 2009
CSS Element selectors [pattern matching] - Cascade Style Sheet Syntax (CSS Syntax)
Pattern | Meaning | Described in section |
---|---|---|
* | Matches any element. | Universal selector |
E | Matches any E element (i.e., an element of type E). | Type selectors |
E F | Matches any F element that is a descendant of an E element. | Descendant selectors |
E > F | Matches any F element that is a child of an element E. | Child selectors |
E:first-child | Matches element E when E is the first child of its parent. | The :first-child pseudo-class |
E:link E:visited | Matches element E if E is the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited). | The link pseudo-classes |
E:active E:hover E:focus | Matches E during certain user actions. | The dynamic pseudo-classes |
E:lang(c) | Matches element of type E if it is in (human) language c (the document language specifies how language is determined). | The :lang() pseudo-class |
E + F | Matches any F element immediately preceded by a sibling element E. | Adjacent selectors |
E[foo] | Matches any E element with the "foo" attribute set (whatever the value). | Attribute selectors |
E[foo="warning"] | Matches any E element whose "foo" attribute value is exactly equal to "warning". | Attribute selectors |
E[foo~="warning"] | Matches any E element whose "foo" attribute value is a list of space-separated values, one of which is exactly equal to "warning". | Attribute selectors |
E[lang|="en"] | Matches any E element whose "lang" attribute has a hyphen-separated list of values beginning (from the left) with "en". | Attribute selectors |
DIV.warning | Language specific. (In HTML, the same as DIV[class~="warning"].) | Class selectors |
E#myid | Matches any E element with ID equal to "myid". | ID selectors |
Reference: W3C CSS Guidlines (Section 5: Selectors)
Thursday, April 23, 2009
CLRProfiler (CLR Profiler) waiting for application to start common language runtime - .NET Runtime
Symptom: When you start an application using CLR profiler, it always says [waiting for application to start common language runtime] and wait forever
Resolution
- Most probably you may be using CLR Profiler 1.1 to profile .NET 2.0 Application. Download CLR Profiler 2.0 from the here
If it is VISTA or Windows XP, may be CLR Profiler doesn't have enough permissions to run. Try running CLR Profiler as an Administrator.Right Click on the CLRProfiler.exe -> Run as -> Administrator
Wednesday, April 22, 2009
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding – Microsoft ADO.NET
Symptom: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Resolution:
- SqlConnection: If this happen when tries to connecting to SQL Server, then try increasing the timeout of the connection Connection String: server=Server;database=Database;uid=Uid;pwd=Pwd;timeout=600 (ConnectionTimeout is read-only)
- SqlCommand: More interestingly if you manage to connect successfully and although you set a fat timeout value to your connection command object does not inherit the timeout from its connection. It uses its own timeout value. More logically ConnectionTimeout and CommandTimeout.
command.CommandTimeot = 600 (set to 10 minutes)
Reference: ASP.NET Forums
Tuesday, March 17, 2009
String.Format(“{0:X}”, args[]) Function : C#.Net
Example: String.Format("{0:D}", DateTime.Now) = 17 Mar 2009
Symbol | Type | Representation |
C | Currency: | (123.00) |
D | Decimal | -123 |
E | Scientific | -1.234500E+002 |
F | Fixed point | -123.45 |
G | General (default) | -123 (default = 'G') |
N | Number | -123.00 |
P | Percent | -12,345.00 % |
R | Round-trip | -123.45 |
X | Hexadecimal | FFFFFF85 |
Date Time Formatting | ||
Symbol | Type | Representation |
d | Short date | 07/09/2007 |
D | Long date | Monday, 09 July 2007 |
t | Short time | 13:42 |
T | Long time | 13:42:50 |
f | Full date/short time | Monday, 09 July 2007 13:42 |
F | Full date/long time | Monday, 09 July 2007 13:42:50 |
g | General date/short time | 07/09/2007 13:42 |
G | General date/long time (default) | 07/09/2007 13:42:50 (default = 'G') |
M | Month | July 20 |
R | RFC1123 | Mon, 09 Jul 2007 13:42:50 GMT |
s | Sortable | 2007-07-09T13:42:50 |
u | Universal sortable | 2007-07-09 13:42:50Z (invariant) |
U | Universal full | Monday, 09 July 2007 20:42:50 |
Y | Year | 2007 July |
Standard Enumeration Formatting | ||
G | General (default) | Green (default = 'G') |
F | Flags | Green (flags or integer) |
D | Decimal number | 3 |
X | Hexadecimal | 00000003 |
Reference: String.Format - MSDN
Friday, February 27, 2009
Login Failed The user is not associated with a trusted SQL Server connection: SQL Server 2005
This occurs when you try to login using SQL Server user cardinals without configuring SQL Server to use Windows and SQL Server authentication.
Resolution:
[1] Open SQL Server management studio – [2] Login to SQL server using windows authentication – [3] Right click on SQL Server instance and go to properties – [4] Expand security tab and select 'SQL Server and Windows authentication mode' under 'Server Authentication'
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding - Microsoft SQL Server 2005
Symptom:
SQL Server throws an exception 'Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. (Microsoft SQL Server, Error: -2) when try to connect from a remote computer. Most probable symptom for the error is TCP Port 1433 being blocked by the windows firewall in a computer running windows XP(SP2).
Solution
Scenario 1
Make sure you have enabled remote connections from the SQL Server surface area configuration and allow TCP/IP, Named Pipe protocol or combination as necessary.
- To Enable Remote connections: [1] SQL Server 2005 – [2] Configuration Tools – [3] SQL Server Surface area configuration – [4] Click on 'Surface area configuration for services and connections'.
- Expand [1] Database Engine – [2] Remote Connections – [3] Select Local and remote connections – [4] Select the desired protocol (In this scenario I have used TCP/IP and Named Pipes)
- Restart the SQL Server.
Open TCP Port 1433 – This is the default port that SQL server use for remote connections. By default windows XP firewall deny access of this port:
- Open [1] Control Panel – [2] Windows Firewall – [4] Click on 'Add Port'
- Add: Name = SQL Server (Any meaningful name), Port Number = 1433 (by default, if you have changed the default port you have to make sure you enter the corresponding port number)
Monday, February 09, 2009
DATEDIFF Function - TSQL - Microsoft SQL Server 2000/2005
Ex: DATEDIFF(yyyy, applicant.DateOfBirth, GETDATE()) = 28 [age of applicant in years]
datepart - Abbriviation
year - yy, yyyy
quarter - qq, q
month - mm, m
dayofyear - dy, y
day - dd, d
week - wk, ww
hour - hh
minute - mi, n
second - ss, s
millisecond - ms
microsecond - mcs
nanosecond - ns
datepart - Abbriviation
year - yy, yyyy
quarter - qq, q
month - mm, m
dayofyear - dy, y
day - dd, d
week - wk, ww
hour - hh
minute - mi, n
second - ss, s
millisecond - ms
microsecond - mcs
nanosecond - ns
Subscribe to:
Posts (Atom)
Azure Storage Account Types
Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...
-
Why we need asynchronous tasks? Execute a time consuming operations in parallel to the CLR thread which execute the request If you have ...
-
Demo: I was thinking a way to show images before actually uploading them to server. I would say to preview images using javascript. Obv...