Sunday, June 21, 2009

Submit InfoPath Form To Sharepoint (C#)

I would like to share this approach, because the most of people think, that the using of InfoPath forms in Sharepoint solutions is difficult for implementation and maintenance! I wish to show how the developers can use InfoPath Forms Server rendering engine as user interface for their applications!

Downloads:

The Visual Studio Project (using VSeWSS 1.3 CTP)

The form template:

Step 1: Create the form template:

1. Open InfoPath 2007 and choose to design a blank form template

image 

2. Select Tools –> Form Options and:

  • On “Compatibility” section check “Design a form template that can be opened in a browser or InfoPath”

image

  • On “Security and Trust” section uncheck “Automatically determine security level” and select “Domain”

image

3. Design the form: add layout elements, labels and controls

image

4. Configure the “Button control” actions:

  • Right click and select “Button Properties”

image

  • From Actions combo box select “Submit”

image

  • Open “Submit Options” and check “Allow user to submit this form”; select the radio button “Perform custom actions using Rules”

image 

  • Add new rule and action for it

image

  • Configure a new Submit connection

image

image

image

  • Finalize the rule configuration

image

image

image

5. Check for errors your form

image

6. Save the for as .xsn file on your local drive and open publishing wizard from File –> Publish

7. Follow the publishing steps below:

image

  • Type the URL of DSharepoint site, where InfoPath Form Services are available

image

  • Choose the last option

image

  • Specify the location, where to store the published form

image

  • Finalize the steps of publishing wizard

8. Open Sharepoint Central Administration site and navigate to Application Management -> Manage Form Templates; open “Upload Form Template” page; Browse to the location where the published form has been stored and upload it!

image

9. When the status of the form become “Ready” activate it for the preferred site collection

ip-approve

ip-approve-sc

10. As result you can find the activated form in “FormServerTemplates” library in the site collection

image

 

Step 2: Create the Visual Studio project

I’m using Visual Studio 2008 with installed VSeWSS 1.3 CTP (March 2009)

1. Create a new project, using “Web Part” template; choose “Full trust” deployment type

image

image

2. in the new project add references to these assemblies:

C:\Program Files\Microsoft Office\Office12\Microsoft.Office.Infopath.dll

C:\Program Files\Microsoft Office Servers\12.0\Bin\Microsoft.Office.InfoPath.Server.dll

image

3. Change the default name of the web part with any human readable :)

image

image

image

4. Change the target URL where you want to deploy your web part – right click on the project name and select “Properties; open debug section and change the value of “Start browser with URL”

image

5. In the .cs file of your web part add using clauses for

using Microsoft.Office.InfoPath.Server.Controls;
using System.Xml.XPath;
using System.Xml;

6. Declare the instance of XmlFormView

protected XmlFormView formView = null;


7. Instantiate the XmlFormView and add it to the web part’s controls collection



protected override void CreateChildControls()

{


    base.CreateChildControls();



    formView = new XmlFormView();

    formView.Width = System.Web.UI.WebControls.Unit.Percentage(100);


    this.Controls.Add(formView);


}



8. Override “Prerender” event of the web part; set the URL to the activated form and subscribe the instance of XmlFormView to SbmitToHost event




protected override void OnPreRender(EventArgs e)

{


    base.OnPreRender(e);



    formView.XsnLocation = "http://vm-moss-01/FormServerTemplates/Request.xsn";


    formView.ShowHeader = false;


    formView.ShowFooter = false;



    formView.EditingStatus = XmlFormView.EditingState.Editing;

    formView.SubmitToHost += new EventHandler<SubmitToHostEventArgs>(formView_SubmitToHost);



}



void formView_SubmitToHost(object sender, SubmitToHostEventArgs e)

{


    try


    {


        XPathNavigator xNavMain = formView.XmlForm.MainDataSource.CreateNavigator();


        XmlNamespaceManager manager = formView.XmlForm.NamespaceManager;



        string formContent = xNavMain.OuterXml;



    }

    catch(Exception ex)


    {


        throw new ApplicationException("RequestForm Exception", ex);


    }


}




Get the whole C# file





9. Right click on the project name and select Deploy. This functionality is avalable from VSeWSS!



vsewss-deploy



Step 3: Deployment and debugging



1. Create new page in your Sharepoint site and choose any template with web part zones :)



image



2. Open the dialog for adding of new web part



image



3. Navigate to Miscellaneous section, where you will find your new created web part; select it and click “Add” button below



image



4. The web part will show the Request Form on the page; publish the page



image



5. Switch to Visual Studio; right click on the project name; select Quick Deploy –> Attach to IIS worker process



image


Saturday, June 13, 2009

Resolve Problems During Installation of VSeWSS 1.3 CTP

I had the following screen error when I tried to install Visual Studio extensions for Windows Sharepoint Services v1.3 CTP (March 2009)

Please wait while installer finishes determining your disk space requirements

image

The system was Windows Server 2008. I made preliminary configuration, according requirements, namely I created a local user account “vsewss”, with local administrator privileges as well as new application pool “VSeWSS” with Managed Pipeline Mode “Classic” and with service account “vsewss”.

After installation failure, I removed my application pool and created new one - “vsdev” with the same settings and started the setup again

app-pool

The result was better

image

Obviously, the problem was in the name of my application pool. I left the default and finished the installation. After that, I changed the application pool for new created site “VSeWSS” with “spdev”.

image

Finally, I tried to deploy a solution with Visual studio and the result was:

vs-error

The last thing, which was necessary here, was to add the user “vsewss” to Site Collection Administrators of the site, where I wanted to deploy my solution!

Microsoft Online Services Availability

This morning, I found this post about free Sharepoint master pages, and there are links to instructions how to install them to Microsoft Online Services! I never visited it before, therefore I decided to explore MOS portal and get a trial of Sharepoint online! … but… after short registration I found, that the only available services for Bulgaria is Live Meeting Pro… :)

image

Obviously, it is only for our region, because when I changed my location to United States, the picture was change

image

I’m not sure, when “Business Productivity Online” suite would be available for our region, but I’ll investigate this situation and share the result online!

:-)

Friday, June 12, 2009

Try to open SampleWorkbook.xlsx

I tried to open “SampleWorkbook.xlsx”, which is a part of OOB Reports center site with my Office 2010

image

And… here is the result

WTF…. :)

image