- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我没有更多的想法。我想为 Sharepoint 列表创建一个新元素并添加一个文件作为附件。我可以使用 ListItem
创建一个新元素。但是文件不会上传。
我尝试使用 SaveBinaryDirect()
函数和 AttachmentCreationInformation()
类。如果我尝试我得到这个异常
Exception thrown: 'System.Net.WebException' in System.dll (400)
我还连接到 SharePoint Server 并查看了 Windows 日志,但我一无所获。
在我的代码中,我使用 lLibrary.AddItem(itemCreateInfo)
添加了一个新的 ListItem
。使用 ListItem
我在 SharePoint 中创建了一个新元素。此元素位于 SharePoint 文件夹中。这一切都很好。
我尝试了很多,但没有任何效果。我需要帮助,拜托!
这里是我的完整代码:
public bool UploadToSharepoint(string sURL, string sLibrary, string sFolderName, string sTitel, string sDescription, string sFilePath)
{
using (ClientContext clientContext = new ClientContext(sURL))
{
if (!SetCredentialsInClientContext(clientContext))
{
return false;
}
List lLibrary = clientContext.Web.Lists.GetByTitle(sLibrary);
clientContext.Load(clientContext.Web.Lists);
clientContext.Load(lLibrary, l => l.RootFolder.ServerRelativeUrl);
clientContext.ExecuteQuery();
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
if (!string.IsNullOrEmpty(sFolderName))
{
itemCreateInfo.FolderUrl = lLibrary.RootFolder.ServerRelativeUrl + "/" + sFolderName;
}
ListItem newItem = lLibrary.AddItem(itemCreateInfo);
#region Work only with Document list in SharePoint
//using (FileStream fs = new FileStream(sFilePath, FileMode.Open))
//{
// clientContext.Load(lLibrary.RootFolder);
// clientContext.ExecuteQuery();
// string fileUrl = string.Format("{0}/{1}", lLibrary.RootFolder.ServerRelativeUrl, fi.Name);
// Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, fs, true);
//} // Ende using 'FileStream'
#endregion
using (FileStream fs = new FileStream(sFilePath, FileMode.Open))
{
#region WORK!
newItem["Title"] = sTitel;
newItem["Description"] = sDescription;
newItem.Update();
clientContext.ExecuteQuery();
#endregion
#region SaveBinaryDirect Example NOT WORK
//using (FileStream strm = new FileInfo(sFilePath).Open(FileMode.Open))
//{
// Uri url = new Uri(sURL);
// //Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, url.AbsolutePath + "/Attachments/" + newItem.Id + "/" + fi.Name, strm, true);
// Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, lLibrary.RootFolder.ServerRelativeUrl + "/Attachments/" + newItem.Id + "/" + fi.Name, strm, true);
//}
////Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, "", fs, true);
//string serverRelativeUrl = lLibrary.RootFolder.ServerRelativeUrl;
//Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, serverRelativeUrl, fs, true);
#endregion
#region AttachmentCreationInformation Example NOT WORK
AttachmentCreationInformation attInfo = new AttachmentCreationInformation();
attInfo.FileName = fs.Name;
attInfo.ContentStream = fs;
newItem.AttachmentFiles.Add(attInfo);
newItem.Update();
clientContext.ExecuteQuery();
#endregion
}
}
return true;
}
编辑!
我犯了一个大错。 Sharepoint 是 2010 年的。所以 AttachmentFiles.Add()
函数不起作用。
我发现我必须添加服务引用并更改我的代码。如需更多信息,请访问 SharePoint 2010 - Client Object Model - Add attachment to ListItem。
但现在我遇到异常 500。这就是我尝试连接到测试 SharePoint 的原因。在那里我可以读取消息 The list does not exist 的日志信息。
所选页面包含不存在的列表。该列表可能已被其他用户删除。
我不知道我必须为找到列表的函数 AddAttachment()
指定什么 listName
属性。
我的新代码:
public bool UploadToSharepoint(string sURL, string sLibrary, string sFolderName, string sTitel, string sDescription, string sFilePath)
{
using (ClientContext clientContext = new ClientContext(sURL))
{
if (!SetzeCredentialsInClientContext(clientContext))
{
return false;
}
List lLibrary = clientContext.Web.Lists.GetByTitle(sLibrary);
clientContext.Load(lLibrary);
clientContext.Load(lLibrary.RootFolder);
clientContext.ExecuteQuery();
ListItemCreationInformation listItemCreationInformation = new ListItemCreationInformation();
if (!string.IsNullOrEmpty(sFolderName))
{
listItemCreationInformation.FolderUrl = lLibrary.RootFolder.ServerRelativeUrl + "/" + sFolderName;
}
var newItem = lLibrary.AddItem(listItemCreationInformation);
newItem["Title"] = sTitel;
newItem.Update();
clientContext.ExecuteQuery();
clientContext.Load(newItem);
clientContext.ExecuteQuery();
TestSP.ListsSoapClient lsc = new TestSP.ListsSoapClient();
if (_cbAutorisierung.Checked)
{
lsc.ClientCredentials.Windows.ClientCredential = new NetworkCredential(tbName.Text, tbPasswort.Text, tbDomain.Text);
}
else
{
lsc.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
}
lsc.AddAttachment(sLibrary, newItem["ID"].ToString(), Path.GetFileName(sFilePath), System.IO.File.ReadAllBytes(sFilePath));
}
return true;
}
最佳答案
我终于开始工作了!
问题在于,在配置文件 App.Config
中,端点地址显式引用了站点。
“config”文件部分:
<system.serviceModel>
<bindings>
<basicHttpsBinding>
<binding name="ListsSoap">
<security>
<transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" />
</security>
</binding>
</basicHttpsBinding>
</bindings>
<client>
<endpoint address="https://TestSharePoint.com/_vti_bin/lists.asmx"
binding="basicHttpsBinding" bindingConfiguration="ListsSoap"
contract="SPRivarkom.ListsSoap" name="ListsSoap" />
</client>
</system.serviceModel>
在标签“端点”处是属性“地址”。这包含 Web 引用的地址。但正确的地址必须是 address="https://TestSharePoint.com/TestSite/TestUnderSite/_vti_bin/lists.asmx"
。
关于C# - 将文件作为附件添加到 Microsoft.SharePoint.Client.ListItem (SharePoint 2010),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47419671/
我遇到了一个错误,我不知道如何解决。我有以下代码(来自 Eliom Graffiti 教程),我正在尝试使用 make test.byte 进行测试。 open Eliom_content.Html5
我阅读文档的理解是这样的: 客户端是测试用例的子类。当我们运行 manage.py test 时,会为每个以“test_”开头的方法创建一个 SimpleTest 类的实例(它继承自 TestCase
我已经编写了一个用于接收多个客户端的服务器,它可以分别与客户端通信。在这里,我可以列出服务器中已连接的客户端,但是当客户端断开连接时,它不会从服务器中删除客户端。 Server.py import s
我正在制作一个社交网站。当任何用户在站点上更新或创建新内容时,我需要查看站点的任何其他用户来查看更改更新。 我有一些需要低延迟的评论,因此建议为此订阅。 我也有事件,但这些不需要这么低的延迟。每 10
我想在突变后使用乐观 UI 更新:https://www.apollographql.com/docs/react/basics/mutations.html 我对“乐观响应”和“更新”之间的关系感到
我想了解 Dask 在本地机器上的使用模式。 具体而言, 我有一个适合内存的数据集 我想做一些 pandas 操作 分组依据... 日期解析 等等 Pandas 通过单核执行这些操作,这些操作对我来说
我使用 Apollo、React 和 Graphcool。我有一个查询来获取登录的用户 ID: const LoginServerQuery = gql` query LoginServerQ
在本指南的帮助下,我最近在几个设备的应用程序中设置了 P2P 通信:http://developer.android.com/training/connect-devices-wirelessly/n
注意:我在节点项目中使用@twilio/conversations 1.1.0 版。我正在从使用可编程聊天过渡到对话。 我看到对 Client.getConversationByUniqueName
我对服务客户端和设备客户端库有点困惑。谁能解答我对此的疑问。 问题:当我通过 deviceClient 发送数据时,我无法接收数据,但当我使用服务客户端发送数据时,相同的代码可以工作。现在,xamar
我对服务客户端和设备客户端库有点困惑。谁能解答我对此的疑问。 问题:当我通过 deviceClient 发送数据时,我无法接收数据,但当我使用服务客户端发送数据时,相同的代码可以工作。现在,xamar
假设我有一个简单的应用程序。 如何设置 OAuth2 以允许其他应用程序访问我的应用程序的某些部分。 例如,当开发人员想要使用 Facebook API 时,他们会使用 Facebook API 用户
我有两个模块: 在一个模块中,我从另一个模块run 中引用了一个函数: @myorg/server import { Client } from '.' import { Middleware } f
我在通过服务器从客户端向客户端发送数据时遇到了一些问题(以避免监听客户端上的端口)。 我有一个这样的服务器: var net = require("net"); var server = net.cr
我正在使用 django.test.client.Client 来测试用户登录时是否显示某些文本。但是,我的 Client 对象似乎并没有让我保持登录状态。 如果使用 Firefox 手动完成,则此测
有两个我制作的程序无法运行。有服务器和客户端。服务器通过给用户一个 ID(从 0 开始)来接受许多客户端。服务器根据服务器的 ID 将命令发送到特定的客户端。 (示例:200 个客户端连接到 1 个服
今天,我在 Windows 10 的“程序和功能”列表中看到了 2 个不同版本的 ARC,因此我选择卸载旧版本,因为我需要一些空间。在卸载结束时,它们都消失了! 所以,我从 https://insta
在每个新的客户端连接上 fork 服务器进程 不同的进程(服务器的其他子进程,即 exec)无法识别在 fork 子进程中使用相同 fd 的客户端。 如何在其他进程上区分客户端? 如果文件描述符为新
a和b有什么区别? >>> import boto3 >>> a = boto3.Session().client("s3") >>> b = boto3.client("s3") >>> a ==
a和b有什么区别? >>> import boto3 >>> a = boto3.Session().client("s3") >>> b = boto3.client("s3") >>> a ==
我是一名优秀的程序员,十分优秀!