Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Log In Sign Up
BETA
x Dismiss
Sign up
I see that there are some ways to get the application folder path:
BLOG
275 1. Application.StartupPath
New Kids on the Block: Understanding
2. System.IO.Path.GetDirectoryName( Developers Entering the Workforce
System.Reflection.Assembly.GetExecutingAssembly().Location) Today
3. AppDomain.CurrentDomain.BaseDirectory
99 4. System.IO.Directory.GetCurrentDirectory()
5. Environment.CurrentDirectory
6. System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
7. System.IO.Path.GetDirectory(Application.ExecutablePath)
c# .net
share improve this question edited Jul 19 '15 at 11:50 asked May 18 '11 at 7:35
Peter Mortensen Leo Vo
11.2k 16 76 109 2,494 9 42 68
Linked
6 Why we have a lot ways to get application' path. I think there is a reason for each way. Leo Vo May 18 '11
at 7:43 13 How to get application folder when program
is started by Windows Task Scheduler
There is a error in #6: should read: System.Reflection.Assembly.GetExecutingAssembly().GetName().
CodeBase), System.IO.Path.GetDirectoryName(Application.ExecutablePath) BillW Nov 6 '14 at 15:33 Loading an XML file path in C#
4
4 Environment.CurrentDirectory vs
System.IO.Directory.GetCurrentDirectory
7 Answers active oldest votes
6 How to get executing assembly location?
In a VSTO 2005 application, it will be the directory containing the VSTO managed assemblies for your 1 How do I use a relative path instead of an
application, not, say, the path to the Excel executable. absolute path
The others may return different directories depending on your environment - for example see 3 How do I assign a relative path of an embed
@Vimvq1987's answer. image to a
ActiveSheet.PageSetup.LeftHeaderPicture.
CodeBase is the place where a file was found and can be a URL beginning with http://. In which case FileName?
Location will probably be the assembly download cache. CodeBase is not guaranteed to be set for see more linked questions
assemblies in the GAC.
Related
share improve this answer edited Jul 19 '15 at 11:51 answered May 18 '11 at 7:55
Peter Mortensen Joe 474 What is the correct way to create a single-
11.2k 16 76 109 88.4k 21 130 254 instance application?
This also worked on the Mac with Xamarin. Jared Updike Jan 29 '14 at 20:29 1510 What is the best way to iterate over a
Dictionary in C#?
+1 @Joe and For VSTO document-level add-in see THIS user2140173 Apr 3 '14 at 9:15
489 Best way to repeat a character in C#
1 Be aware that this returns a path with a backslash at the end. This caused me problems when formatting a
string with the result to pass as a process argument. avenmore Nov 6 '15 at 12:18 1706 How do I get a consistent byte
representation of strings in C# without
6 @avenmore - If you're formatting a string to build a path, consider using Path.Combine instead. This will
manually specifying an encoding?
take care of the trailing backslash for you. Joe Nov 6 '15 at 13:09
733 Best way to parse command line
show 1 more comment arguments in C#?
returns the current directory, which may or may not be the folder where the application is located. The Globally defined macro changes numerical value
same goes for Environment.CurrentDirectory . In case you are using this in a DLL file, it will return
Rigorous nature of combinatorics
the path of where the process is running (this is especially true in ASP.NET).
How was so much wildfire made and then
share improve this answer edited Jul 19 '15 at 11:54 answered May 18 '11 at 7:45 transported underneath the cathedral?
Hope this saves you some time. DM advice for a very specific type of one-off
For a web application, to get the current web application root directory, generally call by web page for
the current incoming request:
2
HttpContext.Current.Server.MapPath();
System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
share improve this answer edited Jul 19 '15 at 11:55 answered Jun 6 '15 at 6:24
Peter Mortensen Raj kumar
11.2k 16 76 109 199 2 7
I started a process from a Windows Service over the Win32 API in the session from the user which is
actually logged in (in Task Manager session 1 not 0). In this was we can get to know, which variable is
0 the best.
For all 7 cases from the question above, the following are the results:
Perhaps it's helpful for some of you, doing the same stuff, when you search the best variable for your
case.
share improve this answer edited Feb 20 at 19:36 answered Feb 10 at 13:51
Bhargav Rao Beetee
25.4k 16 65 101 53 2 9
0 System.IO.Path.GetDirectoryName(Process.GetCurrentProcess).MainModule.FileName)
Your Answer
By posting your answer, you agree to the privacy policy and terms of service.
Not the answer you're looking for? Browse other questions tagged c# .net or ask your own question.
question feed
about us tour help blog chat data legal privacy policy work here advertising info developer jobs directory mobile contact us feedback
Stack Overflow Geographic Code Review Photography English Language & MathOverflow Meta Stack Exchange
Information Systems Usage
Server Fault Magento Science Fiction & Mathematics Stack Apps
Electrical Engineering Fantasy Skeptics
Super User Signal Processing Cross Validated (stats) Area 51
Android Enthusiasts Graphic Design Mi Yodeya (Judaism)
Web Applications Raspberry Pi Theoretical Computer Stack Overflow Talent
Information Security Movies & TV Travel Science
Ask Ubuntu Programming Puzzles
Database & Code Golf Music: Practice & Christianity Physics
Webmasters Administrators Theory
more (7) English Language Chemistry
Game Development Drupal Answers Seasoned Advice Learners
(cooking) Biology
TeX - LaTeX SharePoint Japanese Language
Home Improvement Computer Science
Software Engineering User Experience Arqade (gaming)
Personal Finance & Philosophy
Unix & Linux Mathematica Bicycles
Money more (3)
Ask Different (Apple) Salesforce Role-playing Games
Academia
WordPress ExpressionEngine Anime & Manga
Development more (8)
Answers
Motor Vehicle
Cryptography Maintenance & Repair
more (17)
site design / logo 2017 Stack Exchange Inc user contributions licensed under cc by-sa 3.0 with attribution required