string strPath = HttpContext.Current.Server.MapPath("/开放式DLL"); DirectoryInfo df = new DirectoryInfo(strPath); System.IO.FileInfo[] fr = df.GetFiles(); foreach (System.IO.FileInfo f in fr) { if (f.Name.EndsWith("CNKI_Mngr.dll")) { System.Reflection.Assembly Mngrass = System.Reflection.Assembly.LoadFrom(f.FullName);//加载程序集 Type cnkiStructtp = Mngrass.GetType("CNKI_Mngr.UserStruct");//获取程序集中的实体对象 Type cnkiBasetp = Mngrass.GetType("CNKI_Mngr.UserBaseInfo"); Type cnkiComtp = Mngrass.GetType("CNKI_Mngr.UserComInfo"); object obj1 = System.Activator.CreateInstance(cnkiStructtp);//创建实例 object obj2 = System.Activator.CreateInstance(cnkiBasetp); object obj3 = System.Activator.CreateInstance(cnkiComtp); FieldInfo[] BaseInfo = cnkiBasetp.GetFields();//获取创建的实例的所有属性 FieldInfo[] ComInfo = cnkiComtp.GetFields(); FieldInfo[] StructInfo = cnkiStructtp.GetFields(); BaseInfo[1].SetValue(obj2, enty.UserName);//对指定的属性就行赋值 BaseInfo[11].SetValue(obj2, enty.RealName); BaseInfo[5].SetValue(obj2, enty.PassWord); BaseInfo[13].SetValue(obj2, enty.Department); ComInfo[2].SetValue(obj3, enty.EMail); ComInfo[9].SetValue(obj3, enty.Phone); StructInfo[0].SetValue(obj1, obj2); StructInfo[1].SetValue(obj1, obj3); foreach (System.IO.FileInfo item in fr) { if (item.Name.EndsWith("Grid30Register.dll")) { System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFrom(item.FullName); Type tp = ass.GetType("Grid30Register.CreateOperateClass"); MethodInfo meth = tp.GetMethod("PersonLibRegister"); object obj = System.Activator.CreateInstance(tp, new object[] { GridConfig.UserServerIP, GridConfig.UserServerIP, GridConfig.UserServerIP, KbaseConfig.ServerIP, KbaseConfig.ServerUserName, KbaseConfig.ServerPsw, "", GridConfig.Language }); ReStr = meth.Invoke(obj, new object[] { us }).ToString(); } } }