Search code examples
c#windowsregistryvsto

What kind of encoding is this and how do I produce it programmatically?


I was creating an Office add-in using Visual Studio tools for Office, and part of deploying/installing the add-in is creating Windows registry entries for it. Visual Studio automatically creates these registry entries for the developer when he or she builds the add-in, but they need to be created by some other means (such as by an installer) when the add-in is being installed/deployed on an end-user's machine. Here is an example of the registry entry I'm questioning:

Manifest    REG_SZ    file:///C:/Users/Ryan/Office Projects/C%23/MyProject/addin.vsto

How do I programmatically recreate that kind of encoding? I guess it's not URL encoding, because the colon (:) is not changed into %3A, the spaces are not changed into %20s, however the # in "C#" is turned in to a %23... so what do I call this type of encoding, and how would I translate an absolute file system path into this type of encoding for the purposes of creating my own installer that would write this sort of registry entry?


Solution

  • I think Uri is what you want. This example:

    Debug.WriteLine(new Uri(@"C:\Test\c#file.txt").ToString());
    // outputs: file:///C:/Test/c%23file.txt