我正在使用 C# 的共享点。在共享点列表中保存数据时,它会被保存,但在插入附件时,它会出现异常

问题描述 投票:0回答:0

我正在保存带有附件的表单数据。表单数据正确保存在列表中,但在更新附件时出现异常 “访问被拒绝。您无权执行此操作或访问此资源。” 在 Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(流响应流) 在 Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() 在 Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) 在 Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() 在 D 中的 Skoda_DCMS.DAL.IDCardDAL.d__12.MoveNext():-2023 年 7 月 Forms_Skoda_UAT_CHECK Forms_Skoda\Skoda_DCMS\DAL\IDCardDAL.cs:第 440 行。

但是我使用另一个人的登录名,然后它可以正确保存。上传附件的代码是

   if (file != null)
            {
                int attachmentID = RowId;

                string path = file.FileName;
                path = path.Replace(" ", "");
                string FileName = path;

                List docs = web.Lists.GetByTitle(listName);
                ListItem itemAttach = docs.GetItemById(attachmentID);

                var attInfo = new AttachmentCreationInformation();

                attInfo.FileName = FileName;

                byte[] fileData = null;
                using (var binaryReader = new BinaryReader(file.InputStream))
                {
                    fileData = binaryReader.ReadBytes(file.ContentLength);
                }

                attInfo.ContentStream = new MemoryStream(fileData);

                Attachment att = itemAttach.AttachmentFiles.Add(attInfo); //Add to File

                _context.Load(att);
                _context.ExecuteQuery();
            }

我已经检查了SharePoint中列表设置的权限。

c# asp.net-mvc sharepoint sharepoint-designer
© www.soinside.com 2019 - 2024. All rights reserved.