I am programmatically adding an InfoPath Form web part to a web part page. In my code I am setting the form location and some other properties. When the feature is activated, the web part is added to the page and the properties are set but the form doesn't show. The error on the web part page is "The Web Part cannot find an InfoPath form in the specified location. Either the location does not have an InfoPath form associated with it or it is on a different site collection. Modify the Web Part Properties and select a list or library on the current site." When I edit the web part and click apply, the form shows. Here is my code. After the method is called in the feature activation, I am doing a site.Update(). Any help would be appreciated. Thank you.
private void AddWebPartToPage(string pageName, SPWeb site, string reqLibName, string url)
{
SPFile page = site.GetFile(url + "/" + listTitle + "/" + certReqPageName);
SPLimitedWebPartManager manager = site.GetLimitedWebPartManager(url + "/" + listTitle + "/" + pageName, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
//create instance of InfoPath form webpart
Microsoft.Office.InfoPath.Server.Controls.WebUI.BrowserFormWebPart wp = new Microsoft.Office.InfoPath.Server.Controls.WebUI.BrowserFormWebPart();
//set webpart properties
wp.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;
wp.AllowClose = false;
wp.AllowHide = false;
wp.AllowMinimize = false;
//add webpart to page
manager.AddWebPart(wp, "Full Page", 0);
manager.SaveChanges(wp);
//set form location for CertReq webpart
wp.FormLocation = url + "/" + reqLibName;
manager.SaveChanges(wp);
page.Update();
}