8

I just installed Visual Studio Code 1.28.1, but I'm unable to associate it with the .txt extension on Windows 10.

I'm well aware how to associate an extension with an application on Windows. I can right-click in Explorer, select, "Open As...", select the application, and make sure "Always open with this app" is checked. Or I can go in to the properties of a file in Explorer, look at "Opens with", and click on "Change". Or I can go to "Choose default apps by file type …", etc. The problem is that none of this is working with VS Code.

Currently my .txt files are associated with EmEditor. I change the association to Notepad. No problem. I change the association back to EmEditor. That works.

But if I select the blue "Visual Studio Code" option that appears in the list of applications, nothing changes. The old association remains.

I even tried ignoring the blue icon in the selection list, and manually browsed and selected %LocalAppData%\Programs\Microsoft VS Code\Code.exe as the default editor. That doesn't work, either. Nor did manually selecting %LocalAppData%\Programs\Microsoft VS Code\bin\code.cmd.

In case you think this might be related to EmEditor, I tried to associate .tidyconfig files (which on my system are currently not associated with any editor at all) with VS Code. It did nothing.

What's going on? Associating VS Code with my text files should be the most basic of basic Windows integration. Why won't it work?

(I filed this as VSCode Issue #61084, but I had no responses. I'm filing it here in case the "bug" is some sort of user error.)

14
  • Did you try to run the command manually per command line, like "%LocalAppData%\Programs\Microsoft VS Code\Code.exe" "sometxt.txt"?
    – musicman
    Commented Oct 17, 2018 at 17:23
  • What does that have to do with associating the application with the file type via extension in Windows Explorer? Commented Oct 17, 2018 at 17:30
  • To see if it is working at all to open the textfile with this application? You might also want to inspect and share the contents of your win registry regarding the file type association.
    – musicman
    Commented Oct 17, 2018 at 17:37
  • Yes, I can edit text files just fine. The editor is working fine. This question is about association with a file type based upon extension in Windows Explorer. Have you personally tried to associate Visual Studio Code 1.28.1 with the .txt extension in Windows 10? What was the result for you? Did you succeed? Commented Oct 17, 2018 at 17:39
  • 1
    Possible duplicate of SSMS wont give up file associations Commented Nov 11, 2018 at 17:42

3 Answers 3

2

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.

7
  • At github.com/Microsoft/vscode/issues/61084 they also indicated the Windows bug and gave a link to reddit.com/r/windows/comments/9qeijs/… for more discussion. I haven't tried your workaround because for now I want to wait for the Windows fix, but thanks. I've upvoted the answer. If someone else reports that this workaround works, I can mark this as the correct answer. Commented Nov 1, 2018 at 0:05
  • Odd, I got an email saying my bounty had expired, but I don't remember whether I put a bounty on this or not; I guess I did, based on my current reputation. But I don't see anything about a bounty, even though it is supposedly still in the grace period. Commented Nov 1, 2018 at 0:07
  • @GarretWilson - You started the bounty on Oct 19 at 21:06 which would have expired 7 days later. 50% of the bounty goes to the answer with the most votes cast after the bounty was started. 100% would have gone to the answer you selected. However, no answer received votes during those 7 days, so the bounty wasn’t awarded to answer in this case (there is a minimum number of votes that must be given to an answer)
    – Ramhound
    Commented Nov 1, 2018 at 5:52
  • Yes, I'm quite experienced using the bounty system on Stack Overflow. But oddly I don't see any option to assign the bounty here, even though I'm in the grace period. Maybe my reputation is so low on Super User that I'm not allowed to assign my own bounty during the grace period. Odd. Commented Nov 1, 2018 at 14:36
  • @GarretWilson - Your bounty expired several days ago (as of Nov 1). So it’s likely you attempted to award it after it expired
    – Ramhound
    Commented Nov 5, 2018 at 2:41
3

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"
1
1

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

enter image description here

enter image description here

2
  • That was a lot of work you went to, but you're just repeating the obvious. In fact the question made clear I had already tried this. In this case there was a Windows 10 bug that prevented association, and it was only fixed in the last couple of months. Commented Jan 24, 2019 at 21:46
  • This only works if the file type doesn't already have an association. Because otherwise, the "open with" option doesn't appear on the context menu.
    – cowlinator
    Commented Jul 15, 2020 at 1:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .