简体   繁体   中英

Obtaining the correct path to a resource file in my project

I have translated a piece of C# code that is referencing a resource in a namespace path, something which VB doesn't exactly replicate.

The translated code is as follows:

Dim path As String = ThemesPath & "Dark.vssettings"
 Using stream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(path)
                If stream IsNot Nothing Then
                    AmbientHighlightingStyleRegistry.Instance.ImportHighlightingStyles(stream)
                End If
            End Using

In my Project I have folder Called 'Resources', which in turn contains a folder called 'SyntaxEditor' which contains the Dark.vssettings file.

I would like to declare ThemesPath as a string constant but am having trouble getting the syntax right such that the code within the Using statement can find the Dark.vssettings file.

I tried the following which I thought would do the trick but it doesn't.

 Public Const ThemesPath As String = "Resources/SyntaxEditor/"

Any suggestions?

Application.StartupPath returns the folder for the program running from within the VS project. You can parse back up the path and come down to Resources. Only works while running under VS of course. Typical path: C:\\DevVS2010\\_Misc_Projects\\_TestApp\\TestApp\\bin\\Debug

I guess your problem is also related to wrong slashes...

Try this code:

    Public Const ThemesPath As String = Application.StartupPath & "\Resources\SyntaxEditor\"

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM