During development, while you run the application as a console application or windows form application, often the code needs to load a specific file within the same folder of the exe assembly resides. The file can be located by using the file name directory since the default location will be the exe’s directory.
For instance,
File.Exists("myfile.xml");
However, it is a different story if you run the application as a WindowsService. In order to resolve the excuting assembly directory path, the code needs to do a bit extra work.
Console.WriteLine(Assembly.GetExecutingAssembly().Location) ;
result: “C:\FolderName\RunMe.exe”
Console.WriteLine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ) );
result: “C:\FolderName”
So , load the specifc file “myfile.xml”
File.ReadAllText( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location + @"\myfile.xml" ));
Tags: C#, Directory, File System, Windows service
Operating System: Windows Vista Enterprise 32 bit
CPU: Intel Pentium(R) 4 CPU 3.00GHz
Memory: 2038 MB
Tools: Testing Javascript Page
Opera 9.24 Score: 82
It is not too bad.
Firefox 3 Score : 109
It is fairly fast!
Chrome beta Score : 1105
WOW, ten times faster than firefox,
I am glad I downloaded it. Well done Google!
Internet Explorer 7 Score : ??????
After running ten seconds of browsing the page, I got err..
Here we go, continue. The score is 19
Happy Browsing!
Tags: Chrome, IE, Javascript, Performance