Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# windows资源管理器外壳集成和更多?_C#_.net_Xml_Shell - Fatal编程技术网

C# windows资源管理器外壳集成和更多?

C# windows资源管理器外壳集成和更多?,c#,.net,xml,shell,C#,.net,Xml,Shell,我已使用此链接在windows资源管理器的右键单击菜单中注册了一个程序,它很好用。但我的问题是,我想以XML文件为目标,如果我右键单击该文件,它将加载该XML文件并打开文件对话框,以选择文件夹,并根据XML文件的结构创建文件夹和子文件夹。当我在shell服务器上品尝时,它看起来很好。我试图用下面的代码注册,但当我单击任何XML文件时,它都不会出现 using System.IO; using System.Runtime.InteropServices; using System.Text; u

我已使用此链接在windows资源管理器的右键单击菜单中注册了一个程序,它很好用。但我的问题是,我想以XML文件为目标,如果我右键单击该文件,它将加载该XML文件并打开文件对话框,以选择文件夹,并根据XML文件的结构创建文件夹和子文件夹。当我在shell服务器上品尝时,它看起来很好。我试图用下面的代码注册,但当我单击任何XML文件时,它都不会出现

using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using SharpShell.Attributes;
using SharpShell.SharpContextMenu;
using System.Xml;

namespace ClassLibrary1
{
[ComVisible(true)]
[COMServerAssociation(AssociationType.ClassOfExtension, ".xml")]
public class Class1 : SharpContextMenu
{
    protected override bool CanShowMenu()
    {
        return true;
    }     
    protected override ContextMenuStrip CreateMenu()
    {          
        var menu = new ContextMenuStrip();
        var createFolder = new ToolStripMenuItem
        {
            Text = "Create Folder",                
        };                      
        createFolder.Click += (sender, args) => myFunction();
        menu.Items.Add(createFolder);
        return menu;
    }
    private void myFunction()
    {
        var ofd = new OpenFileDialog();
        foreach (var filePath in SelectedItemPaths)
        {             
            if (ofd.ShowDialog() != DialogResult.Cancel)
            {
                string fullPath = ofd.FileName;               
                using (XmlTextReader reader = new  XmlTextReader(fullPath))
                {
                    var basePath = filePath + "/";
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                            case XmlNodeType.Element:                           
                                var baseDirPath = Path.Combine(basePath + reader.Name);
                                Directory.CreateDirectory(baseDirPath);
                                break;
                            case XmlNodeType.Text: 
                                Directory.CreateDirectory(basePath + reader.Name + "/" + reader.Value);
                                break;
                        }
                    }
                }
            } 
        }        
    }
}
}