Use Microsoft Power Automate (Flow) to automatically convert RTF files to DOC

I once ran into situations with users where some data files are exported from software solutions in .rtf or .txt format only. To improve the user experience once these files are dropped into SharePoint, we can convert any .rtf file automatically to .doc.

Why convert from RTF?

When RTF files are opened in the browser, the option to “Edit in browser” is grayed out since the file type isn’t compatible with that functionality.

Click to enlarge

Okay, but why .doc and not .docx?

Unfortunately, we can’t convert from RTF to DOCX without the use of Azure functions (thanks, Pieter Veenstra for that info). But if we can at least convert it to DOC for users, they’ll get the “Edit in Browser” option which will then prompt them to convert the file to DOCX in two clicks (Convert –> Edit). Then we finally have a .docx file.

Click to enlarge

How to auto-convert .rtf to .doc using Power Automate (Flow)

Update 12/3/2020 (big thanks to Dawid Ziolkowski for the tip on trigger condition)

Create the flow (.rtf to .doc)

  1. Create a new flow with the trigger When a file is created or modified (properties only) and select (or enter) your site and library name.
  2. Click the ellipsis and Settings.

3. Add a Trigger Condition as @endsWith(triggerOutputs()?[‘body/{FilenameWithExtension}’],’rtf’) and click Done.

Now the flow will only run if the file’s extension is RTF.

Next, configure each next step as pictured below (beginning with the blue-outlined Get File content using path step), careful with file paths not to include the whole URL – just the relative path beginning something like /Shared Documents/…

  1. Trigger step for when file is created (we already configured this with the trigger condition)
  2. Get file content using path (gets contents of the .rtf file – use File name with extension dynamic data from step 1/red)
  3. Create file (creates new .doc file using the .rtf contents – use dynamic data from step 2/blue)
  4. Delete file (deletes original .rtf file to avoid confusion – use Identifier from step 1/red)
Click to enlarge

That’s it! Now when an RTF file is added, it’ll be replaced with a DOC version and the RTF file will be deleted. Any non-RTF file won’t be touched, and won’t trigger/count as a flow run.

Expand the flow (optional – delete .doc if .docx created)

Users can easily convert .doc to .docx in two clicks in the browser. But it leaves the original file (.doc) behind which can be confusing for users. So we can create a separate flow to delete a .doc file IF a .docx by the same name is created.

It starts out the same as our first flow, with a “when a file is added” step paired with a trigger condition but looking for .docx this time.

Create the second (optional) flow (delete .doc version if .docx version with same name exists)

  1. Create a new flow with the trigger When a file is created or modified (properties only) and select (or enter) your site and library name.
  2. Click the ellipsis and Settings.

3. Add a Trigger Condition as @endsWith(triggerOutputs()?[‘body/{FilenameWithExtension}’],’docx’) and click Done.

Then use a “Get file metadata using path” step to get any file by the same name from that library (use the “Name” dynamic content from the trigger step and add a .doc). Then in your “delete file” step, simply use the ID from the get file metadata step.

Now when a user converts a .doc to a .docx file in the browser, your Flow will delete the .doc that’s left behind if there’s a match. Note that this runs on ANY .docx file in the library when added/modified, and will fail if no .doc name match is found. There’s probably a cleaner way to do this.

While these are certainly not ideal workarounds, it may be the best you’re able to do with the resources on hand. Not everyone has Azure, or developers, premium add-ins/vendors or the budgets for such things. Best of luck!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.