unable to associate .txt file with listed Visual Studio Code on Windows 10

Solution 1:

This isn't user error or a Code bug. Microsoft have broken how file associations work in the latest alpha. I found a workaround which works in Windows 10 Pro - Version 1803 - OS Build 17134.320.

Find the command to start Visual Studio Code with a named file: click Start, type "code", right click Visual Studio Code and select Open File Location.

Right click the shortcut, click Properties and copy the contents of Target. This will be something like "C:\Users\[your name]\AppData\Local\Programs\Microsoft VS Code\Code.exe" "%1"

In Registry Editor, create HKEY_CLASSES_ROOT/.txt and set Default to txt_auto_file. Now create HKEY_CLASSES_ROOT/txt_auto_file/shell/open/command and set Default to the text you copied from Target.

At this point you can stop because double clicking a .txt file will now open it in Code. However the icon in Explorer is wrong. Right click the .txt file and select Open With. You'll now find everything works as it should; you can tick Always Use and this will fix the icon.

Solution 2:

There's no need to edit the registry.

Run Command Prompt as Administrator, and then use assoc and ftype:

assoc .txt=txtfile && ftype txtfile="%LocalAppData%\Programs\Microsoft VS Code\Code.exe" "%1"

Solution 3:

Right-click on .txt file and select "Open with" worked for me:

https://answers.microsoft.com/en-us/windows/forum/windows_10-other_settings/how-to-add-a-program-to-the-default-list-in/21c06a03-70db-43ff-9689-342e5ca4509f

  • rt. click on a file you want to associate with a specific app.
  • Select "Open with" (when I first tried this, I couldn't see the Open With menu item and followed this process: https://www.howtogeek.com/261076/how-to-fix-the-missing-open-with-option-on-the-windows-10-right-click-context-menu/, but the key was already there. More likely I had rt. clicked on a file type that you can't 'Open with', like an .exe. But just in case.)
  • Select 'Choose another app
  • Check 'Always use..."
  • Select "More apps"
  • Scroll down, select the app you want

enter image description here

enter image description here