Reputation: 11
There is something weird with the way I add to registry run.
When I use
private static string AppPath = new Uri((System.Reflection.Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
to set the path in run registry it worked fine, but if folder name is "c#" for example the added key will be cut before # so should be :
c:/desktop/c#/myprogram.exe but it's
c:/desktop/c
What's the problem can you guys help?
Upvotes: 1
Views: 77
Reputation: 5650
This happens because the #
character gets encoded in the Uri
and becomes %23
instead.
I'm not sure why you want to use Uri
to get the location of the executable. There is a better way (as nightsnaker posted).
However, if you must use an Uri
(for whatever reason), you can get the full path by doing something like this:
string s = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
Uri u = new Uri(s);
string local = u2.LocalPath+u2.Fragment.Replace('/','\\');
Upvotes: 0
Reputation: 15237
I can't duplicate what you're seeing. I think maybe you're missing some information:
var uri = new Uri("c:/desktop/c#/myprogram.exe");
string raw = uri.ToString(); // "file:///c:/desktop/c%23/myprogram.exe"
string local = uri.LocalPath; // "c:\desktop\c#\myprogram.exe"
Are you sure about what's coming out of the Codebase property there?
Upvotes: 1
Reputation: 471
I think there is an issue with the Uri escape symbols. Try this:
string AppPath = System.Reflection.Assembly.GetExecutingAssembly ().Location;
Upvotes: 5