[ACCEPTED]-Convert VB to C# - My.Application.Info.DirectoryPath-vb.net

Accepted answer
Score: 24

Application.ExecutablePath

System.Windows.Forms.Clipboard

System.Media.*

Application.Exit

0

Score: 9
My.Application.Info.DirectoryPath
  AppDomain.CurrentDomain.BaseDirectory

My.Computer.Clipboard
  System.Windows.Clipboard //(WPF)
  System.Windows.Forms.Clipboard //(WinForms)

My.Computer.Audio.PlaySystemSound()
  System.Media.SystemSounds.*.Play()

My.Application.Shutdown()
  System.Windows.Forms.Application.Exit() //(WinForms)
  or
  System.Windows.Application.Current.Shutdown()  //(WPF)
  or
  System.Environment.Exit(ExitCode)  //(Both WinForms & WPF)

0

Score: 4

From decompiling Microsoft.VisualBasic.dll, the 2 actual code that gets executed when calling 1 My.Application.Info.DirectoryPath is:

Path.GetDirectoryName(
    new AssemblyInfo(
        Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).Location);
Score: 3

If you are converting a WPF application, you 1 can use the following:

System.Reflection.Assembly.GetExecutingAssembly().Location;
//gets file path with file name

System.Windows.Clipboard;

System.Media.SystemSounds.[Sound].Play();

System.Windows.Application.Current.Shutdown();
Score: 2

This may not be exactly what you're looking 5 for, but just in case you want to take a 4 shortcut, if you add a reference to the 3 Microsoft.VisualBasic assembly, you can 2 use the nifty tools VB programmers have 1 access via the MyServices namespace.

Score: 1
System.IO.Directory.GetParent(Application.ExecutablePath) 

is exactly the same as:

My.Application.Info.DirectoryPath

If you only do:

Application.ExecutablePath

You 2 will get the executing file appended to 1 the path, which may not be useful at all.

Score: 0

I think that you search is this sentence:

Application.StartupPath;
//Get file path without file name.

0

Score: 0

The following

using System.IO;
Directory.GetCurrentDirectory()

0

More Related questions