InfoPath库为XmlFormView.XmlForm.SaveAs方法抛出NotImplementedException

时间:2011-05-18 08:09:16

标签: c# .net sharepoint infopath xmlformview

我在SharePoint页面中使用XmlFormView来查看启用InfoPath浏览器的表单,并以编程方式添加一些打开和保存逻辑。

没有XmlForm.SaveAs方法,一切顺利。如果我在实例化的XmlForm上调用它并使用有效位置,则此方法抛出NotImplementedException,请参阅代码:

ASPX:

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

代码背后:

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();
}

导致以下异常和堆栈跟踪:

  

方法或操作不是   实现。在   Microsoft.Office.InfoPath.Server.DocumentLifetime.XmlFormHost.SaveAs(字符串   fileUrl)at   MyProject.ShowInfoPathForm.SaveButton_Click(对象   sender,EventArgs eventArguments)
  在   System.Web.UI.WebControls.LinkBut​​ton.OnClick(EventArgs的   吃   System.Web.UI.WebControls.LinkBut​​ton.RaisePostBackEvent(字符串   eventArgument)at   System.Web.UI.WebControls.LinkBut​​ton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串   eventArgument)at   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler   sourceControl,String eventArgument)
  在   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection中   postData)at   System.Web.UI.Page.ProcessRequestMain(布尔   includeStagesBeforeAsyncPoint,Boolean   includeStagesAfterAsyncPoint)

为清楚起见,我发现Microsoft.Office.InfoPath.Server.DocumentLifetime.XmlFormHost是一个继承自抽象XmlForm类的内部类。

  • 有没有人知道为什么这段代码会抛出NotImplementedException?
  • 是否有解决方法可以使用指定的文件名保存XmlForm?

提前致谢!!

2 个答案:

答案 0 :(得分:1)

出于安全原因,XmlFormView控件的XsnLocation,XmlLocation和 SaveLocation 属性必须在自定义页面的同一网站集中指定位置。

答案 1 :(得分:0)

请注意,SaveAs不适用于您从问题链接的文章中指定的服务器表单:“只能从在Microsoft Office InfoPath 2007中打开的表单中运行的代码访问此类型或成员。”

考虑使用SaveLocation(http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.server.controls.xmlformview.savelocation.aspx)在与模板相同的网站集中指定文件名。

相关问题