Geeks With Blogs
Sharvan Dhaka blog October 2006 Entries
Perform a Case-IN sensitive Search in .NET Using XPath
The following code shows to how to perform a case-sensitive search in .NET using XPath. and contains is used as like operator in xpath. XML File: <?xml version="1.0" encoding="utf-8"?><US... <USER> <NAME>sharvan</NAM... <PASSWORD>dhaka</P... </USER></USERS>... File:<%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Xml" %><%@ Page Language="C#" Debug="true" %><SCRIPT runat="server">void Page_Load(object ......

Posted On Sunday, October 15, 2006 6:37 PM

Search in Xml File through XPATH
Using xpath you can find elements in a xml file.There is more to XML then just a way of describing data. Over the years, a number of XML-based standards have emerged. Among the most fundamental ones are XSD (XML Schema Definition), XPath Query, XSLT (Extensible Stylesheet Language Transformation), SOAP (Simple Object Access Protocol), and WSDL (Web Services Description Language). All build on top of the XML syntax.The Sample XML Document for the Series of Articles This series of articles assumes ......

Posted On Sunday, October 15, 2006 6:29 PM

XPath Introduction
XPath is a language for finding information in an XML document. XPath is used to navigate through elements and attributes in an XML document. What is XPath? XPath is a syntax for defining parts of an XML document XPath uses path expressions to navigate in XML documents XPath contains a library of standard functions XPath is a major element in XSLT XPath is a W3C Standard XPath Path Expressions XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look ......

Posted On Sunday, October 15, 2006 6:22 PM

X509Chain Class
Namespace: System.Security.Cryptograph... System (in system.dll) The X509Chain object has a global error status called ChainStatus that should be used for certificate validation. The rules governing certificate validation are complex, and it is easy to oversimplify the validation logic by ignoring the error status of one or more of the elements involved. The global error status takes into consideration the status of each element in the chain.The following code example opens ......

Posted On Sunday, October 15, 2006 6:18 PM

Digital Certification X509Certificate C# Asp.net
Any application of cryptography in building a secured infrastructure uses many of encryption, hashing and signature ciphers. In fact all the cryptographic solutions that are available today include a comprehensive infrastructure with many ciphers, extensive security policies, rich tools for creating, deploying and managing secure applications and other integrated set of cryptographic services. One such infrastructure that comes with Windows 2000 is Public Key Infrastructure (PKI). The challenge for ......

Posted On Sunday, October 15, 2006 6:12 PM

Read Response of a web request in a byte Array with C# Asp.net
this code snippet read the respone fo a web request through binary reader private byte[] getByte(string URL) { HttpWebRequest wrGETURL = (HttpWebRequest)WebRequest.... System.Net.HttpWebResponse webresponse = (HttpWebResponse)wrGETURL.G... string ct = webresponse.ContentType; Stream objStream = webresponse.GetResponseStre... BinaryReader breader = new BinaryReader(objStream); byte[] buffer = breader .ReadBytes((int)webresponse... return buffer; } ......

Posted On Sunday, October 15, 2006 5:57 PM

Force a page to download a file c# asp.net
string Id= "0"; try { this.EnableViewState = false; Response.ContentType = "text/.txt"; string Filename = System.Web.HttpContext.Curr... Filename = Filename + Id + ".txt"; Response.WriteFile(Filename); // Response.Write("string"); string strFilename = Id + ".txt"; Response.Buffer = true; Response.AddHeader("Content... "attachment; filename=" + ID+".txt"); } catch (Exception ex) { Response.Write(ex.ToString()); } Response.End(); ......

Posted On Sunday, October 15, 2006 5:56 PM

How to change the ower of tables in Microsoft SQL Server database
To do this, execute the following command on every table exec sp_changeobjectowner '?????', 'DBO' - where ????? is the name of your database table. Also below is the stored procedure through which you can change the owner for every table in the database. EXEC sp_changeobjectowner @oldownerplusobject, @new create procedure _ChangeObjectOwner (@type varchar(1),@old varchar(20),@new varchar(20)) as declare @ObjectName varchar(100) declare @oldownerplusobject varchar(50) begin declare Cursor_Object cursor ......

Posted On Sunday, October 15, 2006 5:55 PM

Create .VCF File(outlook contact file) with C#
This is code of to create vcf card on the fly //sdBuild is string builder sdBuild.Append("N:" + strCn + System.Environment.NewLine); sdBuild.Append("FN:" + strCn +System.Environment.NewLine); //// encoding to base 64 certString64 = certString64 + System.Environment.NewLine + "KEY;X509;ENCODING=BASE64:" + System.Environment.NewLine; certString64 = certString64 + Convert.ToBase64String((byt... + System.Environment.NewLine; //// encoding to base 64 ends here sdBuild.Append(certString64); sdBuild.Append(System.Envir... ......

Posted On Sunday, October 15, 2006 5:55 PM

LDAP Get Info from Active Directory
To retrive all imformation from avtive directory through ldap protocol using objX509Cert = System.Security.Cryptograph... string filter = "mail=*"; xd = lcl.LDAPInfo(filter); public XmlDocument LDAPInfo(string filter) { XmlDocument xd = new XmlDocument(); string domainAndUsername = string.Empty; string userName = string.Empty; string passWord = string.Empty; string Sur = ""; string Cn = ""; string Name = ""; string GName = ""; string DGname = ""; string Member = ""; string Init = ......

Posted On Sunday, October 15, 2006 5:54 PM

How to change the ower of tables in Microsoft SQL Server database
To do this, execute the following command on every table exec sp_changeobjectowner '?????', 'DBO' - where ????? is the name of your database table. Also below is the stored procedure through which you can change the owner for every table in the database. EXEC sp_changeobjectowner @oldownerplusobject, @new create procedure _ChangeObjectOwner (@type varchar(1),@old varchar(20),@new varchar(20)) as declare @ObjectName varchar(100) declare @oldownerplusobject varchar(50) begin declare Cursor_Object cursor ......

Posted On Sunday, October 15, 2006 5:54 PM

Clear Project List from Start Page
Here is a nice tips to clear the Recent project list or File list from Visual Studio .Net
Run--> RegEdit and navigate to

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\\ProjectMRUList delete unnecessary list.

similarly for FileMRuList.

Make sure not disturb other key from the registry.

Posted On Sunday, October 15, 2006 5:51 PM

Lightweight Directory Access Protocol (LDAP)
In computer networking, the Lightweight Directory Access Protocol, or LDAP ("ell-dap"), is a networking protocol for querying and modifying directory services running over TCP/IP. An LDAP directory usually follows the X.500 model: it is a tree of entries, each of which consists of a set of named attributes with values. While some services use a more complicated "forest" model, the vast majority use a simple starting point for their database organization. An LDAP directory often reflects various political, ......

Posted On Sunday, October 15, 2006 5:49 PM

How to get the HTML name attribute of ASP.Net Control c# as.net
//Function to get the HTML name of the server control from the Client Id // Parameters: // clientId - Control.ClientId // serverId - Control.id private string GetHTMLNameById(string clientId, string serverId) { int pos = serverId.IndexOf('_'); string HTMLName = ""; if(pos >= 0) { pos = clientId.IndexOf(serverId); HTMLName = clientId.Remove(pos, serverId.Length); HTMLName = HTMLName.Replace('_', '$'); HTMLName += serverId; } else HTMLName = clientId.Replace('_', '$'); return HTMLName; } ......

Posted On Sunday, October 15, 2006 5:49 PM

Serialize & Deserialize c# asp.net
Serialize (convert an object instance to an XML document): // Assuming obj is an instance of an object XmlSerializer ser = new XmlSerializer(obj.GetType()); System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter writer = new System.IO.StringWriter(sb); ser.Serialize(writer, obj); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); Deserialize (convert an XML document into an object instance): //Assuming doc is an XML document containing a serialized object ......

Posted On Sunday, October 15, 2006 5:43 PM

How to convert a string to a byte array and convert a byte array to a string c# asp.net
Convert a string to a byte array string myString = "a test string"; byte[] myByteArray = new byte[myString.Length]; int i = 0; foreach(char c in InStr.ToCharArray()) { myByteArray [i] = (byte)c; i++; } Convert a byte array to a string System.Text.Encoding enc = System.Text.Encoding.ASCII; byte[] myByteArray = enc.GetBytes("a text string); string myString = enc.GetString(myByteArray ); ......

Posted On Sunday, October 15, 2006 5:42 PM

Split function in MS Sql, Split string
There is no in bulit function to split values in sql. i have created a tabular function that can split a string in a table. Create function [dbo].[StrFunc_Split] ( @InputStr nvarchar(4000), @SplitChar nchar ) returns @Splittings table ( Position int, Value nvarchar(4000) ) as begin declare @Index int, @LastIndex int, @SNo int set @LastIndex = 0 set @Index = charindex(@SplitChar, @InputStr) set @SNo=0 while @Index > 0 begin set @SNo=@SNo+1 insert into @Splittings(Position, Value) values(@SNo, substring(@InputStr, ......

Posted On Sunday, October 15, 2006 5:39 PM

Diff DataReader/DataAdapter
The DataReader provides forward, read-only access to the data read from the database. It provides no mechanisms for randomly accessing the data. A DataAdapter, along with a DataTable or DataSet, provides random access to data. In addition, the data can be changed in the DataTable or DataSet, and the DataAdapter can be used to update the data in the database. Of the two access methods, the DataReader is the lightest and fastest and is preferable when you need to only read the data, as reflected in ......

Posted On Sunday, October 15, 2006 5:38 PM

Preventing Multiple Logins in ASP.NET
We talked about the fact that the classic ASP Session_OnEnd handler is widely known to be pretty unreliable. However, in ASP.NET the corresponding Global class handler, Session_End, is very reliable. Then we talked about "what if" scenarios, such as what if the ASP.NET worker process was recycled? If so, I reasoned, it didn't matter whether you were using Session, Application or Cache, all of your stuff would be lost. The only exceptions to this would be if you were using the ASP.NET State Server ......

Posted On Sunday, October 15, 2006 5:36 PM

Interview Question
classes MUST follow. It defines method signatures but cannot have any implementations; the latter must be provided by the classes that implement the interface. C# differs from C++ in this regard because C++ lacks native language support for interfaces. As a C++ programmers you have to create an interface by defining an abstract class with pure virtual methods. what is an abstract class................. An Abstract class lets you define some behaviors and force your subclasses to provide others. For ......

Posted On Sunday, October 15, 2006 5:34 PM

What's New in Asp.Net 2.0
1) Application-wide registration of custom controls. One of my biggest complaints about custom controls (and this was true of both UserControls and custom controls from a custom assembly) was that you had to put a “” directive at the top of every .aspx page from which you wanted to declare an instance of the control. One of the main purposes of custom controls was to be able to use them from multiple .aspx pages in one application. Since controls typically encapsulate elements like menus, ......

Posted On Sunday, October 15, 2006 5:34 PM

Resize popup to image size
This script is used to Resize the Popup as per the Image dimensions.
http://www.scriptsearch.com/cgi-bin/jump.cgi?ID=7049

Posted On Sunday, October 15, 2006 5:32 PM

Asp.Net Page Life Cycle

Posted On Sunday, October 15, 2006 5:29 PM

WEB PART
The Major Components of the ASP.NET 2.0 WebPart Framework Before diving into a sample WebPart-driven Web site, you must first understand the major reusable controls built into the .NET framework, which you will use to set up the site: WebPart: A WebPart is a reusable widget on a Web page. The user can choose to add a WebPart on his page, customize the WebPart per his needs, or even define communication between various WebParts. An ASP.NET 2.0 WebPart inherits from the System.Web.UI.WebControls.W... ......

Posted On Sunday, October 15, 2006 5:27 PM

MVC Architecture
The goal of the MVC design pattern is to separate the application object (model) from the way it is represented to the user (view) from the way in which the user controls it (controller). The Model object knows about all the data that need to be displayed. It also knows about all the operations that can be applied to transform that object. However, it knows nothing whatever about the GUI, the manner in which the data are to be displayed, nor the GUI actions that are used to manipulate the data. The ......

Posted On Sunday, October 15, 2006 5:26 PM

SQL Interview Questions
What is normalization? Explain different levels of normalization? What is denormalization and when would you go for it? As the name indicates, denormalization is the reverse process of normalization. It's the controlled introduction of redundancy in to the database design. It helps improve the query performance as the number of joins could be reduced. How do you implement one-to-one, one-to-many and many-to-many relationships while designing tables? One-to-One relationship can be implemented as a ......

Posted On Sunday, October 15, 2006 5:13 PM

Interview Questions
Q1. Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process. Q2. What’s the difference between Response.Write() andResponse.Output.Write()? Sol : Response.Output.Write() allows you to write formatted output. Q3. What methods are fired during the page load? Sol : Init() - when the page is instantiatedLoad() - when the page is loaded into server memoryPreRender() - the brief moment before the page is displayed to the user as HTMLUnload() - when page finishes ......

Posted On Sunday, October 15, 2006 5:06 PM

What is .NET Framework and what are CLR, CTS and CLS?
. NET is a software platform. It's a language-neutral environment for developing .NET applications that can easily and securely operate within it. The .NET Framework has two main components: the Common Language Runtime (CLR) and the .NET Framework class library. The Runtime can be considered an agent that manages code at execution time. Thus providing core services such as memory management, thread management, and remoting. Also incorporating strict type safety, security and robustness. The class ......

Posted On Sunday, October 15, 2006 5:03 PM

HOW TO: Configure SQL Server Security for .NET Applications
This article describes how to configure the SQL Server for .NET applications. By default, the SQL Server denies access to user accounts that have not explicitly been granted access to a database, a table, or a view. By default, ASP.NET applications run in the context of the ASPNET user account. Unless you permit access to the ASPNET user account, an ASP.NET application cannot read and cannot update data in an SQL Server database. This article describes the process that you can use to permit an ASP.NET ......

Posted On Sunday, October 15, 2006 4:59 PM

SQL Injection
SQL injection is a technique used to take advantage of non-validated input vulnerabilities to pass SQL commands through a Web application for execution by a backend database. Attackers take advantage of the fact that programmers often chain together SQL commands with user-provided parameters, and can therefore embed SQL commands inside these parameters. The result is that the attacker can execute arbitrary SQL queries and/or commands on the backend database server through the Web application. Detailed ......

Posted On Sunday, October 15, 2006 4:18 PM

Url Rewriting
<div class="post-body"><p&... style="CLEAR: both"></div><span style="color:#ff0000;">&... Sample </strong> </span> string StrFilePath = Request.FilePath; int intStart = StrFilePath.LastIndexOf("/") + 1 ; int intEnd = StrFilePath.LastIndexOf(".a... int intLength = intEnd - intStart; //CHECK THE URL STRING FOR USER SUB DIRECTORY if(intEnd&gt;0 &amp;& intStart&gt;0) { StrFilePath = StrFilePath.Substring(intSt... ......

Posted On Sunday, October 15, 2006 4:15 PM

Partial Classes in ASP.NET
Partial class is a new functionality that is included in Visual Studio .Net 2005 and is supported in ASP.Net 2.0. This new functionality helps you to split a single class into multiple partial classes. These partial classes can be in different individual files. In the earlier versions of Visual Studio .Net 2005, while you create an ASP.Net application, you might have seen that a single class has to be in a single file. You will be beginning a class and ending that class in the same file. It was not ......

Posted On Sunday, October 15, 2006 4:14 PM

Access to the path containing 'hash.web' is getting denied.
After installing Visual Studio .NET and F5 a couple of times, I used to get this error frequently. The only resolution was to wait for upto 5 to10 mins or restart system, since a folder in Temporary ASP.NET files containing web.config gets locked up automatically. After searching a while in KBs, Forums, I found one closest matching solution, which solved my problem. Just wanted to share with other readers who would also be experiencing this issue. The problem occurs significantly if you touch web.config ......

Posted On Sunday, October 15, 2006 4:12 PM

What is the difference between const and static read-only
A const must be initialized at the time of its creation. A readonly field can be assigned to once in the class constructor allowing you to pass in the value at run-time. Declaring fields as const protects both you and other programmers from accidentally changing the value of the field. Also note that with const fields, the compiler performs some optimization by not declaring any stack space for the field. The readonly keyword is similar to const, with two exceptions. First, the storage of a readonly ......

Posted On Sunday, October 15, 2006 4:10 PM

Asp.Net Caching Basics
At a minimum a developer wants to be able to cache some (or possibly all) of the pages in her ASP.NET Application. The simplest way to achieve this is to add the @ OutputCache directive to the top of the .aspx file of each page:OutputCache Duration="5" VaryByParam="none" %>Now, that was easy, wasn't it? But - exactly what does it do? You are specifying how long the page is to be retained in the Cache with the Duration attribute, inseconds. In the above example, this page will be rendered on the ......

Posted On Sunday, October 15, 2006 4:05 PM

Copyright © Sharvan Dhaka | Powered by: GeeksWithBlogs.net