在我的公司中,附加到SharePoint列表的所有文件都存储在一个文件夹中,路径为:https://SharePointListURL/Dokuments/
将一个文件上传到此文件夹是没有问题的。将文件附加到Sharepoint列表项目
private void UploadFile(string FileName, System.Uri SharePointURL, string ListName, string SubFolder)
{
#region PreChecks
if (SharePointURL.ToString().Substring(SharePointURL.ToString().Length - 1, 1) != "/") { SharePointURL = new System.Uri(SharePointURL.ToString() + "/"); }
if(SubFolder.Substring(0,1) == "/") { SubFolder = SubFolder.Substring(1, SubFolder.Length - 1); }
if(SubFolder.Substring(SubFolder.Length - 1, 1) != "/") { SubFolder = SubFolder + "/"; }
if (!System.IO.File.Exists(FileName)) { throw new System.IO.FileNotFoundException(); }
#endregion
#region Sharepoint connection
Microsoft.SharePoint.Client.ClientContext cC = new Microsoft.SharePoint.Client.ClientContext(SharePointURL) { Credentials = System.Net.CredentialCache.DefaultCredentials };
Microsoft.SharePoint.Client.List SPList = cC.Web.Lists.GetByTitle(ListName);
#endregion
#region Define file stream
byte[] FileContent = System.IO.File.ReadAllBytes(FileName);
Microsoft.SharePoint.Client.FileCreationInformation fci = new Microsoft.SharePoint.Client.FileCreationInformation();
#endregion
#region Define FileCreationInformation
fci.Overwrite = true;
fci.Url = SubFolder + System.IO.Path.GetFileName(FileName);
fci.Content = FileContent;
#endregion
#region Uploading file
SPList.RootFolder.Files.Add(fci);
cC.ExecuteQuery();
#endregion
}
现在,我想将这些文件链接到他们的目标SharePoint.ListItems。我搜索了ListItem的所有FieldValues,但我不知道附加文件的路径存储在哪里。
任何人都可以告诉我,我可以如何将这些文件附加到指定的ListItem?
文件夹http://SharePointListURL/Lists/ListName/Attachments/ItemID/
不存在,因为如果你在谷歌搜索有几个页面解释,你只需要上传文件到这个文件夹。
谢谢 扬
确定以列表项,它似乎没有人可以帮助我在这里。在许多文章中,附件很容易被ListItem.Attachments使用。此成员不能使用Microsoft.SharePoint.Client.dll,但它应该在Microsoft.SharePoint.dll(服务器上的dll)中可用。我无法访问此服务器的libarary。它最终有可能解决我的问题吗?有人知道吗? – CJens