You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在InfoPath物资申请表单中显示SharePoint List关联附件的可行性问询

好问题!在InfoPath里给绑定SharePoint列表项的重复节添加附件显示完全是可行的,我整理了两种实操性强的方案,你可以根据自己的场景选:

方案1:用数据连接+规则实现(无代码)

这是最省心的方式,适合大多数普通场景:

  • 首先确认你已经和目标SharePoint列表建立了接收数据连接,设置时一定要勾选包含ID字段和附件相关的字段(InfoPath会自动识别列表的附件数据,别漏选)
  • 给重复节里的列表框加一个规则:当列表框的选中值变化时,触发「查询数据」动作,用当前选中项的ID作为筛选条件,从SharePoint列表数据连接中拉取对应项的附件
  • 在重复节里添加一个附件控件(如果要支持下载/查看)或者图片控件(如果是图片类附件),把控件的数据源绑定到查询回来的附件数据节点上
    • 小提示:如果列表项有多附件,得在附件控件外面再套一层重复节,才能显示所有附件哦
方案2:自定义代码实现(复杂场景)

如果规则满足不了你的特殊需求(比如要自定义附件展示样式),可以用C#/VB写InfoPath代码:

  • 给列表框的Changed事件绑定代码,通过SharePoint Client Object Model根据选中项的ID获取附件
  • 把获取到的附件信息(文件名、下载链接)写入表单的临时数据源,再绑定到表单控件上
  • 这里给你一段C#示例代码(记得替换成自己的站点和列表信息):
using Microsoft.Office.InfoPath;
using Microsoft.SharePoint.Client;
using System.IO;

public void listBox1_Changed(object sender, XmlEventArgs e)
{
    // 替换成你的SharePoint列表ID和站点URL
    string listId = "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
    string siteUrl = "https://your-sharepoint-site-url";
    
    // 获取当前选中列表项的ID
    XPathNavigator currentItemIdNode = this.MainDataSource.CreateNavigator()
        .SelectSingleNode("/my:myFields/my:repeatingSection/my:listBoxSelectedId", this.NamespaceManager);
    int itemId = int.Parse(currentItemIdNode.Value);
    
    using (ClientContext ctx = new ClientContext(siteUrl))
    {
        // 从SharePoint获取对应项的附件
        List targetList = ctx.Web.Lists.GetById(new Guid(listId));
        ListItem listItem = targetList.GetItemById(itemId);
        ctx.Load(listItem, i => i.AttachmentFiles);
        ctx.ExecuteQuery();
        
        // 清空当前重复节的旧附件数据
        XPathNavigator attachmentsContainer = this.MainDataSource.CreateNavigator()
            .SelectSingleNode("/my:myFields/my:repeatingSection/my:attachmentsList", this.NamespaceManager);
        attachmentsContainer.DeleteSelf();
        attachmentsContainer = this.MainDataSource.CreateNavigator()
            .SelectSingleNode("/my:myFields/my:repeatingSection", this.NamespaceManager)
            .AppendChild("<my:attachmentsList></my:attachmentsList>", this.NamespaceManager);
        
        // 把新附件写入表单数据源
        foreach (AttachmentFile attachment in listItem.AttachmentFiles)
        {
            XPathNavigator attachmentNode = attachmentsContainer.AppendChild("<my:attachment></my:attachment>", this.NamespaceManager);
            attachmentNode.AppendChildElement("my", "fileName", this.NamespaceManager, attachment.FileName);
            attachmentNode.AppendChildElement("my", "fileUrl", this.NamespaceManager, attachment.ServerRelativeUrl);
        }
    }
}
  • 写完代码后,在表单里加一个绑定到/my:myFields/my:repeatingSection/my:attachmentsList/my:attachment的重复节,里面放个超链接控件,绑定fileUrl字段,显示fileName字段就行
关键注意事项
  • 如果用自定义代码,要确保表单的安全设置允许代码运行,发布的时候选择合适的信任级别
  • 要是做的是浏览器表单,自定义代码可能受限制,优先考虑无代码方案
  • 测试的时候多试试多个重复节的情况,确保每个节的附件都是对应选中的列表项,别串了

内容的提问来源于stack exchange,提问作者hime-da-bimes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:15:27