Pergunta

I need to access the full path of a Resource file in my C# vs2010 project to use to create myType variable below. If I manually type the path as

@"C:\dir1\dir2\dir3\dir4\Source\dir5\dir6\Resources\myIcon.png"

the code works and accesses the icon. But if I use:

var result = Path.GetFullPath("myIcon.png")  

The value in the variable result is the name of the correct directory except with two \ backslashes instead of one throughout i.e.

"C:\\dir1\\dir2\\dir3\\dir4\\Source\\dir5\\dir6\\myIcon.png" 

. The problem is that I need to derive the result (file name variable) dynamically and I cant hard code it.

I don't know if I am supposed to manually get rid of the two \ and replace it with a single \ ? Or am I missing something.

var result = Path.GetFullPath("myIcon.png");
ToolboxItemWrapper myType = new ToolboxItemWrapper(
    type,
    @"C:\dir1\dir2\dir3\dir4\Source\dir5\ImAdmin\dir6\myIcon.png",
    type.Name);

I am re-Editing my question. I have more than few problems, I am realizing after reading all the comments and the answers. So, I will mark the only answer as the answer but the one comment about being careful of using GetFullPath was also a valuable feedback. Thank you to all.

Foi útil?

Solução

If you are seeing \\ in debugger, then it is simply debugger escaping the \ character so string appears the same way as if it were to appear as literal in the code. Clicking on the small magnifying glass will bring up dialog that shows true, human-readable value.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top