我有一个小型表单应用程序,我不会浏览网络UNC路径然后复制文件夹我得到错误无法转换方法组' GetType'到非委托类型' System.Type'。你打算调用这个方法吗?在此代码行上Type type = oFolderBrowserDialog.GetType;
namespace Deploy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
{
FolderBrowserDialog objFolderDialog = new FolderBrowserDialog();
textBox1.Text = GetNetworkFolders(objFolderDialog);
}
foreach (string dirPath in Directory.GetDirectories(textBox1.Text, "*",
SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.Replace(textBox1.Text, textBox2.Text));
//Copy all the files & Replaces any files with the same name
foreach (string newPath in Directory.GetFiles(textBox1.Text, "*.*",
SearchOption.AllDirectories))
File.Copy(newPath, newPath.Replace(textBox1.Text, textBox2.Text), true);
}
public static string GetNetworkFolders(FolderBrowserDialog oFolderBrowserDialog)
{
Type type = oFolderBrowserDialog.GetType;
System.Reflection.FieldInfo fieldInfo = type.GetField("rootFolder", BindingFlags.NonPublic | BindingFlags.Instance);
fieldInfo.SetValue(oFolderBrowserDialog, (Environment.SpecialFolder)18);
if (oFolderBrowserDialog.ShowDialog() == DialogResult.OK)
{
return oFolderBrowserDialog.SelectedPath;
}
else
{
return "";
}
}
}
}
答案 0 :(得分:0)
只需更改此行
即可 Type type = oFolderBrowserDialog.GetType();
^^^^^
答案 1 :(得分:0)
您错过了一组()
,就像错误消息所说的那样。