How to delete any object in a Word DOCX document in C# .NET Framework

You may have experienced the process of interacting with DOCX files via C# before. If you have, you would know the pain and suffering that I know. Luckily for you, I have an alternate method for you to try, a shortcut if you will. Let’s dive in.

To begin, run this command in the Package console. That will allow NuGet to download and install our API client.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

Next, call EditDocumentDocxRemoveObject and provide the path to the desired object.

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class EditDocumentDocxRemoveObjectExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new EditDocumentApi();var reqConfig = new DocxRemoveObjectRequest(); // DocxRemoveObjectRequest | Document input requesttry{// Delete any object in a Word DOCX documentDocxRemoveObjectResponse result = apiInstance.EditDocumentDocxRemoveObject(reqConfig);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditDocumentApi.EditDocumentDocxRemoveObject: " + e.Message );}}}}

And that’s really all there is to it. Easy.

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store