what is the code to be put in your program such that your program could show its location?

Dani AI

Generated

: what "location" you want matters — executable folder, current working directory, or the web application root. pointed at the WinForms approach that returns the executable folder; that works for desktop Forms apps but is not appropriate for ASP.NET. was right to ask for clarification. Below are practical alternatives depending on the app type, plus a few gotchas.

For a reliable app-folder value (works for desktop and many hosted scenarios) use the app-domain base directory. To get the exact assembly file path, read the executing/entry assembly and strip the filename. For ASP.NET use the server/hosting MapPath APIs.

' app-domain base directory (good general choice)
TextBox1.Text = AppDomain.CurrentDomain.BaseDirectory
' full path of the entry assembly, then directory
Dim exePath = System.Reflection.Assembly.GetEntryAssembly().Location
Dim exeFolder = System.IO.Path.GetDirectoryName(exePath)
TextBox1.Text = exeFolder
' in ASP.NET code-behind (HttpContext available)
Dim root = Server.MapPath("~")

' outside a request (background thread)
Dim rootBg = System.Web.Hosting.HostingEnvironment.MapPath("~")

Notes and troubleshooting: Environment.CurrentDirectory is the current working directory and can change, so it is usually the wrong choice. In ASP.NET assemblies may be shadow-copied; Assembly.Location can show a temp path — prefer MapPath("~") or AppDomain.CurrentDomain.BaseDirectory for web apps. If an API returns a URI (e.g., CodeBase) convert it to a local path first. Microsoft docs: Application.StartupPath (WinForms) (Application.StartupPath), app-domain base (AppDomain.CurrentDomain.BaseDirectory), assembly location (Assembly.Location) and ASP.NET mapping (HttpServerUtility.MapPath).

Recommended Answers

All 2 Replies

What d'you mean by your program showing its location.?
please elaborate..

Try This

Textbox.Text=Application.StartupPath

this should get the path

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.