Tuesday, 23 August 2011

Inheritance and Polymorphism tips


The following example is demonstrated in C#

I have classB inherites from classA as following:

    class Program
    {
        static void Main(string[] args)
        {
            classB b = new classB();
            classA a = b as classA;
            a.DoSomething();
            b.DoSomething();

            classB b2 = a as classB;
            b2.DoSomethingElse();
        }
        public class classA
        {
            protected string s = "hello from classA";

            public classA()
            {
                s = "hello from classA";
            }

            public void DoSomething()
            {
                Console.WriteLine(s);
            }
        }
        public class classB : classA
        {
            protected string d = "something else";

            public classB()
            {
                s = "hello from classB";
            }
            public void DoSomethingElse()
            {
                Console.WriteLine(d);
            }
        }
    }

The derived class - classB gains all the non-private data and behavior of the base class (classA) in addition to any other data or behaviors it defines for itself. classB is effectively both classB and classA (polymorphism).

When the program is run, both a.DoSomething() and b.DoSomething() output "hello from classB" to the Console, because when creating classB object, the Constructor of classA will be called before the Constructor of classB is called, so the value of s is "hello from classB".

When classB is cast to classA, classB is not changed by the cast, but the view of classB becomes restricted to classA's data and behavior. After casting classB to classA, that classA can be cast back to classB without losing the data. So when b2.DoSomethingElse() is invoked, it will output "something else"

Monday, 15 August 2011

Create InfoPath 2007 form and submit to SharePoint 2007


You should have InfoPath 2007 and SharePoint 2007 Standard or Enterprise installed and set up properly

1. Create an InfoPath Form Library in SharePoint 2007

Navigate to your top-level site collection, and then
Site Action | Create | Library | Form Library, name it as "InfoPathFormLibrary", note that
Document Template is Microsoft Office InfoPath form

2. InfoPathFormLibrary Settings | Form Library Settings | Advanced settings | Browser-enabled Documents | Display as a web page | OK

3. Enable InfoPath browser form features in SharePoint 2007

Site Actions | Site Settings | Site Collection Administration | Site Collection features

For SharePoint Enterprise edition, activate Office SharePoint Server Enterprise Site Collection features (Features include business data catalog, forms services, and Excel Services)

For SharePoint Standard edition, activate InfoPath Forms Services support

4. Configure InfoPath Forms Services

Central Administration | Application Management | InfoPath Forms Services | Configure InfoPath Forms Services

In the section of [User Browser-enabled Form Templates], select both Allow users to browser-enabled form templates and Render form  templates that are browser-enabled by users, and click OK to save it.

5. Create a browser-compatible form template in InfoPath and publish to SharePoint 2007

Design a blank Form Template in InfoPath, and enable browser-compatible features



Layout | Table with title

Change the title to Customers, add a 2x2 table under Customers, it has two labels at the left column: Name and Address.  Two TextBox at the right column.


6. Double click Name TextBox, and set Field name as name
Double click Address TextBox, and set Field name as address


7. Set submit options

Tools | Submit Options


Click Add to create data connection for submit. Follow the Data Connection Wizard.


my Document libary is: http://vm2/InfoPathFormLibrary
File name is the result of a function: concat("form",now()), you can click Fx button to build the function


Choose Allow overwrite if file exists
When you have completed the Data connection wizard and returned to the Submit Options window, click Advanced button, and choose Close the form after submit.


8. Set Form Options

Tools | Form Options...
Uncheck Show toolbar at bottom of from and click OK to save


9. Save this template
Click Save icon, name it as CustomerFormTemplate.xsn and save it in My Documents folder

10. Publish the templage
File | Publish, it invokes Publishing Wizard





On the following screen, do not click Add, click Next to go to Next step

Click Publish on the following screen


Close the wizard when success


11. Test the InfoPath form

Close InfoPath 2007.
Return to your site collection, click InfoPathFormLibrary at the quick launch.

New | New Document
you will see the InfoPath form in your browser


Submit the form when you're done.


12. You should be able to see it in the InfoPathFormLibrary

Monday, 8 August 2011

Create and publish Infopath Form to SharePoint 2010


Environment:
SharePoint 2010
InfoPath 2010

1. Navigate to the top level site and create a Custom List
Click 'Lists' from quick launch, then 'Create', name it as 'Customers'

















and then go to List Tools | List and create three columns as 'Contact Name', 'Email' and 'Phone Number', make all of the fields 'Single line of text'


2. Open InfoPath Designer 2010, double-click the SharePoint List template. In the Data Connection Wizard, enter the URL of your top level site. For example, the URL I am using is:

http://win-4me5lbbsmh5/SitePages/Home.aspx

If the URL provide is not top level site, my experience is that InfoPath cannot establish the connection.




3. Click 'Next', choose 'Customize an existing SharePoint list', select 'Customers' and then click 'Next'



4. When finish, Infopath generates a form that maps to the fields of Customers list, you can do some customization and preview the changes you made, and then publish it to SharePoint by click the Quick Publish button (next to the Save icon at the top left of InfoPath)


5. To use the form in SharePoint, navigate to your sharepoint site and choose 'Edit Page' from 'Site Actions'

6. The Infopath Form will be display on the sharepoint page as a webpart. Click on the page at where you want the webpart being rendered. Then click Editing Tools | Insert | Web Part, select Forms in the Categories, InfoPath Form Web Part, and then click Add button to add the InfoPath Form webpart.

7. Select a Form. Click here to open the tool pane. In the 'List or Library' dropdown, select 'Customers' and click OK, you will see the InfoPath form on the page.


8. To use the InfoPath Form, click the Forms Edit Tab, fill out the form and click Save.

9. To see the data you just entered and saved. Go to Home, click Customers from quick launch.