How to Delete an Object from a DOCX Document in C#

Cloudmersive
2 min readJan 26, 2021

Simplifying your online editing process is a huge time-saver, and with the right equipment, it can be as easy as 1–2–3. Once you’ve opened a Word document for modifications with our Begin Editing function, the following process can be used to remove objects (paragraphs, tables, images, etc.) from the text.

Starting off, we are going to install the .NET Framework SDK (.NET Core available as well):

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

Next, we will call the remove object function:

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: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new EditDocumentApi();
var reqConfig = new DocxRemoveObjectRequest(); // DocxRemoveObjectRequest | Document input request
try
{
// Delete any object in a Word DOCX document
DocxRemoveObjectResponse result = apiInstance.EditDocumentDocxRemoveObject(reqConfig);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling EditDocumentApi.EditDocumentDocxRemoveObject: " + e.Message );
}
}
}
}

When the object has been successfully deleted from your document, you can continue to make edits, or use our Finish Editing process to download and save your changes. To retrieve your personal API key and gain access to 800 monthly calls, head to the Cloudmersive website and register for a free account.

--

--

Cloudmersive

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