Herman Cordes
Herman Cordes

Reputation: 4976

InfoPath library throws NotImplementedException for XmlFormView.XmlForm.SaveAs method

I'm using the XmlFormView in a SharePoint page to view InfoPath browser enabled forms and programmatically add some opening and saving logic.

All goes fine, without the XmlForm.SaveAs method. This method throws an NotImplementedException if I call it on an instantiated XmlForm and with a valid location, see code:

ASPX:

<InfoPath:XmlFormView ID="infoPathFormView" ShowHeader="false" Style="width: 100%;" runat="server" />

Code behind:

infoPathFormView.SaveLocation = "http://localhost/MyFormLibrary";
infoPathFormView.DataBind();

if(infoPathFormView.XmlForm.New)
{
   string fileName = Page.User.Identity.Name;
   infoPathFormView.XmlForm.SaveAs(fileName); // This line throws.
}
else
{
   infoPathFormView.XmlForm.Save();
}

Resulting in the following exception and stacktrace:

The method or operation is not implemented. at Microsoft.Office.InfoPath.Server.DocumentLifetime.XmlFormHost.SaveAs(String fileUrl) at MyProject.ShowInfoPathForm.SaveButton_Click(Object sender, EventArgs eventArguments)
at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

For clarity, I found that Microsoft.Office.InfoPath.Server.DocumentLifetime.XmlFormHost is an internal class that inherits from the abstract XmlForm class.

Thanks in advance!!

Upvotes: 1

Views: 641

Answers (2)

Alexei Levenkov
Alexei Levenkov

Reputation: 100545

Note that the SaveAs is not available for server forms as specified in the article you linked from the question: "This type or member can be accessed only from code running in forms opened in Microsoft Office InfoPath 2007."

Consider using SaveLocation ( http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.server.controls.xmlformview.savelocation.aspx) to specify file name in the same site collection as the template.

Upvotes: 0

ukhardy
ukhardy

Reputation: 2104

For security reasons, the XsnLocation, XmlLocation, and SaveLocation properties of the XmlFormView control must specify locations in the same site collection as the custom page.

Upvotes: 1

Related Questions