Charitha
Charitha

Reputation: 527

Need to get application folder

I need to get my application directory and add a file name to that path. So I used it this way.

String kofaxTextFilePath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(File)).CodeBase) + "\\KofaxBatchHistory.txt"

So it will give a path like this.

“file:\\C:\\Documents and Settings\\MyApplication\\ KofaxBatchHistory.txt”

But I need to get only

C:\\Documents and Settings\\MyApplication\\ KofaxBatchHistory.txt

With out doing any thing to this string is there any method to get it directly?

Upvotes: 2

Views: 286

Answers (3)

STRIIB.NET
STRIIB.NET

Reputation: 11

See Environment.SpecialFolder enumeration, http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx.

You might be looking for SpecialFolder.CommonApplicationData

Upvotes: 0

BlueMonkMN
BlueMonkMN

Reputation: 25601

string myDir = System.Reflection.Assembly.GetExecutingAssembly().Location;
myDir = System.IO.Path.GetDirectoryName(myDir);
String kofaxTextFilePath = System.IO.Path.Combine(myDir, "KofaxBatchHistory.txt");

Upvotes: 2

Pieter van Ginkel
Pieter van Ginkel

Reputation: 29640

Try Assembly.Location.

Assembly.GetAssembly(typeof(File)).Location

Or (better yet):

typeof(File).Assembly.Location

Upvotes: 1

Related Questions