BExplorer.Shell.Interop.User32.PinUnpinToStartMenu C# (CSharp) Method

PinUnpinToStartMenu() public static method

public static PinUnpinToStartMenu ( string filePath ) : void
filePath string
return void
		public static void PinUnpinToStartMenu(string filePath) {
			//PinUnpinStartMenu(filePath, !IsPinnedToStartMenu(filePath));
			var pin = IsPinnedToStartMenu(filePath);

			if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);

			// create the shell application object
			dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));

			string path = Path.GetDirectoryName(filePath);
			string fileName = Path.GetFileName(filePath);

			dynamic directory = shellApplication.NameSpace(path);
			dynamic link = directory.ParseName(fileName);

			dynamic verbs = link.Verbs();
			for (int i = 0; i < verbs.Count(); i++) {
				dynamic verb = verbs.Item(i);
				string verbName = verb.Name.Replace("&", string.Empty).ToLower();

				if ((pin && verbName.Equals("pin to start menu")) || (!pin && verbName.Equals("unpin from start menu"))) {
					verb.DoIt();
				}
			}

			shellApplication = null;
		}