设为首页 收藏本站
查看: 1053|回复: 0

[经验分享] 从 InfoPath 2010 表单打开 SharePoint 2010 模式对话框

[复制链接]

尚未签到

发表于 2015-9-26 10:51:07 | 显示全部楼层 |阅读模式
  效果图:
DSC0000.png
  源码下载地址:http://files.cnblogs.com/love007/RibbonDemo.rar

添加测试页面
  1. 在 Visual Studio 2010 中,创建新项目。
  2. 在“新建项目”对话框中,选择“SharePoint 2010”和“空白 SharePoint 项目”模板。
  3. 将项目命名为MyTest,然后单击“确定”。
DSC0001.jpg
  4. 在“SharePoint 自定义向导”中,单击“部署为场解决方案”。然后单击“完成”。
DSC0002.png
  5. 在“解决方案资源管理器”中,右键单击项目节点,指向“添加”,然后单击“新项”。
  6. 在“添加新项”对话框中,选择“应用程序页”模板。将页面命名为 ModalHost.aspx,然后单击“添加”。
DSC0003.jpg
  7. 在 ModalHost.aspx 应用程序页标记中,查找 ContentPlaceHolderID="PlaceHolderMain"。将光标放置在 </asp:Content>结束标记上方的空行中。然后,复制以下标记并将它粘贴到插入点。
DSC0004.jpg


  • 在“解决方案资源管理器”中的“布局”文件夹下,右键单击“MyTest”文件夹,指向“添加”,然后单击“新文件夹”。将新文件夹命名为 scripts。
DSC0005.png


  • 右键单击“scripts”文件夹,指向“添加”,然后单击“现有项”。导航到下载的 jquery-1.7.2.min.js 文件,然后单击“添加”。
DSC0006.png


  • 右键单击“scripts”文件夹,指向“添加”,然后单击“新项”。选择“Visual C#”,然后单击“常规”。选择“文本文件”模板,并将文件命名为 ModalHost.js。然后单击“添加”。
  • 复制以下代码并将它粘贴到 ModalHost.js。
  // When invoked open the modal dialog box.
  // We will call this function from the Web Parts page.
  function popupmodalui(url) {
  // Set the required properties.
  var options = { autoSize: true,
  title: "Search documents",
  showClose: true,
  allowMaximize: true
  };
  // Pop up the application page in the modal dialog box,
  // and pass the site URL as a query string to the application page.
  SP.UI.ModalDialog.commonModalDialogOpen("../_layouts/MyTest/ModalHost.aspx?url="
  + url,
  options, closecallback, null);
  }
  // Executes when the modal dialog box is closed.
  // This function runs in the context of the Web Part's page.
  function closecallback(result, value) {
  // Determine whether the OK button was clicked.
  if (result === SP.UI.DialogResult.OK) {
  }
  }
DSC0007.jpg

设计Infopath表单页


  • 在 InfoPath Designer 2010 中,单击“文件”选项卡,然后单击“新建”。
  • 在“可用表单模板”下,选择“空白表单”。然后单击“设计表单”。
DSC0008.jpg


  • 单击“单击此处添加标题”,然后键入“测试“
  • 添加button按钮如下
DSC0009.jpg

为按钮单击事件添加处理程


  • 在 InfoPath Designer 中,单击“开发工具”选项卡,然后单击“语言”。
  • 在“表单选项”对话框中的“表单模板代码语言”下,选择“C#”,然后单击“确定”。
DSC00010.jpg


  • 在“开发工具”选项卡上,单击“代码编辑器”以启动 Microsoft Visual Studio Tools for Applications。
  注意:如果出现错误,则按照如下操作进行配置
DSC00011.jpg
  附:安装VSTA插件
  运行office2010安装文件如下
DSC00012.jpg
DSC00013.jpg
DSC00014.jpg
DSC00015.jpg


  • 在 InfoPath Designer 中,在表单设计图面上,选择“搜索”(Search) 按钮。在功能区上,单击“属性”选项卡。单击“自定义代码”以便为按钮生成单击事件处理程序。
DSC00016.jpg
DSC00017.jpg
  输入代码NotifyHost("测试");保存关闭窗口

发布infopath表单


  • 在 InfoPath Designer 中,单击“文件”选项卡。
  • 在操作列中,单击“发布”,然后单击“SharePoint Server”,如图 15 所示。
DSC00018.jpg


  • 在“发布向导”中,键入目标 SharePoint 网站的 URL,然后单击“下一步”。
DSC00019.jpg


  • 确认“使用户可以通过浏览器填写此表单”复选框处于选中状态,并且选择了“表单库”,如图 16 所示。
DSC00020.jpg
  表单库访问地址为:http://moss:8001/InfopathList/Forms/template.xsn

创建自定义 Web 部件


  • 在 Visual Studio 中,打开“MyTest”解决方案。
  • 在“解决方案资源管理器”中,右键单击解决方案节点,指向“添加”,然后单击“新项目”。依次选择“SharePoint”、“2010”和“空白项目”。将项目命名为 ModalHost.WebParts。单击“确定”。
  将显示 SharePoint“自定义向导”。
DSC00021.jpg


  • 选择“部署为场解决方案”,然后单击“完成”。
  • 在“解决方案资源管理器”中,右键单击“ModalHost.WebParts”项目节点,指向“添加”,然后单击“新项”。依次选择“SharePoint”、“2010”和“Web 部件”。将 Web 部件命名为 InfoPathFormHost,然后单击“确定”。
DSC00022.jpg


  • 在“ModalHost.WebParts”项目中,通过浏览到 <驱动器号>:\Program Files\Microsoft Office Servers\14.0\Bin 文件夹添加对 Microsoft.Office.InfoPath.Server.dll 的引用。
DSC00023.png
  如果 Visual Studio 显示一条警告消息,请单击“是”以继续向项目添加引用。
DSC00024.png
DSC00025.png


  • 在 InfoPathFormHost.css 的顶部,添加以下 using 语句:
  using Microsoft.Office.InfoPath.Server.Controls;
  using System.Text;
DSC00026.png
  代码如下:



using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.Office.InfoPath.Server.Controls;
using System.Text;
namespace ModalHost.WebParts.InfoPathFormHost
{
[ToolboxItemAttribute(false)]
public class InfoPathFormHost : WebPart
{
// XmlFormView control object to render the browser-enabled InfoPath form.
private XmlFormView xmlFormView = null;
// Field to hold the return value from the modal dialog box.
private TextBox hiddenText = null;
private string receivedValue = null;
// Property to store the InfoPath XSN URL.
[WebBrowsable(true)]
[WebDisplayName("Form XSN URL")]
[Description("Relative URL of the InfoPath XSN file.")]
[Category("Configurations")]
[Personalizable(PersonalizationScope.Shared)]
public string FormXSNURL { get; set; }
/// <summary>
/// 注册外部脚本文件        
        /// </summary>
/// <param name="e"></param>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Register scripts to load and display the modal dialog box.
ScriptLink.Register(this.Page, "MyTest/scripts/jquery-1.7.2.min.js", false);
ScriptLink.Register(this.Page, "MyTest/scripts/ModalHost.js", false);
}
/// <summary>
/// CreateChildControls
/// </summary>
protected override void CreateChildControls()
{
try
{
base.CreateChildControls();
// Instantiate the XMlFormView object.
this.xmlFormView = new XmlFormView();
// Set the editing status to init on initial load.
this.xmlFormView.EditingStatus = XmlFormView.EditingState.Init;
// Add to the Web Part controls collection.
this.Controls.Add(this.xmlFormView);
// Add a handler for the NotifyHost event.
//为a NotifyHost
                this.xmlFormView.NotifyHost += new EventHandler<NotifyHostEventArgs>(xmlFormView_NotifyHost);

}
catch
{
throw;
}
}
/// <summary>
/// 此代码覆盖 OnPreRender() 事件处理程序,以将 XmlFormView 控件配置为托管 Web 部件的 FormXSNURL 属性指向的 InfoPath 表单,并将控件的 EditingStatus 属性设置为 Editing。这样做使 XMLFormView 控件可以访问 InfoPath 表单的基础 XML 数据源。        /// </summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
try
{
// Determine whether the user has set the FormXSNURL property with InfoPath XSN location.
if (!string.IsNullOrEmpty(this.FormXSNURL))
{
// Configure the XmlFormView control to host the form.
this.xmlFormView.XsnLocation = this.FormXSNURL;
// Set the editing status to ensure the control displays the form.
this.xmlFormView.EditingStatus = XmlFormView.EditingState.Editing;
}
}
catch
{
throw;
}
}
// Handles the event that is raised when the button
// in the InfoPath form is clicked.
/// <summary>
/// 按钮事件
        /// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void xmlFormView_NotifyHost(object sender, NotifyHostEventArgs e)
{
try
{
// Check if the argument contains the XPath.
if (!string.IsNullOrEmpty(e.Notification))
{

// Construct a JavaScript function to invoke the modal dialog box.
StringBuilder functionSyntax = new StringBuilder();
functionSyntax.AppendLine("function popupparams() {");
// Pass the current SharePoint web URL as an argument.
functionSyntax.AppendLine("var url ='" + SPContext.Current.Web.Url + "';");
// Call the JavaScript function to pop up the modal dialog box.
functionSyntax.AppendLine("popupmodalui(url);}");
// Ensure the function popupparams is called after the UI is finished loading.
functionSyntax.AppendLine("_spBodyOnLoadFunctionNames.push('popupparams');");
// Register the script on the page.
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "ModalHostScript", functionSyntax.ToString(), true);
}
}
catch
{
throw;
}
}


}
}

  
  最后效果图:
DSC00027.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-119008-1-1.html 上篇帖子: Some Articles About Creating SharePoint Webparts. 下篇帖子: SharePoint Server 2016 Update
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表