How to Delete a File in SharePoint Online (Quick Guide)

How to Delete a File in SharePoint Online (Quick Guide)

Last Updated on November 17, 2024

Not sure how to delete a file?

In this quick guide, I will show you how to easily delete a file in SharePoint Online in various ways.

Let’s get started.

What happens when you delete a file?

When you delete a file in SharePoint Online, it doesn’t disappear immediately.

Instead, it’s moved to the recycle bin.

go to the recycle bin from the site contents

The flow goes like this:

  • First stop: recycle bin
  • Second stop: site collection recycle bin
  • Permanent deletion

This feature allows you to recover deleted files for up to 93 days unless you manually delete them permanently.

So technically, you can recover accidentally deleted files easily, though once the retention period is over, files can’t be recovered.

👉 Related: SharePoint Deleted File, Recycle Bin: Know Everything Now

Sign up for exclusive updates, tips, and strategies

    Deleting a Single File

    Deleting a single file in SharePoint Online is quick and easy.

    The fastest method is like this:

    • Go to the library where the file is stored
    • Right-click on the file
    • Click the “Delete” option

    Like this:

     delete a single file from the library

    Confirm the action when prompted to move the file to the recycle bin.

    As I mentioned earlier, the file is not permanently removed right away and will be moved to the recycle bin.

    👉 Related: How to Restore a Library in SharePoint Online (Quick Guide)

    Deleting Multiple Files

    Deleting multiple files is as easy as deleting a single file.

    The only difference is that you need to select these files first through their checkboxes:

    delete multiple files from the library

    The “Delete” button can be found in the toolbar (you can use this even when deleting a single file only).

    Similar to deleting a single file, you need to confirm the action to move all selected files to the recycle bin.

    This method saves time compared to deleting files one by one (though you can also delete the entire library/folder).

    Deleting Files Using PowerShell

    Using PowerShell to delete files in SharePoint Online is a powerful option for administrators.

    I recommend it if what you want to do is bulk deletions or automating file management tasks.

    Here’s a sample script you can run:

    # Connect to SharePoint Online
    $AdminUrl = "https://yourtenant-admin.sharepoint.com"
    $SiteUrl = "https://yourtenant.sharepoint.com/sites/yoursite"
    Connect-SPOService -Url $AdminUrl
    
    # Define Variables
    $Library = "Documents"
    $SiteRelativeFilePath = "https://www.mrsharepoint.com/sites/yoursite/$Library/ExampleFile.txt"  # Replace with the file's relative path
    
    # Delete a Single File
    Remove-SPOFile -SiteUrl $SiteUrl -ServerRelativeUrl $SiteRelativeFilePath
    
    # For Bulk Deletions (Example)
    $FilesToDelete = @(
        "https://www.mrsharepoint.com/sites/yoursite/$Library/File1.txt",
        "https://www.mrsharepoint.com/sites/yoursite/$Library/File2.txt"
    )
    
    foreach ($FilePath in $FilesToDelete) {
        Remove-SPOFile -SiteUrl $SiteUrl -ServerRelativeUrl $FilePath
    }
    
    # Disconnect from SharePoint Online
    Disconnect-SPOService

    The key here is to run the Remove-SPOFile command with the file’s URL or ID to delete it.

    PowerShell allows for advanced automation, like deleting files based on specific criteria (e.g., older than a certain date).

    However, you must ensure you have proper permissions and understand the impact of the commands.

    Troubleshooting Deletion Issues

    Sometimes, you may encounter problems when trying to delete files in SharePoint Online.

    Here are some of them:

    ProblemDescriptionSolution
    Insufficient PermissionsYou might not have the required permissions to delete the file.Ensure you have “Contribute” or higher access to delete files. Contact your admin if necessary.
    Retention PoliciesSharePoint may have policies preventing deletion for compliance reasons.Verify with your administrator if a retention policy is in place that restricts deletions.
    File in UseA file cannot be deleted while it’s open or actively in use.Ask users to close the file or terminate any workflows involving it.

    If these steps don’t work, administrators can intervene using advanced tools like PowerShell.

    Do you have any questions about deleting a file in SharePoint Online? Let me know in the comments.

    For any business-related queries or concerns, contact me through the contact form. I always reply. 🙂

    About Ryan Clark

    As the Modern Workplace Architect at Mr. SharePoint, I help companies of all sizes better leverage Modern Workplace and Digital Process Automation investments. I am also a Microsoft Most Valuable Professional (MVP) for SharePoint and Microsoft 365.

    Subscribe
    Notify of
    guest
    0 Comments
    Oldest
    Newest Most Voted
    Inline Feedbacks
    View all comments
    0
    Would love your thoughts, please comment.x
    ()
    x
    Scroll to Top