提取Infopath表单附件到库 [英] Extract Infopath form attachment to Library

查看:103
本文介绍了提取Infopath表单附件到库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//此代码的目的是从信息表格中获取附件并将​​其添加到Sharepoint 2013库。



//我有代码下面但是我收到错误命名空间Sharepoint不存在。即使我已将它添加到引用中。



我相信这是因为我使用的是服务器对象模型,即使机器不是服务器。我试图将代码转换为客户端模型但仍然出现错误。例如我将SPSite更改为网站。



我还会收到警告:警告13无法解析主要参考Microsoft.SharePoint,因为它对框架程序集System.Workflow.Runtime,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35具有间接依赖性无法在当前目标框架中解决。.NETFramework,Version = v2.0。要解决此问题,请删除引用Microsoft.SharePoint或将应用程序重新定位到包含System.Workflow.Runtime,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35的框架版本。 C:\ Windows \ Macrosoft.NET \ Framework64 \v4.0.30319 \ Microsoft.Common.targets 1605 5 Form2





使用Microsoft.Office.InfoPath;

使用System;

使用System.Xml;

使用System.Xml.XPath;

使用Microsoft.SharePoint.Client;

使用Microsoft.SharePoint.Client.site;









名称空间Form2

{

公共部分类FormCode

{

//启用浏览器的表单不支持成员变量。

//而是从FormState写入和读取这些值

//使用以下代码的字典:

//

//私有对象_memberVariable

// {

// get

// {

//返回FormState [_ memberVariable];

//}

// set

// {

// FormState [_ memberVariable] = value;

//}

//}



//注意:Microsoft InfoPath需要以下过程。

//它可以使用Microsoft InfoPath进行修改。

public void InternalStartup()

{

((ButtonEvent)EventManager.ControlEvents [CTRL1_5])。 Clicked + = new ClickedEventHandler(CTRL1_5_Clicked);

}



public void CTRL1_5_Clicked(object sender,ClickedEventArgs e)

{

//在InfoPath表单中检索附件的值



XPathNavigator ipFormNav = MainDataSource.CreateNavigator();

XPathNavigator nodeNav = ipFormNav.SelectSingleNode(my:document,NamespaceManager);



st ring attachmentValue = string.Empty;

if(nodeNav!= null &&!String.IsNullOrEmpty(nodeNav.Value))

{



attachmentValue = nodeNav.Value;



//将文件添加到文档库

using(Site site =新网站(https://foxgroupinc.sharepoint.com/sites/FIC-Teamsites/finance/EU/RegionalProcesses/_layouts/15/start.aspx#/Submissions%202/Forms/AllItems.aspx)) />
{



使用(web = site.OpenWeb())

{

web.AllowUnsafeUpdates = true;

文件夹docLib = web.Folders [提交];

docLib.Files.Add(名称,数据);

web.AllowUnsafeUpdates = false;

web.Close();

}

site.Close();



}



}



}



}

}

//The purpose of this code is to take the attachment from an infopath form and add it to a Sharepoint 2013 library.

//I have the code below but am receiving the error "namespace Sharepoint does not exist. Even though I have added it to the references.

I believe it is because I am using the server object model even though the machine is not a server. I tried to convert the code to the client model but am still getting errors. E.g. I change SPSite to Site.

I also receive the warning: Warning 13 The primary reference "Microsoft.SharePoint" could not be resolved because it has an indirect dependency on the framework assembly "System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "Microsoft.SharePoint" or retarget your application to a framework version which contains "System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets 1605 5 Form2


using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.site;




namespace Form2
{
public partial class FormCode
{
// Member variables are not supported in browser-enabled forms.
// Instead, write and read these values from the FormState
// dictionary using code such as the following:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }

// NOTE: The following procedure is required by Microsoft InfoPath.
// It can be modified using Microsoft InfoPath.
public void InternalStartup()
{
((ButtonEvent)EventManager.ControlEvents["CTRL1_5"]).Clicked += new ClickedEventHandler(CTRL1_5_Clicked);
}

public void CTRL1_5_Clicked(object sender, ClickedEventArgs e)
{
// Retrieve the value of the attachment in the InfoPath form

XPathNavigator ipFormNav = MainDataSource.CreateNavigator();
XPathNavigator nodeNav = ipFormNav.SelectSingleNode("my:document", NamespaceManager);

string attachmentValue = string.Empty;
if (nodeNav != null && !String.IsNullOrEmpty(nodeNav.Value))
{

attachmentValue = nodeNav.Value;

// Add the file to a document library
using (Site site = new Site("https://foxgroupinc.sharepoint.com/sites/FIC-Teamsites/finance/EU/RegionalProcesses/_layouts/15/start.aspx#/Submissions%202/Forms/AllItems.aspx"))
{

using (web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
Folder docLib = web.Folders["Submissions"];
docLib.Files.Add(Name, data);
web.AllowUnsafeUpdates = false;
web.Close();
}
site.Close();

}

}

}

}
}

推荐答案

您的项目将目标框架设置为.NET 2.0;您尝试引用的程序集要求您将其更改为至少.NET 3.0。

Your project has the target framework set to .NET 2.0; the assembly you're trying to reference requires that you change it to at least .NET 3.0.

如何:定位.NET Framework版本 [ ^ ]


这篇关于提取Infopath表单附件到库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆