How to Detect Existing SharePoint Attachments in an Outlook Add-In
Question details
The user wants to know how to identify if an email attachment in Outlook is already saved in a SharePoint library using an add-in.

- Product
- Microsoft Outlook
- Device & OS
- not provided
- Scenario
- Developing an Outlook add-in to manage attachments and avoid duplicating files in SharePoint.
- Observed behavior
- Outlook lacks a native built-in flag to check if an attachment already exists in SharePoint, requiring a custom add-in solution.
Ensure you have an active Microsoft 365 developer subscription, access to Microsoft Graph or SharePoint APIs, and a basic understanding of building Outlook web add-ins.
Build an Outlook Add-In using Microsoft Graph APIs
Use Microsoft Graph API within a custom Outlook add-in to search SharePoint for existing files with matching attachment names.
Since Outlook and VBA do not have a built-in flag to natively detect existing SharePoint files, you must build a custom Office web add-in. By leveraging Microsoft Graph APIs, the add-in can cross-reference the attachment's name or content identifier with the target SharePoint document library.
Use the Yeoman generator for Office Add-ins to scaffold a new Outlook web add-in project.
Use the Office.js API (specifically 'Office.context.mailbox.item.attachments') to fetch the file names and details of the current email attachments.
Implement the Microsoft Authentication Library (MSAL) or Single Sign-On (SSO) to securely authenticate the user for Microsoft Graph access.
Make an API GET request to the Microsoft Graph SharePoint endpoint (e.g., '/sites/{site-id}/drive/root/search(q='{attachment-name}')') to search the permitted library for the attachment name.
Parse the API response data and display an alert or notification in the Outlook add-in task pane if a duplicate file match is found.

Looking for a reliable and lightweight Office suite? Try WPS Office
While Outlook and SharePoint integrations require complex Microsoft 365 add-in development, if you just need a powerful, lightweight, and free office suite for your daily document needs, WPS Office is an excellent alternative. It offers high compatibility with Microsoft Office formats without the heavy resource usage.
- 1. Download the installer: Visit the official WPS Office website and click the download button for your operating system.
- 2. Install the software: Run the downloaded installation file and follow the on-screen prompts to complete the setup.
- 3. Start creating documents: Open WPS Office to seamlessly view, edit, and manage your documents, spreadsheets, and presentations.

Frequently Asked Questions
Can I use Outlook rules to detect SharePoint attachments?
No, Outlook rules do not have a built-in condition to check if an attachment exists in a SharePoint library. You must use a custom add-in or set up an automated workflow via Power Automate.
Is it possible to use VBA instead of an Outlook web add-in?
While VBA can perform basic local file operations, it is generally unreliable for detecting files in modern SharePoint Online libraries due to modern authentication requirements and API limitations. A web add-in is the recommended approach.
Which APIs are best for checking SharePoint libraries?
The Microsoft Graph API is the recommended and most secure standard for querying SharePoint document libraries and interacting with Microsoft 365 services from within an Outlook add-in.




