How to programmatically submit your form to document library?
First create a new data connection in Infotpath 2010 as a Submit and To a Document Library on a SharePoint site. Don't't worry in entering any SharePoint Server's url and destination document library, because this values can be overridden in code. Once you have created the new Data Connection, name it as SharePoint Library Submit.

Now add a simple button, and in the buttons propery windows select Action= Submit, press Submit Options and check Perform Custom action using Code and finally press Edit Code.

Add the following code in the FormEvents_Submit event
Reference: http://www.dev4side.com/community/technical-articles/sharepoint-2010/what-should-you-know-before-development-in-infopath-2010-.aspx