To register for my program (the program to read and process data from excel file), I did the following:
//Register ContextMenu
public static void RemoveContextMenuItem(string extension, string menuName)
{
RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(extension);
if (registryKey != null)
{
string extstring = registryKey.GetValue("").ToString(); //root
registryKey.Close();
if (!string.IsNullOrEmpty(extstring))
{
registryKey = Registry.ClassesRoot.OpenSubKey(extstring, true);
if (registryKey != null)
{
RegistryKey subky = registryKey.OpenSubKey("shell\\" + menuName);
if (subky != null)
{
subky.Close();
registryKey.DeleteSubKeyTree("shell\\" + menuName);
registryKey.Close();
}
}
}
}
}
And, the path parameter to the program:
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args != null && args.Length > 0)
{
Application.Run(new FormDemo(args[0]));
}
else Application.Run(new FormDemo());
}
with instance method:
public FormDemo()
{
InitializeComponent();
}
public FormDemo(string filePath)
{
InitializeComponent();
}
In my project, Tool.cs file used to process data with excel file. If I do this then my program works well
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
FormDemo main = new FormDemo();
MainTool.frmmain = main;
Application.Run(main);
}
And so my program has been registered on the ContextMenu, but when selecting the program, the program still can not process excel file.
Does anyone can guide me how to still use MainTool.frmmain (Process Excel method) and take the path as:
if (args! = null && args.Length> 0)
{
Application.Run (new FormDemo (args [0]));
}
else Application.Run (new FormDemo ());
I'm having problems in the method void Main().
THANKS