本文整理汇总了C#中System.Environment.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Environment.ToString方法的具体用法?C# Environment.ToString怎么用?C# Environment.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Environment
的用法示例。
在下文中一共展示了Environment.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddSpecialFolder
private static void AddSpecialFolder(Environment.SpecialFolder sf)
{
try
{
AddSpecialFolder(sf.ToString(), Environment.GetFolderPath(sf));
}
catch
{
}
}
示例2: IsEnvironment
public static bool IsEnvironment(Environment env)
{
return ConfigurationManager.AppSettings["Environment"] == env.ToString();
}
示例3: RemoveShortcut
public static void RemoveShortcut(Environment.SpecialFolder directory, String subdir = "")
{
try {
log.Debug("RemoveShortcut: directory=" + directory.ToString() + "; subdir=" + subdir);
if (subdir != "") subdir = "\\" + subdir;
String shortcutDir = Environment.GetFolderPath(directory) + subdir;
if (!System.IO.Directory.Exists(shortcutDir)) {
log.Info("Failed to delete shortcut in \"" + shortcutDir + "\" - directory does not exist.");
return;
}
foreach (String file in System.IO.Directory.GetFiles(shortcutDir)) {
if (file.EndsWith("\\OutlookGoogleCalendarSync.lnk") || //legacy name <=v2.1.0.0
file.EndsWith("\\" + Application.ProductName + ".lnk")) {
System.IO.File.Delete(file);
log.Info("Deleted shortcut in \"" + shortcutDir + "\"");
break;
}
}
} catch (System.Exception ex) {
log.Warn("Problem trying to remove legacy Start Menu shortcut.");
log.Error(ex.Message);
}
}
示例4: CheckShortcut
//public static void AddShortcut(Environment.SpecialFolder directory, String subdir = "") {
// log.Debug("AddShortcut: directory=" + directory.ToString() + "; subdir=" + subdir);
// String appPath = Application.ExecutablePath;
// if (subdir != "") subdir = "\\" + subdir;
// String shortcutDir = Environment.GetFolderPath(directory) + subdir;
// if (!System.IO.Directory.Exists(shortcutDir)) {
// log.Debug("Creating directory " + shortcutDir);
// System.IO.Directory.CreateDirectory(shortcutDir);
// }
// string shortcutLocation = System.IO.Path.Combine(shortcutDir, Application.ProductName + ".lnk");
// #region "Windows Script Host Object Model - 32bit only"
// /*
// IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
// IWshRuntimeLibrary.IWshShortcut shortcut = shell.CreateShortcut(shortcutLocation) as IWshRuntimeLibrary.WshShortcut;
// shortcut.Description = "Synchronise Outlook and Google calendars";
// shortcut.IconLocation = appPath.ToLower().Replace("OutlookGoogleCalendarSync.exe", "icon.ico");
// shortcut.TargetPath = appPath;
// shortcut.WorkingDirectory = Application.StartupPath;
// shortcut.Save();
// */
// #endregion
// #region "C:\Windows\System32\shell32.dll - works but only compiles in VSE 2010?!"
// /*
// System.IO.File.WriteAllBytes(shortcutLocation, new byte[] { });
// //Initialize a ShellLinkObject for that .lnk file
// Shell32.Shell shl = new Shell32.ShellClass();
// Shell32.Folder dir = shl.NameSpace(shortcutDir);
// Shell32.FolderItem itm = dir.Items().Item(Application.ProductName + ".lnk");
// Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink;
// lnk.Path = appPath;
// lnk.Description = "Synchronise Outlook and Google calendars";
// lnk.WorkingDirectory = Application.StartupPath;
// lnk.SetIconLocation(appPath.ToLower().Replace("OutlookGoogleCalendarSync.exe", "icon.ico"), 0);
// lnk.Save(shortcutLocation);
// */
// #endregion
// log.Info("Created shortcut in \"" + shortcutDir + "\"");
//}
public static Boolean CheckShortcut(Environment.SpecialFolder directory, String subdir = "")
{
log.Debug("CheckShortcut: directory=" + directory.ToString() + "; subdir=" + subdir);
Boolean foundShortcut = false;
if (subdir != "") subdir = "\\" + subdir;
String shortcutDir = Environment.GetFolderPath(directory) + subdir;
if (!System.IO.Directory.Exists(shortcutDir)) return false;
foreach (String file in System.IO.Directory.GetFiles(shortcutDir)) {
if (file.EndsWith("\\OutlookGoogleCalendarSync.lnk") || //legacy name <=v2.1.0.0
file.EndsWith("\\" + Application.ProductName + ".lnk")) {
foundShortcut = true;
break;
}
}
return foundShortcut;
}
示例5: RemoveShortcut
public static void RemoveShortcut(Environment.SpecialFolder directory, String subdir = "") {
log.Debug("RemoveShortcut: directory=" + directory.ToString() + "; subdir=" + subdir);
if (subdir != "") subdir = "\\" + subdir;
String shortcutDir = Environment.GetFolderPath(directory) + subdir;
if (!System.IO.Directory.Exists(shortcutDir)) {
log.Info("Failed to delete shortcut in \"" + shortcutDir + "\" - directory does not exist.");
return;
}
foreach (String file in System.IO.Directory.GetFiles(shortcutDir)) {
if (file.EndsWith("\\OutlookGoogleCalendarSync.lnk")) {
System.IO.File.Delete(file);
log.Info("Deleted shortcut in \"" + shortcutDir + "\"");
break;
}
}
}
示例6: AddShortcut
public static void AddShortcut(Environment.SpecialFolder directory, String subdir = "") {
log.Debug("AddShortcut: directory=" + directory.ToString() + "; subdir=" + subdir);
String appPath = Application.ExecutablePath;
if (subdir != "") subdir = "\\" + subdir;
String shortcutDir = Environment.GetFolderPath(directory) + subdir;
if (!System.IO.Directory.Exists(shortcutDir)) {
log.Debug("Creating directory " + shortcutDir);
System.IO.Directory.CreateDirectory(shortcutDir);
}
string shortcutLocation = System.IO.Path.Combine(shortcutDir, "OutlookGoogleCalendarSync.lnk");
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
IWshRuntimeLibrary.IWshShortcut shortcut = shell.CreateShortcut(shortcutLocation) as IWshRuntimeLibrary.WshShortcut;
shortcut.Description = "Synchronise Outlook and Google calendars";
shortcut.IconLocation = appPath.ToLower().Replace("OutlookGoogleCalendarSync.exe", "icon.ico");
shortcut.TargetPath = appPath;
shortcut.WorkingDirectory = Application.StartupPath;
shortcut.Save();
log.Info("Created shortcut in \"" + shortcutDir + "\"");
}
示例7: GetDisplayName
private static string GetDisplayName(Environment.SpecialFolder sf)
{
string path = Environment.GetFolderPath(sf, Environment.SpecialFolderOption.Create);
if (Directory.Exists(path))
{
return System.IO.Path.GetFileName(path);
}
return sf.ToString();
}
示例8: Shortcut
public Shortcut(Environment.SpecialFolder specialFolder) {
var folder = new Folder(Environment.GetFolderPath(specialFolder));
name = folder.Name;
command = folder.FullName;
icon = new PluginIconLoader().Png(specialFolder.ToString());
}