Reputation: 6962
What are the best C# (csharp) equivalents for the following VB (VB.NET, VisualBasic) statements:
My.Application.Info.DirectoryPath
My.Computer.Clipboard
My.Computer.Audio.PlaySystemSound()
My.Application.Shutdown()
Upvotes: 17
Views: 28320
Reputation:
System.IO.Directory.GetParent(Application.ExecutablePath)
is exactly the same as:
My.Application.Info.DirectoryPath
If you only do:
Application.ExecutablePath
You will get the executing file appended to the path, which may not be useful at all.
Upvotes: 1
Reputation: 2596
From decompiling Microsoft.VisualBasic.dll, the actual code that gets executed when calling My.Application.Info.DirectoryPath
is:
Path.GetDirectoryName(
new AssemblyInfo(
Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).Location);
Upvotes: 4
Reputation: 1
I think that you search is this sentence:
Application.StartupPath;
//Get file path without file name.
Upvotes: 0
Reputation: 479
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)
Upvotes: 9
Reputation: 6962
If you are converting a WPF application, you 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();
Upvotes: 3
Reputation: 2099
Application.ExecutablePath
System.Windows.Forms.Clipboard
System.Media.*
Application.Exit
Upvotes: 24
Reputation: 55750
This may not be exactly what you're looking for, but just in case you want to take a shortcut, if you add a reference to the Microsoft.VisualBasic assembly, you can use the nifty tools VB programmers have access via the MyServices namespace.
Upvotes: 2