I am using sharepoint with C#. While saving data in sharepoint list it is getting saved but while inserting attachment it is giving exception

87 views Asked by At

I am saving form data with attachments. Form data is saving in list properly but while updating attachment it is giving exception of "Access denied. You do not have permission to perform this action or access this resource." at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() at Skoda_DCMS.DAL.IDCardDAL.d__12.MoveNext() in D:\07-July-2023\eForms_Skoda_UAT_CHECK\eForms_Skoda\Skoda_DCMS\DAL\IDCardDAL.cs:line 440.

But Im using another person's login then it is saving properly.Code for uploading attachment is

   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();
            }

I have checked the permissions of the list setting in SharePoint.

0

There are 0 answers