Gaurav Taneja

Great dreams... never even get out of the box. It takes an uncommon amount of guts to put your dreams on the line, to hold them up and say, "How good or how bad am I?" That's where courage comes in.

  Home  |   Contact  |   Syndication    |   Login
  82 Posts | 1 Stories | 39 Comments | 7 Trackbacks

News




Google RankGoogle PR™ - Post your Page Rank with MyGooglePageRank.com



The content on this site represents my own personal opinions and thoughts at the time of posting, and does not reflect those of my employer's in any way.

Disclaimer:- All postings in this blog is provided "AS IS" with no warranties, and confers no rights.

Archives

Post Categories

Image Galleries

Atlas

Error

OutLook

SharePointService

Usefull Site Links

Sunday, November 22, 2009 #

What is Proxy and how to generate proxy for WCF Services?
 
The proxy is a CLR class that exposes a single CLR interface representing the service contract. The proxy provides the same operations as service's contract, but also has additional methods for managing the proxy life cycle and the connection to the service. The proxy completely encapsulates every aspect of the service: its location, its implementation technology and runtime platform, and the communication transport.
 
The proxy can be generated using Visual Studio by right clicking Reference and clicking on Add Service Reference. This brings up the Add Service Reference dialog box, where you need to supply the base address of the service (or a base address and a MEX URI) and the namespace to contain the proxy.
 
Proxy can also be generated by using SvcUtil.exe command-line utility. We need to provide SvcUtil with the HTTP-GET address or the metadata exchange endpoint address and, optionally, with a proxy filename. The default proxy filename is output.cs but you can also use the /out switch to indicate a different name.
 
SvcUtil http://localhost/MyService/MyService.svc /out:Proxy.cs
 
When we are hosting in IIS and selecting a port other than port 80 (such as port 88), we must provide that port number as part of the base address:
 
SvcUtil http://localhost:88/MyService/MyService.svc /out:Proxy.cs
 
What are contracts in WCF?
 
In WCF, all services expose contracts. The contract is a platform-neutral and standard way of describing what the service does.
 
WCF defines four types of contracts.
 
 
Service contracts
 
Describe which operations the client can perform on the service.
There are two types of Service Contracts.
ServiceContract - This attribute is used to define the Interface.
OperationContract - This attribute is used to define the method inside Interface.
 
[ServiceContract]
interface IMyContract
{
   [OperationContract]
   string MyMethod( );
}
class MyService : IMyContract
{
   public string MyMethod( )
   {
      return "Hello World";
   }
}
 
 
Data contracts
 
Define which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.
 
There are two types of Data Contracts.
DataContract - attribute used to define the class
DataMember - attribute used to define the properties.
 
[DataContract]
class Contact
{
   [DataMember]
   public string FirstName;
 
   [DataMember]
   public string LastName;
}
 
If DataMember attributes are not specified for a properties in the class, that property can't be passed to-from web service.
 
Fault contracts
 
Define which errors are raised by the service, and how the service handles and propagates errors to its clients.
 
 
Message contracts
 
Allow the service to interact directly with messages. Message contracts can be typed or untyped, and are useful in interoperability cases and when there is an existing message format we have to comply with.
 
What is the address formats of the WCF transport schemas?
 
Address format of WCF transport schema always follow
 
[transport]://[machine or domain][:optional port] format.
 
for example:
 
HTTP Address Format
 
http://localhost:8888
the way to read the above url is
 
"Using HTTP, go to the machine called localhost, where on port 8888 someone is waiting"
When the port number is not specified, the default port is 80.
 
TCP Address Format
 
net.tcp://localhost:8888/MyService
 
When a port number is not specified, the default port is 808:
 
net.tcp://localhost/MyService
 
NOTE: Two HTTP and TCP addresses from the same host can share a port, even on the same machine.
 
IPC Address Format
net.pipe://localhost/MyPipe
 
We can only open a named pipe once per machine, and therefore it is not possible for two named pipe addresses to share a pipe name on the same machine.
 
MSMQ Address Format
net.msmq://localhost/private/MyService
net.msmq://localhost/MyService
 
How to define a service as REST based service in WCF?
 
WCF 3.5 provides explicit support for RESTful communication using a new binding named WebHttpBinding.
The below code shows how to expose a RESTful service
 
[ServiceContract]
interface IStock
{
[OperationContract]
[WebGet]
int GetStock(string StockId);
}
 
By adding the WebGetAttribute, we can define a service as REST based service that can be accessible using HTTP GET operation.
 
What is endpoint in WCF?
Posted by: Poster | Show/Hide Answer
Every service must have Address that defines where the service resides, Contract that defines what the service does and a Binding that defines how to communicate with the service. In WCF the relationship between Address, Contract and Binding is called Endpoint.
 
The Endpoint is the fusion of Address, Contract and Binding.
 
What is binding and how many types of bindings are there in WCF?
 
A binding defines how an endpoint communicates to the world. A binding defines the transport (such as HTTP or TCP) and the encoding being used (such as text or binary). A binding can contain binding elements that specify details like the security mechanisms used to secure messages, or the message pattern used by an endpoint.
 
WCF supports nine types of bindings.
 
Basic binding
 
Offered by the BasicHttpBinding class, this is designed to expose a WCF service as a legacy ASMX web service, so that old clients can work with new services. When used by the client, this binding enables new WCF clients to work with old ASMX services.
 
TCP binding
 
Offered by the NetTcpBinding class, this uses TCP for cross-machine communication on the intranet. It supports a variety of features, including reliability, transactions, and security, and is optimized for WCF-to-WCF communication. As a result, it requires both the client and the service to use WCF.
 
 
Peer network binding
 
Offered by the NetPeerTcpBinding class, this uses peer networking as a transport. The peer network-enabled client and services all subscribe to the same grid and broadcast messages to it.
 
 
IPC binding
 
Offered by the NetNamedPipeBinding class, this uses named pipes as a transport for same-machine communication. It is the most secure binding since it cannot accept calls from outside the machine and it supports a variety of features similar to the TCP binding.
 
 
Web Service (WS) binding
 
Offered by the WSHttpBinding class, this uses HTTP or HTTPS for transport, and is designed to offer a variety of features such as reliability, transactions, and security over the Internet.
 
 
Federated WS binding
 
Offered by the WSFederationHttpBinding class, this is a specialization of the WS binding, offering support for federated security.
 
 
Duplex WS binding
 
Offered by the WSDualHttpBinding class, this is similar to the WS binding except it also supports bidirectional communication from the service to the client.
 
 
MSMQ binding
 
Offered by the NetMsmqBinding class, this uses MSMQ for transport and is designed to offer support for disconnected queued calls.
 
 
MSMQ integration binding
 
Offered by the MsmqIntegrationBinding class, this converts WCF messages to and from MSMQ messages, and is designed to interoperate with legacy MSMQ clients.
 
For WCF binding comparison, see http://www.pluralsight.com/community/blogs/aaron/archive/2007/03/22/46560.aspx
 
Where we can host WCF services?
Posted by: Poster | Show/Hide Answer
Every WCF services must be hosted somewhere. There are three ways of hosting WCF services.
 
They are
 
1. IIS
2. Self Hosting
3. WAS (Windows Activation Service)
 
For more details see http://msdn.microsoft.com/en-us/library/bb332338.aspx
 
What is address in WCF and how many types of transport schemas are there in WCF?
 
Address is a way of letting client know that where a service is located. In WCF, every service is associated with a unique address. This contains the location of the service and transport schemas.
 
WCF supports following transport schemas
 
HTTP
TCP
Peer network
IPC (Inter-Process Communication over named pipes)
MSMQ
 
The sample address for above transport schema may look like
 
http://localhost:81
http://localhost:81/MyService
net.tcp://localhost:82/MyService
net.pipe://localhost/MyPipeService
net.msmq://localhost/private/MyMsMqService
net.msmq://localhost/MyMsMqService
 
What is service and client in perspective of data communication?
 
A service is a unit of functionality exposed to the world.
 
The client of a service is merely the party consuming the service.
 
What is WCF?
 
Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for services, enabling you to expose CLR types as services, and to consume other services as CLR types.
 
 
Difference between WCF and Web services?
Web Services
 
1.It Can be accessed only over HTTP
2.It works in stateless environment
 
WCF
 
WCF is flexible because its services can be hosted in different types of applications. The following lists several common scenarios for hosting WCF services:
IIS
WAS
Self-hosting
Managed Windows Service
 
What are the various ways of hosting a WCF service?
Self hosting the service in his own application domain. This we have already covered in the first section. The service comes in to existence when you create the object of ServiceHost class and the service closes when you call the Close of the ServiceHost class.
Host in application domain or process provided by IIS Server.
Host in Application domain and process provided by WAS (Windows Activation Service) Server.
 
What is three major points in WCF?
We Should remember ABC.
 
Address --- Specifies the location of the service which will be like http://Myserver/MyService.Clients will use this location to communicate with our service.
 
Binding --- Specifies how the two paries will communicate in term of transport and encoding and protocols
 
Contract --- Specifies the interface between client and the server.It's a simple interface with some attribute.
 
What is the difference WCF and Web services?
Web services can only be invoked by HTTP (traditional webservice with .asmx). While WCF Service or a WCF component can be invoked by any protocol (like http, tcp etc.) and any transport type.
 
Second web services are not flexible. However, WCF Services are flexible. If you make a new version of the service then you need to just expose a new end. Therefore, services are agile and which is a very practical approach looking at the current business trends.
 
We develop WCF as contracts, interface, operations, and data contracts. As the developer we are more focused on the business logic services and need not worry about channel stack. WCF is a unified programming API for any kind of services so we create the service and use configuration information to set up the communication mechanism like HTTP/TCP/MSMQ etc
 
 
What are various ways of hosting WCF Services?
There are three major ways of hosting a WCF services
 
• Self-hosting the service in his own application domain. This we have already covered in the first section. The service comes in to existence when you create the object of Service Host class and the service closes when you call the Close of the Service Host class.
 
• Host in application domain or process provided by IIS Server.
 
• Host in Application domain and process provided by WAS (Windows Activation Service) Server.
 
 
What was the code name for WCF?
The code name of WCF was Indigo .
 
WCF is a unification of .NET framework communication technologies which unites the following technologies:-
 
NET remoting
MSMQ
Web services
COM+
 
What are the main components of WCF?
Posted by: Raja | Show/Hide Answer
The main components of WCF are
 
1. Service class
2. Hosting environment
3. End point
 
For more details read http://www.dotnetfunda.com/articles/article221.aspx#WhatarethemaincomponentsofWCF
 
How to set the timeout property for the WCF Service client call?
Posted by: Poster | Show/Hide Answer
The timeout property can be set for the WCF Service client call using binding tag.
 
<client>
   <endpoint
      ...
      binding = "wsHttpBinding"
      bindingConfiguration = "LongTimeout"
      ...
   />
</client>
<bindings>
   <wsHttpBinding>
      <binding name = "LongTimeout" sendTimeout = "00:04:00"/>
   </wsHttpBinding>
</bindings>
 
If no timeout has been specified, the default is considered as 1 minute.
 
How to deal with operation overloading while exposing the WCF services?
Posted by: Poster | Show/Hide Answer
By default overload operations (methods) are not supported in WSDL based operation. However by using Name property of OperationContract attribute, we can deal with operation overloading scenario.
 
[ServiceContract]
interface ICalculator
{
   [OperationContract(Name = "AddInt")]
   int Add(int arg1,int arg2);
 
   [OperationContract(Name = "AddDouble")]
   double Add(double arg1,double arg2);
}
 
 
Notice that both method name in the above interface is same (Add), however the Name property of the OperationContract is different. In this case client proxy will have two methods with different name AddInt and AddDouble.
 
How to configure Reliability while communicating with WCF Services?
Posted by: Poster | Show/Hide Answer
Reliability can be configured in the client config file by adding reliableSession under binding tag.
 
<system.serviceModel>
   <services>
      <service name = "MyService">
         <endpoint
            address = "net.tcp://localhost:8888/MyService"
            binding = "netTcpBinding"
            bindingConfiguration = "ReliableCommunication"
            contract = "IMyContract"
         />
      </service>
   </services>
   <bindings>
      <netTcpBinding>
         <binding name = "ReliableCommunication">
            <reliableSession enabled = "true"/>
         </binding>
      </netTcpBinding>
   </bindings>
</system.serviceModel>
 
Reliability is supported by following bindings only
 
NetTcpBinding
WSHttpBinding
WSFederationHttpBinding
WSDualHttpBinding
 
What is Transport and Message Reliability?
Transport reliability (such as the one offered by TCP) offers point-to-point guaranteed delivery at the network packet level, as well as guarantees the order of the packets. Transport reliability is not resilient to dropping network connections and a variety of other communication problems.
 
Message reliability deals with reliability at the message level independent of how many packets are required to deliver the message. Message reliability provides for end-to-end guaranteed delivery and order of messages, regardless of how many intermediaries are involved, and how many network hops are required to deliver the message from the client to the service.
 
What are different elements of WCF Srevices Client configuration file?
WCF Services client configuration file contains endpoint, address, binding and contract. A sample client config file looks like
 
<system.serviceModel>
   <client>
      <endpoint name = "MyEndpoint"
         address = "http://localhost:8000/MyService/"
         binding = "wsHttpBinding"
         contract = "IMyContract"
      />
   </client>
</system.serviceModel>
 

 


Monday, June 29, 2009 #

Create

Procedure GT_DeleteRecords_AllTables

As

 

/*********************************************************

Stored Procedure: GT_DeleteRecords_AllTables

Do not excute this proc

Purpose: Delete ALL records within ALL the tables in a DB with ease.

Test: Exec GT_DeleteRecords_AllTables**********************************************************/

Set

Exec

nocount on sp_MSForEachTable 'Alter Table ? NoCheck Constraint All'

Exec

sp_MSForEachTable

'

If ObjectProperty(Object_ID(''?''), ''TableHasForeignRef'')=1

Begin

-- Just to know what all table used delete syntax.

Print ''Delete from '' + ''?''

Delete From ?

End

Else

Begin

-- Just to know what all table used Truncate syntax.

Print ''Truncate Table '' + ''?''

Truncate Table ?

End

'

Exec

sp_MSForEachTable 'Alter Table ? Check Constraint All'

Wednesday, December 10, 2008 #

To change the color of Tab control
 
Add this event handler
 
  1. DrawMode property to OwnerDrawFixed.
  2. Override the DrawItem event handler definition.
 
tabControl2.DrawItem += new DrawItemEventHandler(OnDrawItem);
 
 
step 2
 
 
 
 
 
 
private void OnDrawItem(object sender, DrawItemEventArgs e)
        {
           
            TabPage CurrentTab = tabControl2.TabPages[e.Index];
            Rectangle ItemRect = tabControl2.GetTabRect(e.Index);
            SolidBrush FillBrush = new SolidBrush(Color.Red);
            SolidBrush TextBrush = new SolidBrush(Color.White);
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
 
            //If we are currently painting the Selected TabItem we'll
            //change the brush colors and inflate the rectangle.
            if (System.Convert.ToBoolean(e.State & DrawItemState.Selected))
            {
                FillBrush.Color = Color.PaleTurquoise;
                TextBrush.Color = Color.Red;
                ItemRect.Inflate(2, 2);
            }
 
            //Set up rotation for left and right aligned tabs
            if (tabControl2.Alignment == TabAlignment.Left || tabControl2.Alignment == TabAlignment.Right)
            {
                float RotateAngle = 90;
                if (tabControl2.Alignment == TabAlignment.Left)
                    RotateAngle = 270;
                PointF cp = new PointF(ItemRect.Left + (ItemRect.Width / 2), ItemRect.Top + (ItemRect.Height / 2));
                e.Graphics.TranslateTransform(cp.X, cp.Y);
                e.Graphics.RotateTransform(RotateAngle);
                ItemRect = new Rectangle(-(ItemRect.Height / 2), -(ItemRect.Width / 2), ItemRect.Height, ItemRect.Width);
            }
 
            //Next we'll paint the TabItem with our Fill Brush
            e.Graphics.FillRectangle(FillBrush, ItemRect);
 
            //Now draw the text.
            e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, (RectangleF)ItemRect, sf);
 
            //Reset any Graphics rotation
            e.Graphics.ResetTransform();
 
            //Finally, we should Dispose of our brushes.
            FillBrush.Dispose();
            TextBrush.Dispose();
        }
 

CREATING DLL DYNAMICALLY

you need to complie this code

Public Function CreateResourceAssembly() As Boolean
        Dim currentpageHashVal As Hashtable = New Hashtable()
        Dim intArrIndx As Integer
        Dim strTextVal As String
        Dim blnIsSuccess As Boolean
        Dim strAsmFileName As String = FetchTest.resources.dll
        Dim strPathAssmbly As String = strAppPath + FetchTest.resources.dll"
 
        Dim appdomain As AppDomain = Thread.GetDomain()
        Dim asmName As New AssemblyName()
        Dim strVersion As String = Nothing
        Dim strKey As String = Nothing
        Dim hashResPage As Hashtable = New Hashtable()
        Dim ItemEnumeratorPage As System.Collections.IDictionaryEnumerator
        Dim blnIdExist As Boolean = False
 
        asmName.Name = Wpms.resources.dl
 
        Dim resourceName As String = Wpms.resources"
        asmName.CodeBase = strPath
        Dim strDate As String
        strDate = Date.Now.ToString("dd/MM/yyyy").Replace("/", "")
        intBuild = CType(strDate, Integer)
        intRev = intRev + 1
        strVersion = "1.0.0" & "." & CType(intRev, String)
        asmName.Version = New Version(1, 0, 0, intRev)
        asmName.CultureInfo = New CultureInfo(strLang)
 
        Dim asmBuilder As AssemblyBuilder = appdomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave, strPath)
        Dim modulebuilder As ModuleBuilder = asmBuilder.DefineDynamicModule(strAsmFileName, strAsmFileName)
        Dim resWriter As System.Resources.IResourceWriter
        Dim blnGenEngRes As Boolean = True
        resWriter = modulebuilder.DefineResource(resourceName, "MyDescription", ResourceAttributes.Public)
 
‘ writing in resource file below is a n example ….
   Dim ItemEnumerator As System.Collections.IDictionaryEnumerator
ItemEnumerator = resHastable.GetEnumerator()
   Do While ItemEnumerator.MoveNext
                    resWriter.AddResource(CType(ItemEnumerator.Key, String), CType(ItemEnumerator.Value, String))
                Loop
 
                asmBuilder.Save(strAsmFileName) ‘ SAVING ASSEMBLY
Return blnIsSuccess
 
End Function

                   
Reading a dll into bytes
Dim strPathAssmbly As String ="c:\abc.dll"
Dim btByte() As Byte = File.ReadAllBytes(strPathAssmbly)

Diplaying the controls
 
Public Sub DisplayControlName(ByVal oControl As Control, ByVal strPageName As String)
 
        Dim txtBox As TextBox
        Dim ddlLst As DropDownList
        Dim rdBtn As RadioButton
        Dim rdBtnLst As RadioButtonList
        Dim chkBx As CheckBoxList
        Dim chkBx1 As CheckBox
        Dim lblVal As System.Web.UI.WebControls.Label
        Dim htmTbl As System.Web.UI.HtmlControls.HtmlTable
        Dim btnVal As System.Web.UI.WebControls.Button
 
 
        ' Checks for all the WebBased Control in the web page
 
                Select Case oControl.GetType.ToString
 
 
 
                    'Case "System.Web.UI.WebControls.TextBox" ' for textbox control
                    '    txtBox = oControl.FindControl(oControl.ID)
                    '    If Not txtBox.ID Is Nothing Then
                    '        If Not txtBox.Text.ToString() Is Nothing Then
                    '            If txtBox.Text.Length > 0 Then
                    '                ArrayLst.Add(New String() {strPageName & "_" & txtBox.ID & "_" & "TextBox" & "_" & "N/A", txtBox.Text.ToString()})
                    '            End If
                    '        End If
                    '    End If
 
                    Case  MultiLang_DropDownListControl ' for Dropdownlist control
                        ddlLst = oControl.FindControl(oControl.ID)
                        If Not ddlLst Is Nothing Then
 
                        End If
 
                    Case  MultiLang_RadioButtonControl ' for radio button control
                        rdBtn = oControl.FindControl(oControl.ID)
                        If Not rdBtn Is Nothing Then
                            ArrayLst.Add(New String() {strPageName & "_" & rdBtn.ID & "_" MultiLang_RadioButton & "_" & MultiLang_NA, rdBtn.Text.ToString()})
                        End If
                    Case  MultiLang_RadioButtonListControl ' for radio button control
                        rdBtnLst = oControl.FindControl(oControl.ID)
                        If Not rdBtnLst Is Nothing Then
                            Dim MyItem As ListItem
                            For Each MyItem In rdBtnLst.Items
                                ArrayLst.Add(New String() {strPageName & "_" & rdBtnLst.ID & "_" &  MultiLang_RadioButtonList & "_" & MyItem.Value & "_" &  MultiLang_NA, MyItem.Text.ToString()})
                            Next
                        End If
                    Case  MultiLang_CheckBoxListControl
                        chkBx = oControl.FindControl(oControl.ID)
                        If Not chkBx Is Nothing Then
                            Dim MyItem As ListItem
                            For Each MyItem In chkBx.Items
                                ArrayLst.Add(New String() {strPageName & "_" & chkBx.ID & "_" &  MultiLang_CheckBoxList & "_" & MyItem.Value & "_" &  MultiLang_NA, MyItem.Text.ToString()})
                            Next
                        End If
                    Case  MultiLang_CheckBoxControl ' for checkbox control
                        Try
                            'Dim strVal As Object
                            If Not TypeOf oControl.NamingContainer Is CheckBoxList Then
                                chkBx1 = oControl.FindControl(oControl.ID)
                                If Not chkBx1 Is Nothing Then
                                    If Not chkBx1.Text.Equals("") Then
                                        ArrayLst.Add(New String() {strPageName & "_" & chkBx1.ID & "_" &  MultiLang_CheckBox & "_" &  MultiLang_NA, chkBx1.Text.ToString()})
                                    End If
                                End If
                            End If
                        Catch ex As Exception
 
                        End Try
 
                    Case  MultiLang_LabelControl ' for label control
                        Try
                            lblVal = oControl.FindControl(oControl.ID)
                            ' HttpContext.Current.Response.Write("<br>" & "Label:- " & lblVal.Text)
                            If Not lblVal Is Nothing Then
                                If Not lblVal.Text.Equals("") Then
                                    ArrayLst.Add(New String() {strPageName & "_" & lblVal.ID & "_" &  MultiLang_Label & "_" &  MultiLang_NA, lblVal.Text.ToString()})
                                End If
                            End If
                        Catch ex As Exception
 
                        End Try
 
 
                    Case  MultiLang_HtmlTableControl ' for fetching table control
 
                        htmTbl = oControl.FindControl(oControl.ID)
                        Dim MyRow As System.Web.UI.HtmlControls.HtmlTableRow
                        Dim mycell As System.Web.UI.HtmlControls.HtmlTableCell
                        Try
                            ' Travesing each row in the table and then traversing the cells
                            For Each MyRow In htmTbl.Rows
                                For Each mycell In MyRow.Cells
                                    If mycell.Controls(0).GetType().ToString().Equals( MultiLang_LiteralControl) Then
                                        ' If mycell.InnerText.Length > 0 Then
                                        If Not mycell.ID Is Nothing Then
                                            If Not mycell.InnerText.ToString() Is Nothing Then
                                                If mycell.InnerText.Length > 0 Then
                                                    ArrayLst.Add(New String() {strPageName & "_" & mycell.ID & "_" &  MultiLang_td & "_" &  MultiLang_NA, mycell.InnerText.ToString()})
                                                End If
                                            End If
                                        End If
                                        'End If
                                    End If
                                Next
                            Next
                        Catch ex As Exception
 
                        End Try
 
                    Case  MultiLang_ButtonControl ' for fetching button control
                        btnVal = oControl.FindControl(oControl.ID)
                        If Not btnVal Is Nothing Then
                            ArrayLst.Add(New String() {strPageName & "_" & btnVal.ID & "_" &  MultiLang_Button & "_" &  MultiLang_NA, btnVal.Text.ToString()})
                        End If
                End Select
 
    End Sub

 

How to fetch Page controls of web form Dynamically in vb.net

 

To Find the Page Controls in a Web Page
 
Public Function FindPageControl(ByVal oControlCollection As ControlCollection, ByVal strPageName As String) As ArrayList
        ' Traverses all the controls in the page
        For Each oControl As Control In oControlCollection
            DisplayControlName(oControl, strPageName)
            FindPageControl(oControl.Controls, strPageName)
        Next
        Return ArrayLst
    End Function
How to call this function
 
FindPageControl(Page.Controls, strPgName)

Monday, August 04, 2008 #

Looop through the controls...

 

Private

 

SetTooltip(oControl, strToolTip)

FindToolTipControl(oControl.Controls, strToolTip)

 

Sub FindToolTipControl(ByVal oControlCollection As ControlCollection, ByVal strToolTip As String)For Each oControl As Control In oControlCollectionNext

 

......................

 

 

 

Private Sub SetTooltip(ByVal oControl As Control, ByVal strToolTip As String)Select Case oControl.GetType.ToStringCase "System.Web.UI.WebControls.TextBox"

 

Response.Write(

 

Dim otxt As TextBox = oControl.FindControl(oControl.ID)"<br>" & "TextBox:- " & otxt.Text.ToString())Case "System.Web.UI.WebControls.DropDownList"

 

Response.Write(

 

Dim oDdl As DropDownList = oControl.FindControl(oControl.ID)"<br>" & "DropDown :- " & oDdl.Text.ToString())Case "System.Web.UI.WebControls.RadioButton"

 

Response.Write(

 

Dim oRdbtn As RadioButton = oControl.FindControl(oControl.ID)"<br>" & "RadioButton:- " & oRdbtn.Text.ToString())Case "System.Web.UI.WebControls.CheckBox"

 

 

Dim oChkbx As CheckBoxList = oControl.FindControl(oControl.ID)'Response.Write("<br>" & "Ckeckboxloist" & oChkList.Items.Count.ToString())

 

 

Response.Write(

 

Dim MyItem As ListItemFor Each MyItem In oChkbx.Items"<br>" & "Ckeckbox:- " & MyItem.Text.ToString())Next

 

Case "System.Web.UI.WebControls.Label"

 

Response.Write(

 

Dim oLabel As Label = oControl.FindControl(oControl.ID)"<br>" & "Label:- " & oLabel.Text)Case "System.Web.UI.WebControls.CheckBoxList"

 

 

Dim oChkList As CheckBoxList = oControl.FindControl(oControl.ID)'Response.Write("<br>" & "Ckeckboxloist" & oChkList.Items.Count.ToString())

 

 

Response.Write(

 

Dim MyItem As ListItemFor Each MyItem In oChkList.Items"<br>" & "Ckeckboxlist:- " & MyItem.Text.ToString())Next

 

Case "System.Web.UI.HtmlControls.HtmlTableRow"

 

 

Dim oTbrw As HtmlTableRow = oControl.FindControl(oControl.ID)'Response.Write("<br>" & "Table row:- " & oTbrw.InnerText.ToString())

 

End Select

 

End Sub

End Sub

Monday, May 05, 2008 #

Count Procedure

select  count(*) from sysobjects where xtype='P'

other option is below

select CASE(XType) WHEN 'C' THEN 'CHECK constraint'
WHEN 'D' THEN 'Default or DEFAULT constraint'
WHEN 'F' THEN 'FOREIGN KEY constraint'
WHEN 'L' THEN 'Log'
WHEN 'FN' THEN 'Scalar function'
WHEN 'IF' THEN 'Inlined table-function'
WHEN 'P' THEN 'Stored procedure'
WHEN 'PK' THEN 'PRIMARY KEY constraint (type is K)'
WHEN 'RF' THEN 'Replication filter stored procedure'
WHEN 'S' THEN 'System table'
WHEN 'TF' THEN 'Table function'
WHEN 'TR' THEN 'Trigger'
WHEN 'U' THEN 'User table'
WHEN 'UQ' THEN 'UNIQUE constraint (type is K)'
WHEN 'V' THEN 'View'
WHEN 'X' THEN 'Extended stored procedure' END Type
, Count(*) as total from sysObjects
GROUP BY xtype

Thursday, April 17, 2008 #


UrlRewriting is one of the interesting and advance topics in ASP.Net, following is the link shows the comprehensive information on URLRewriting.

Scott has give a fantastic detailed article on URL Rewriting. here

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

http://msdn.microsoft.com/asp.net/community/authors/scottmitchell/default.aspx?pull=/library/en-us/dnaspp/html/urlrewriting.asp

The following link is the example with source code available

http://urlrewriting.net/en/Download.aspx
http://weblogs.asp.net/fmarguerie/archive/2004/11/18/265719.aspx

Possible Cause:-
         When you install IIS AFTER .NET 2.0 framework, the rights of the ASPNET user had not been set correctly.

Resolution
         Repair (Uninstall if repair does not work for you)  .NET Framework 2.0

Simply run the following from command line to reset the IIS registry settings for aspnet user. Usually framework directory for .Net Framework 2.0 resides under C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727


Wednesday, April 16, 2008 #

Well while implementing Ajax i had received error due to Sys.WebForms.PageRequestManagerParserErrorException

the best solution that i could figure out to over come is catch this exception and byPass it.. if any body has a good way of catching this exception why this arise Please do let me know.

i has to modify the script

<script type="text/javascript">
                                        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, args)
                                        {
                                          
                                             if (args.get_error()!=null)
                                             {
                                                                                        
                                                 if (args.get_error().name === 'Sys.WebForms.PageRequestManagerParserErrorException')
                                                 {
                                                   
                                                    // remember to set errorHandled = true to keep from getting a popup from the AJAX library itself
                                                    args.set_errorHandled(true);
                                                     window.location.href='Login.aspx?Message=SessionExpired';
                                                }                                                
                                                 if ( args.get_error().name === 'Sys.WebForms.PageRequestManagerTimeoutException')
                                                {
                                                  
                                                    // remember to set errorHandled = true to keep from getting a popup from the AJAX library itself
                                                    args.set_errorHandled(true);
                                                    window.location.href='Login.aspx?Message=SessionExpired';
                                                }
                                             
                                             }
                                         }
                                         );
                                     </script>

Monday, April 07, 2008 #

Below is the solution


<asp:GridView ID="gvSubject" runat="server" >

<Columns>

<asp:HyperLinkField DataTextField="CategoryName" DataNavigateUrlFields="SubjectID,SubjectName,Description" DataNavigateUrlFormatString="TargetPage.aspx?SubjectID={0}&SubjectName={1}&description={2}" />

</Columns>

</asp:GridView>


Sunday, April 06, 2008 #

 public static bool CheckImageExist(string strImageURL)
        {
            bool blnImageExist = true;
            System.Net.HttpWebRequest httpImageRequest = null;
            System.Net.HttpWebResponse httpImageResponse = null;

            // Sends the HttpWebRequest and waits for the response.
            try
            {
                httpImageRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strImageURL);
                httpImageResponse = (System.Net.HttpWebResponse)httpImageRequest.GetResponse();
            }
            catch (Exception ex)
            {
                blnImageExist = false;
            }

            return blnImageExist;
        }

WrapCharacters

 
public static string WrapCharacters(object objstr, int intNum)
        {
            if (objstr == System.DBNull.Value)
            { return ""; }

            string str = (string)objstr;
            int intLen = str.Length / intNum;
            int intInsertedChars = 0;

            if (intLen < 1)
            {
                return str;
            }
            int intStartIndex = 0;
            if (str.IndexOf(" ", 0) < intNum && str.IndexOf(" ", 0) != -1)
            {
                intStartIndex = str.IndexOf(" ", 0) + 1;
                intLen = str.Length - intStartIndex;
                intLen = intLen / intNum;
            }
            for (int intCount = 0; intCount < intLen; intCount++)
            {

                if (intCount > 0)
                    intStartIndex = intCount * intNum + 1;

                if (str.IndexOf(" ", intStartIndex) == -1 || str.IndexOf(" ", intStartIndex) > intNum)
                {
                    int intInsertIndex = (intNum * intCount) + intNum + intInsertedChars;
                    string strSubPart = "";
                    intStartIndex = intStartIndex + intInsertedChars;
                    if (intStartIndex + intNum > str.Length)
                    {
                        strSubPart = str.Substring(intStartIndex, str.Length - intStartIndex);
                    }
                    else
                    {
                        strSubPart = str.Substring(intStartIndex, intNum);
                    }
                    if (strSubPart.IndexOf(" ") == -1)
                    {
                        str = str.Insert(intInsertIndex, " ");
                        intInsertedChars++;
                    }

                }
            }
            return str.Trim();
        }