Отключите опцию «Связать с редактором» на панели инструментов Package Explorer.
(значок стрелки влево / вправо, здесь включен)
Проще остальных:
using System.IO;
using System.Reflection;
...
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
Application.StartupPath
should do that for you.
Update: from you edit I see that you are running on Compact Framework. Then Application.StartupPath will not work. This is the construct that I usually use then:
private static string GetApplicationPath()
{
return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
}
You can use Path.GetDirectoryName(string) method passing your original path string as parameter for this. What problem are you trying to solve? Maybe you really need something like working directory?
Если это exe-файл, как в вашем случае, используйте:
// Summary:
// Gets the path for the executable file that started the
// application, not including the executable name.
Application.StartupPath
А как насчет использования объекта FileInfo для извлечения имени каталога?
В Vb.Net:
fi = New FileInfo(System.Reflection.Assembly.GetExecutingAssembly.Location)
path = fi.DirectoryName