0

Based on this solution to convert .xls to .xlsx, is there a way to convert .doc to docx within SharePoint Online?

We migrated a lot of files and folders from NTFS folders to SharePoint online but did not have the time to convert the files beforehand.

Thanking you in advance, Andrew

2
  • In the solution you have linked to, the file is actually converted in PowerShell using the Excel application e.g. it just downloads the file, converts it locally and then uploads the new version to SharePoint. A similar solution is described here: social.msdn.microsoft.com/Forums/office/en-US/… Commented Aug 12, 2022 at 12:11
  • Hi Callum, The solution you have kindly linked to pertains to an offline conversion where the files are stored locally and then migrated to SahrePoint, my problem is that the files are already in SharePoint Online (365) so need to pull, convert and then push back, I don't even mind if it creates a new docx file and leaves the old doc file there as I can do a search for all doc files then delete. Commented Aug 12, 2022 at 12:23

1 Answer 1

0

You can repurpose the script to convert doc to docx's. Essentially this should be the logic of the script.

  1. Connect to SharePoint and get all "doc" items that need converting (this can be done using CAML query or get all list items and use where clause in PowerShell

  2. Iterate over each document (foreach loop) and download a local copy in a temp folder for conversion

  3. Convert the document from doc to docx (see code sample below) and upload the file back to SharePoint after this you can delete the original doc file from SharePoint

    if ($currentFile.Extension -like ".doc*") { [ref]$SaveFormat = "microsoft.office.interop.word.WdSaveFormat" -as [type] $word = New-Object -ComObject word.application $word.visible = $false $doc = $word.documents.open($currentFile.fullname) $path = ($currentFile.fullname).substring(0,($currentFile.fullname).lastindexOf(".")) $doc.saveas([ref] $path, [ref]$SaveFormat::wdFormatDocumentDefault) $doc.close() $word.Quit() $word = $null [gc]::collect() [gc]::WaitForPendingFinalizers() } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.