Anatomy of UDC

on Thursday, October 22, 2009

The anatomy of a UDC file

OK, we’ve talked about super-fantastic high end authentication scenarios. We’ve talked about cross-domain security and administrative control. We’ve talked about generating UDC files using InfoPath and consuming them again in the designer. Now let’s drill into the structure of the file itself.


UDC V2 is an XML format, and like any good XML format, there is a schema and a namespace associated with it. I’ll give you the full schema at the end of this post.

A handy tip: copy the schema into notepad and save it with an xsd extension, then follow the steps outlined in Aaron Stebner’s blog here: http://blogs.msdn.com/astebner/archive/2005/12/07/501466.aspx to add the xsd file to Visual Studio’s intellisense cache. Once that’s in place, Visual Studio will help you generate your UDC files!


Basic Structure of the File

Every UDC file you create will have the structure below, so copy it to notepad and use it as the basis for all your files. This is the infrastructure – the metadata that describes the connection and allows external components such as SharePoint and InfoPath to understand what’s inside.

<?MicrosoftWindowsSharePointServices ContentTypeID=”0x010100B4CBD48E029A4ad8B62CB0E41868F2B0”?>
<udc:DataSource MajorVersion="2" MinorVersion="0" xmlns:udc="http://schemas.microsoft.com/office/infopath/2006/udc">
  <udc:Name/>
  <udc:Description/>
  <udc:Type MajorVersion="2" MinorVersion="0" Type=""/>
  <udc:ConnectionInfo Purpose="" AltDataSource=””/>
</udc:DataSource>


The file begins with a processing instruction specifying a Content Type Id. This is necessary to associate the file with the UDC content type on a Microsoft Office SharePoint 2007 server. Having the content type identified allows the Name, Title, Description, Type, and Purpose fields to be promoted into columns in the data connection library so that the InfoPath designer can see the file.

By the way: there’s a known issue on Windows Vista where the title property doesn’t get promoted when using the Convert function in the InfoPath designer. To work around this issue, save the file to your local disk, and then re-upload the file to the library using the SharePoint library upload function.

The root node is called DataSource, and it specifies the UDC version of 2.0, as well as the udc V2 namespace. The Name and Description fields are promoted into SharePoint columns, and they show up in the InfoPath designer when browsing to the file in the data connection wizard. So, while these fields are not strictly required, you should use them to provide useful information about what the data connection is about, and maybe even contact information for the owner of the data source.

Type (specifically, the Type attribute on the Type element) and Purpose are both required, and very easy to fill once you know the possible values:

DataSource/Type/@Type:


Value



Use for


SharePointList


SharePoint list query connection


SharePointLibrary


SharePoint Library submit connection


Database


Database query connection


XmlQuery


Xml file query connection


XmlSubmit


HTTP Post submit connection


WebService


Web service submit or query connection


DataSource/ConnectionInfo/@Purpose:



Value


Use for


ReadOnly


All query connections


WriteOnly



All submit connections


ReadWrite


Web service only, when both query and submit methods are specified and they reference the same WSDL

The AltDataSource attribute specifies a second UDC file in the same library. When specified, InfoPath will use the original file, and Forms Services will use the file specified in the attribute. The attribute's value should be the filename of the alternate UDC file. Naturally, the two files should specify equivalent connections - specifically, the connections have to have the same Type and Purpose, and they have to return the same data, or data in the same format.


The ConnectionInfo Element

The meat of the connection information is here, and each type of data connection requires specific elements. So, the contents of this element will change depending on the Type and Purpose attributes.

Let’s run ‘em down, shall we? I’m confident that you can learn by example, so I’m not going to do a lot of explaining here. As I noted in a previous post, we’re working on a schema reference that will fill in the details.


1. Web Service
This example is for a query connection. For a submit connection, the Purpose would be WriteOnly, and the ServiceUrl and SoapAction would be contained within an UpdateCommand element rather than SelectCommand.

Web service is the only connection type that can have both a SelectCommand and an UpdateCommand in the same file. The two operations need to share the same WSDL, and the Purpose in that case is ReadWrite.

<udc:ConnectionInfo Purpose=”ReadOnly”>
   <udc:WsdlUrl>
   http://www.someserver.com/service/service1.asmx?wsdl
 </udc:WsdlUrl>
 <udc:SelectCommand>
  <udc:ServiceUrl>
   http://www.someservice.com/service/service1.asmx
  </udc:ServiceUrl>
  <udc:SoapAction>
   http://www.someservice.com/service/SomeOperation
  </udc:SoapAction>
 </udc:SelectCommand>
</udc:ConnectionInfo>

2. Database
A database connection is always marked as ReadOnly. InfoPath determines at design time whether submit can be enabled for the connection.


<udc:ConnectionInfo Purpose=”ReadOnly”>
 <udc:SelectCommand>
  <udc:ConnectionString>
Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\temp\Database1.accdb;Mode=Share Deny None;Jet OLEDB:System database=&quot;&quot;;Jet OLEDB:Registry Path=&quot;&quot;;Jet OLEDB:Database Password=&quot;&quot;;Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=&quot;&quot;;Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;
  </udc:ConnectionString>
  <udc:Query>SELECT * FROM Table1</udc:Query>
 </udc:SelectCommand>
</udc:ConnectionInfo>


3. SharePoint list query
<udc:ConnectionInfo Purpose=”ReadOnly”>
 <udc:SelectCommand>
  <udc:ListId>{8fe80d4c-2203-4fa3-a411-f57f2e8be459}</udc:ListId>
  <udc:WebUrl>http://someserver/sites/somesite</udc:WebUrl>
 </udc:SelectCommand>
</udc:ConnectionInfo>

4. SharePoint library submit
The FolderName element specifies the default folder name that is used to prepopulate the data connection wizard.  Form designers will still need to specify the file name, as it is stored in the form template.


<udc:ConnectionInfo Purpose=”WriteOnly”>
 <udc:UpdateCommand>
  <udc:FileName>ExpenseReport.xml<udc:FileName>
  <udc:FolderName AllowOverwrite=”true”>
   http://someserver/sites/somesite/somelibrary
  </udc:FolderName>
 </udc:UpdateCommand>
</udc:ConnectionInfo>

5. XML file query
<udc:ConnectionInfo Purpose=”ReadOnly”>
 <udc:SelectCommand>
  <udc:Query>http://someserver/somefile.aspx</udc:Query>
 </udc:SelectCommand>
</udc:ConnectionInfo>


6. HTTP Post
<udc:ConnectionInfo Purpose=”WriteOnly”>
 <udc:UpdateCommand>
  <udc:Submit>http://someserver/somefile.aspx</udc:Submit>
 </udc:UpdateCommand>
</udc:ConnectionInfo>


Authentication

I’ve described the contents of the Authentication element in previous blog posts, so I won’t go into a detailed explanation. Two things are important here:
1. The Authentication element must be the last child of ConnectionInfo
2. If both SSO and UseExplicit are specified, Forms Services will use the credentials specified in the SSO element and will ignore the UseExplicit element.
This section is used only for forms running in the browser – InfoPath always ignores the authentication element.


<udc:Authentication>
 <udc:UseExplicit CredentialType="">
  <udc:UserId/>
  <udc:Password/>
 </udc:UseExplicit>
 <udc:SSO AppId="" CredentialType=""/>
</udc:Authentication>


The Universal Data Connection 2.0 schema

Download the XSD from here.

How to create and Manage UDC files

Today I am going to cover about How to Create and Manage UDC(Universal Data Connection) files which are very important in real world infopath applications using external connections. I have looked lot of places but no single article gives you all the details that are required about How to create and manage UDC files.
Note: We will use DCL for Data Connection Library.

To create UDC file you need to follow the steps.

1. Create a Data Connection Library in your sharepoint site.Let's say the url of DCL is http://servername:123/DLClib1
2. Create a Data Connection the normal way in infopath first.
3. Then Click on convert button 



4. It will ask you to give the URL of your DCL. Type the URL of your DCL and name of udcx file like http://servername:123/DLClib1/birthdays.udcx
5.You are still not done. If you check your DCL now it will have one record which will be checked out and you won't be able to check it in and then approve it. So you need to download this file from DCL on your machine and then upload it again into DCL and then approve it.
6. Once you are done with this, If you want to manage the udcx file from central admin then you need to upload the same udcx file in central administration and then in dataconnection you have to chagne to pick up the udcx settings from central admin.


References:
Ref1

Ref2

Ref3

Ref4

VS2008 IDE TO USE CUSTOM XSD FROM CACHE

on Wednesday, October 21, 2009


How to configure the Visual Studio 2005 IDE to use custom XSD files for IntelliSense


I've finally gotten some time to experiment with some of the features of the Visual Studio 2005 IDE (as you can see from my post last week about how to populate the Add References dialog).  I wanted to share a couple of tricks I discovered about using Visual Studio 2005 to create and edit XML that I found pretty useful, but for which the documentation was either vague or lacking (in my opinion).
I have been trying to install or register an XSD file so that Visual Studio 2005 can find it and automatically use it when I am editing specific types of XML documents in the IDE.  Initially, I expected that there would be a simple registry-based solution to associate new XSDs like there is for populating folders with assemblies into the Add References dialog.  After some research, I couldn't find a way to do this so I began looking for what kind of other options are available.
I found an MSDN document that describes what is new in code editing in VS 2005.  This document describes some of the features of the new XML editor in the IDE.  I was specifically interested in "Flexible schema association" and "XSD-based IntelliSense" so I tried to find more information about these topics.  I ended up finding this topic about the schema cache.  Based on this document, I was able to get the following mechanisms to work to cause Visual Studio 2005 to recognize my XSD:
Option 1 - copy the XSD into the Visual Studio 2005 schemas directory
  • Place a copy of the XSD file into the folder %ProgramFiles%\Microsoft Visual Studio 9.0\XML\Schemas
I also decided to associate a file extension for my file type with Visual Studio 2005.  If you are using a well-known file extension you may not need to use these additional steps.
  • Go to the Tools menu and choose Options
  • If you are using a Visual Studio 2005 Express Edition, check the box in the lower left corner named Show all settings
  • Expand the Text Editor tree item and choose File Extension
  • Type the name of your extension, choose XML Editor in the dropdown and click OK
This option worked fine for me, but required that I copy my XSD into the Visual Studio 2005 schemas directory.
Option 2 - modify the Visual Studio 2005 schemas catalog.xml file
  • Edit %ProgramFiles%\Microsoft Visual Studio 9.0\XML\Schemas\catalog.xml and add a new section that looks like the following:
    <Schema href="(path to your XSD file)" targetNamespace="(your schema namespace)" />
Because I also wanted to associate a file extension for my file type with Visual Studio 2005, I added this line to catalog.xml as well.  If you are using a well-known file extension you may not need to add this additional entry.
<Association extension="(your extension)" schema="(path to your XSD file)"/>
This option allowed me to store my XSD file in whatever location I wanted to, but had the drawback of requiring me to edit one of the configuration files that ships with Visual Studio 2005.
Option 3 - add a new XML file to the Visual Studio 2005 schemas directory
I could not find this option documented on MSDN, but I discovered it by asking some questions of the team that developed the XML Editor features in Visual Studio 2005.  I wanted to be able to register my schema without requiring my XSD file to be in the central Visual Studio 2005 schemas directory and without requiring any modifications to the catalog.xml file that shipped with Visual Studio 2005.  I found out that Visual Studio 2005 will parse files named *.xml in %ProgramFiles%\Microsoft Visual Studio 9.0\XML\Schemas and look for additional schema registration, even if the file is not named catalog.xml.
So in this option, I did the following:
  • Create a new file named myschema.xml
  • Add the following lines to the XML file:
    <Schema href="(path to your XSD file)" targetNamespace="(your schema namespace)" />
    <Association extension="(your extension)" schema="(path to your XSD file)"/>


  • Copy the file to %ProgramFiles%\Microsoft Visual Studio 9.0\XML\Schemas
This option allowed me to store my XSD file in whatever location I wanted to, and it did not require me to to edit one of the configuration files that ships with Visual Studio 2005.  This is the option I ended up choosing for my scenario.
Additional notes
A few other notes about this process that I found while trying to figure this out:
  • The MSDN documentation claims that Visual Studio monitors the %ProgramFiles%\Microsoft Visual Studio 9.0\XML\Schemas directory when the IDE is running and will dynamically update if any changes are made.  I may have been doing something wrong, but I could not get that feature to work and I had to close and reopen the IDE in order to see the changes I made to the contents of the Schemas directory get picked up and used by Visual Studio
  • The MSDN documentation also claims you can add a new <catalog> entry in %ProgramFiles%\Microsoft Visual Studio 9.0\XML\Schemas\catalog.xml in order to add new directories that Visual Studio will look in to try to find XSD files.  I could not get that functionality to work either, but I feel that option 3 listed above is cleaner anyways because you don't have to edit a pre-existing XML file (which makes it easier to write a setup that will register a schema with Visual Studio because Windows Installer does not have native support for editing XML files and you would have to write a custom action to do this)
Also, the coolest thing I discovered while looking into this is that any annotations in your XSD will be picked up and used by Visual Studio 2005 as IntelliSense comments.  That means when you type an open angle bracket to start a tag, and you get the dropdown with a list of applicable tags, when you give focus to each tag VS will display tooltips for the tag based on the annotations in the XSD file.  This is mentioned very briefly in this MSDN article, but I found this to be extremely useful - once I found out that I could easily enable this feature, I didn't need to Alt+Tab back and forth to the help documentation for my schema nearly as often.  Very cool!!

Populate DropDownList using code - InfoPath

Problem

You have a drop-down list box in InfoPath, which you would like to dynamically populate (=fill) through code with items from an
XML document.

Solution

Bind the drop-down list box to a repeating node in either the Main or a secondary data source
of the InfoPath form
, and then loop through the nodes in the XML document to populate the data source that is bound to
the drop-down list box with the data from the XML document.



Discussion

A drop-down list box in InfoPath consists of:

  1. A field in which to store the value of the item that is selected from the drop-down list box. This is the field that you drag-and-drop onto the InfoPath form and
    which represents the drop-down list box.
  2. A repeating node in the Main or a secondary data source, which the drop-down list box is bound to, and
    which contains the items to display in the drop-down list box.
Thus populating a drop-down list box in InfoPath means populating the data source the drop-down list box has been bound to
instead of setting the value of the drop-down list box. The latter will set the selected value on the drop-down list box
instead of filling the drop-down list box with items.
This is an important concept to understand when using list boxes in InfoPath and wanting to fill them programmatically
with items.
You can accomplish this functionality as follows:
  1. Open Microsoft Office InfoPath 2007, create a new blank form, and add a Drop-Down List Box
    to the form (also see: Insert a drop-down list box). Your form should resemble the following figure:


    The InfoPath form template in Design mode

    Figure 1. The InfoPath form template in Design mode.

  2. Create an XML file with the following content:


    <?xml version="1.0" encoding="UTF-8" ?>
    <lists>
    <list><title/></list>
    <list>
    <title/></list>
    </lists>



    This XML file will serve as a secondary data source that will contain the items for the drop-down list box, so create
    a Receive data connection to an XML document for this XML file, and bind
    the Drop-Down List Box to the data connection you created
    (also see: Working with the data source and data connections).
    Note: The XML file contains two list nodes instead of one. This is necessary for
    InfoPath to recognize the list node as a repeating node. One of these
    nodes will be deleted later through code before populating the drop-down list box. The remaining node will
    be copied repeatedly to create the items for the drop-down list box.


    Binding the drop-down list box to a secondary data source

    Figure 2. Binding the drop-down list box to a secondary data source.

  3. Create an XML document and add a Receive data connection for this XML document
    to the InfoPath form template. You will use this secondary data source to populate the secondary data source that
    is bound to the drop-down list box, so that the content of this XML document will show up as items in the drop-down
    list box. Note: You are not required to use an XML document to populate the drop-down list box, but could use any
    other type of data source or file that contains rows of data, which can be loaded into InfoPath, looped through,
    and used to populate
    the secondary data source that is bound to the drop-down list box.

  4. Add the following code to the Loading event handler of the form:


    C#
    RemoveFirstItem();
    XPathNodeIterator players = DataSources["doclibs"].CreateNavigator().Select(
    "//player", NamespaceManager);
    foreach (XPathNavigator player in players)
    {
    string title = player.SelectSingleNode("title", NamespaceManager).Value;

    AddItem(title);
    }






  5. Add the following code for the RemoveFirstItem and AddItem methods to the form's code.
    The RemoveFirstItem method removes one of the list nodes from the secondary data source that is bound to
    the drop-down list box (see note in step 2). The AddItem method adds an item to the secondary data source
    that is bound to the drop-down list box, thereby filling the title.
    for each item that will appear in the drop-down list box.


    C#

    private void AddItem(string title)
            {
                XPathNavigator nav = this.DataSources["doclibs"].CreateNavigator();
                XPathNavigator group1 = nav.SelectSingleNode("/lists", NamespaceManager);
                XPathNavigator node = group1.SelectSingleNode("list", this.NamespaceManager);
                XPathNavigator newNode = node.Clone();
                newNode.SelectSingleNode("title").SetValue(title);
                group1.AppendChild(newNode);

            }
            private void RemoveFirstItem()
            {
                XPathNavigator firstNode = this.DataSources["doclibs"].CreateNavigator().SelectSingleNode("/lists/list", this.NamespaceManager);
                firstNode.DeleteSelf();
            }




  6. Save your work, build the project, and test the form.

You should now have a fully functional InfoPath form so that once the form loads, the items from the XML document
will appear as items in the drop-down list box.

WebSite vs Virtual Directory vs Web Application

WebSite- each web site can have different IPAddress ,Port as well as host headers. So suppose a website url is http://www.abc.com:111

Virtual Application - Each virtual application can have their own application pool. So it is like separating process boundries and make sure that it doesn't interfere with other virtual applications. They fall under a website so all the virtual applications under a perticular website will have same ipaddress and port. So all virual application will have the URLs like http://www.abc.com:111/app1  , http://www.abc.com:111/app2.


Virtual Directory - You can convert any folder in IIS to virtual directory and virtual directory only has alias and a physical path mapping. All Virtual directories under the web site will have the URLs like http://www.abc.com:111/virdir 



Enable Remote Connections in SQL Server 2008

on Tuesday, October 20, 2009

To allow access to users in a Windows domain

  1. Open the SQL Server Management Tool.
  2. Log in to the machine. This step presumes that you are the administrator of the computer and the SQL Server installation.
  3. In the Object Explorer window, expand the Security node.
  4. Right-click Logins and click New Login....
  5. Type in the name of the user to allow using the domain\username format.
  6. Click Search and use the dialog to confirm that the user is a Windows authenticated user. Then close the New Login dialog.
  7. In the Object Explorer pane, expand the Databases node.
  8. Expand the node of the database you want to grant access to.
  9. Expand the Security node of the database.
  10. Right-click the Users node and click New User.
  11. In the User name box, type in any name you want for the user.
  12. In the Login name box, type the name of the user using the domain\username format.
  13. In the Role Members list box, check the box of the role you want to grant the user for the database. Common options are db_dataread and db_datawriter.

Enable a Port

This is a one-time procedure that is performed on the computer hosting the SQL Server installation. You must instruct the computer to allow access to the machine through a specific port. The default set by SQL Server is 1433. If you change the default, follow the directions below and change the port number as appropriate.

To enable port 1433

  1. On the Start menu, click Control Panel.
  2. Under Security, click Allow a program through Windows Firewall.
    Dd857537.note(en-us,VS.85).gifNote:
    Alternatively, click Start, and in the Search box type Windows Firewall. If two versions appear, select the simpler version (that is "Windows Firewall" and not "Windows Firewall with Advanced Security." In the dialog box, click Allow a program through Windows Firewall.

  3. If prompted, click Continue. This presumes you are the administrator of the computer.
  4. In the Windows Firewall Settings dialog box, click the Add Port button.
  5. In the Name box, type a name, such as "SQL Server Port".
  6. In the Port number box, type 1433. Use the default protocol TCP.
  7. Click OK.

Start sql server browser service



Restart the SQL Server Service

Set a Protocol

This is also a one-time procedure performed on the computer hosting SQL Server. You must instruct SQL Server about which protocol to use when communicating with remote clients. This procedure uses the TCP/IP protocol.

To set the protocol

  1. Open the SQL Server Configuration Manager application. This is found in the Configuration Tools folder of the Microsoft SQL Server 2008 folder.
  2. Expand the SQL Server Network Configuration node.
  3. Click Protocols for MSSQLSERVER.
  4. If the Named Pipes Status is set to Disabled:
    1. Double-click the Named Pipes row.

    2. Set the Enabled property to Yes and click OK.

  5. To stop and restart SQL Server:
    1. Open the SQL Server Management Studio application.

    2. Log into the computer. This presumes you are the administrator of the computer and the SQL Server installation.

    3. In the Object Explorer window, right-click the topmost node (by default, it is the name of the computer with a SQL Server version and other information) and click Restart.

  6. If the TCP/IP Status is set to Disabled:
    1. Double-click the TCP/IP row.

    2. Set the Enabled property to Yes and click OK.

CSS Styles for tags,classes, id selectors

Style1

If you want to style the entire body in a perticular way you would define it like

body
{
font-size:xx-large;
background-color:Black;
color:Aqua;
}

Style2

If you want to style using perticular class name then you would put "DOT(.)" before the name like
.classname
{
font-size:xx-large;
background-color:Black;
color:Aqua;
}

Style3

If you want to style using perticular element having a specific id then you would do something like

a#abc
{
font-size:xx-large;
background-color:Black;
color:Aqua;
}
<a runat="server" id="abc">hello</a>

Style4

If you want to style a specific id then you would do something like

#abc
{
font-size:xx-large;
background-color:Black;
color:Aqua;
}
which will make all the elements with id abc use the above style.