How to add attachment file to Share Point Document Libarary using Graph API - C# code

Maryam Adib 0 Reputation points
2023-02-15T14:58:26.5333333+00:00

Hi there,

I am using this code for adding a sample file as an attachment in SharePoint by Graph API programming in C#, but I got this error

 using (FileStream fsSource = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
            {

                var file_Stream = await graphServiceClient.Sites[siteId].Lists[listId].Drive.Root.ItemWithPath(FilePath).Content.Request().PutAsync<DriveItem>(fsSource);
            }

User's image

Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Microsoft Security | Microsoft Graph
{count} votes

2 answers

Sort by: Most helpful
  1. CarlZhao-MSFT 46,406 Reputation points
    2023-02-16T03:20:37.31+00:00

    Hi @Maryam Adib

    You can use the graph API to upload files to drive items in SharePoint document library, but adding attachment files to list items is not currently supported.

    There is a similar feature request on the graph feedback forum, and you can upvote this thread to increase the priority of the request.

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".


  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.