SharePoint: Using the SharePoint Object Model with InfoPath Form Code Behind Part 3 of 2


Like the Spanish Inquisition,

“Our chief weapon is surprise…surprise and fear…fear and surprise…. Our two weapons are fear and surprise…and ruthless efficiency……”

In part 1 of this 2 part series we created an InfoPath form which used the SharePoint Object Model in it’s code behind to create new Task list items.

In part 2 of this 2 part series we published this InfoPath form to SharePoint and hooked it into the SharePoint user interface by using a content editor web part to create an HTML link to the browser form.

In part 3 of this 2 part series I conducted  a small experiment to see how one could have this InfoPath form replace the default NewForm.aspx called when adding task list items.

If you were doing this in a production setting, you could quite easily specify the URL of a custom NewForm page called to add new list items, and there are plenty of articles available for custom list form pages.

For more infomation on understanding how SharePoint List form pages work, check out Hristo Pavlov’s excellent article.

In my experiment I simply edited the NewForm.aspx page of the Tasks list using SharePoint Designer, and inserted the following piece of JavaScript into the markup (line breaks added for clarity).

<script type="text/javascript" language="javascript">
	window.location='http://portal/_layouts/FormServer.aspx?
			XsnLocation=http://portal/FormServerTemplates/TestObjectModelForm.xsn
			&SaveLocation=http://portal/
			&Source=http://portal
			&DefaultItemOpen=1';</script>

Quite simply, the javascript does an instant redirect to the URL of our InfoPath form when the NewForm.aspx pages loads, surprisingly or not it works very nicely.

Possibly a handy technique for quick List form replacements, maybe even User Editable List forms (shudder :-)) ?????

About these ads

About Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 571 other followers

%d bloggers like this: