本文介绍了Event Handler 2007中的问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 场景: - 在创建的资源上,我想在名为"projectManager"的查找表中输入资源名称 incase资源属于projectmanager组... 请检查代码并建议我   使用System; 使用System.Collections.Generic; 使用System.Linq; 使用System.Text; 使用PSLibrary = Microsoft.Office.Project.Server.Library; 使用Microsoft.Office.Project.Server.Events; 使用wss = Microsoft.SharePoint; namespace ClassLibrary1 { public class Resource:ResourceEventReceiver { public static Resourcewe.Resource r = new ClassLibrary1.Resourcewe.Resource (); public static LookUpTable1.LookupTable l = new ClassLibrary1.LookUpTable1.LookupTable(); Guid [] lookupguid; public override void OnCreated(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo,ResourceCreatePostEventArgs e) { base.OnCreated(contextInfo,e); string resourcename = e.CreatedResources.ToString(); string ru = e.CreatedResources.GetValue(0).ToString(); Guid siteguid = contextInfo.SiteGuid; string pwaurl = new wss.SPSite(siteguid).Url; // int eventId = 7777; LookUpTable1.LookupTableMultiLangDataSet lds = new ClassLibrary1.LookUpTable1.LookupTableMultiLangDataSet(); // LookUpTable1.LookupTableDataSet.LookupTableTreesRow lrow = lds.LookupTableTrees.NewLookupTableTreesRow(); LookUpTable1.LookupTableMultiLangDataSet.LookupTablesRow lrow = lds.LookupTables.NewLookupTablesRow(); PSLibrary.Filter lookupfilter = new Microsoft.Office.Project.Server.Library.Filter(); lookupfilter.FilterTableName = lds.LookupTables.TableName; //lookupfilter.Fields.Add(new PSLibrary.Filter.Field(lds.LookupTables.TableName,lds.LookupTables.LT_NAMEColumn.ColumnName,PSLibrary.Filter.SortOrderTypeEnum.None)); //lookupfilter.Fields.Add(new PSLibrary.Filter.Field(lds.LookupTables.TableName,lds.LookupTables.LT_UIDColumn.ColumnName,PSLibrary.Filter.SortOrderTypeEnum.None)); PSLibrary.Filter.FieldOperator existinglookup = new Microsoft.Office.Project.Server.Library.Filter.FieldOperator(PSLibrary.Filter.FieldOperationType.Equal,lds.LookupTables.LT_NAMEColumn.ColumnName," projectManager" ); lookupfilter.Criteria = existinglookup; string lookupxml = lookupfilter.GetXml(); lds = l.ReadLookupTablesMultiLang(lookupxml,false); Resourcewe.ResourceDataSet resourceDs = new ClassLibrary1.Resourcewe.ResourceDataSet(); PSLibrary.Filter resourceFilter = new Microsoft.Office.Project.Server.Library.Filter(); resourceFilter.FilterTableName = resourceDs.Resources.TableName; //resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName,resourceDs.Resources.RES_UIDColumn.ColumnName,PSLibrary.Filter.SortOrderTypeEnum.None)); //resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName,resourceDs.Resources.RES_GROUPColumn.ColumnName,PSLibrary.Filter.SortOrderTypeEnum.None)); PSLibrary.Filter.FieldOperator existingResource = new Microsoft.Office.Project.Server.Library.Filter.FieldOperator(PSLibrary.Filter.FieldOperationType.Equal,resourceDs.Resources.RES_NAMEColumn.ColumnName,resourcename); resourceFilter.Criteria = existingResource; String filterXml = resourceFilter.GetXml(); resourceDs = r.ReadResources(filterXml,false); String groupname = resourceDs.Resources [0] .RES_GROUP; lookupguid [0] = lds.LookupTables [0] .LT_UID; if(groupname ==" Project Managers") { LookUpTable1.LookupTableMultiLangDataSet.LookupTableStructuresRow lutStructureRow = lds.LookupTableStructures.NewLookupTableStructuresRow(); lutStructureRow.LT_UID = lookupguid [0]; lutStructureRow.LT_STRUCT_UID = Guid.NewGuid(); lds.LookupTableStructures.Rows.Add(lutStructureRow); LookUpTable1.LookupTableMultiLangDataSet.LookupTableValuesRow lutValueRow = lds.LookupTableValues.NewLookupTableValuesRow(); lutValueRow.LCID = 1033; lutValueRow.LT_VALUE_DESC ="这是根标签A" ;; lutValueRow.LT_VALUE_DUR = 30; lutValueRow.LT_VALUE_DUR_FMT =(byte)PSLibrary.Task.DurationFormat.Hour; lutValueRow.LT_STRUCT_UID = lutStructureRow.LT_STRUCT_UID; lutValueRow.LT_UID = lutStructureRow.LT_UID; lds.LookupTableValues.Rows.Add(lutValueRow); bool validateOnly = false; bool autoCheckIn = true; l.UpdateLookupTablesMultiLang(lds,validateOnly,autoCheckIn); //lrow.LT_UID = new Guid(); //lrow.LT_STRUCT_UID = new Guid(); //lrow.SetLT_PARENT_STRUCT_UIDNull(); //lrow.LT_VALUE_TEXT = resourcename; //lrow.LT_VALUE_SORT_INDEX =(byte)PSLibrary.LookupTables.SortOrder.Ascending; } } } }   解决方案 Hey Nitin, 问题是什么?你有没有注册这个活动&验证代码无效..或抛出异常?    Hi all,Scenario:- On recource created i want enter resouce name in a look up table called "projectManager"incase resource belongs to projectmanager group...Please check code and suggest me using System;using System.Collections.Generic;using System.Linq;using System.Text;using PSLibrary=Microsoft.Office.Project.Server.Library;using Microsoft.Office.Project.Server.Events;using wss=Microsoft.SharePoint;namespace ClassLibrary1{ public class Resource : ResourceEventReceiver { public static Resourcewe.Resource r = new ClassLibrary1.Resourcewe.Resource(); public static LookUpTable1.LookupTable l = new ClassLibrary1.LookUpTable1.LookupTable(); Guid[] lookupguid; public override void OnCreated(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo, ResourceCreatePostEventArgs e) { base.OnCreated(contextInfo, e); string resourcename = e.CreatedResources.ToString(); string ru = e.CreatedResources.GetValue(0).ToString(); Guid siteguid = contextInfo.SiteGuid; string pwaurl = new wss.SPSite(siteguid).Url; //int eventId = 7777; LookUpTable1.LookupTableMultiLangDataSet lds = new ClassLibrary1.LookUpTable1.LookupTableMultiLangDataSet(); // LookUpTable1.LookupTableDataSet.LookupTableTreesRow lrow = lds.LookupTableTrees.NewLookupTableTreesRow(); LookUpTable1.LookupTableMultiLangDataSet.LookupTablesRow lrow=lds.LookupTables.NewLookupTablesRow(); PSLibrary.Filter lookupfilter = new Microsoft.Office.Project.Server.Library.Filter(); lookupfilter.FilterTableName = lds.LookupTables.TableName; //lookupfilter.Fields.Add(new PSLibrary.Filter.Field(lds.LookupTables.TableName, lds.LookupTables.LT_NAMEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None)); //lookupfilter.Fields.Add(new PSLibrary.Filter.Field(lds.LookupTables.TableName, lds.LookupTables.LT_UIDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None)); PSLibrary.Filter.FieldOperator existinglookup = new Microsoft.Office.Project.Server.Library.Filter.FieldOperator(PSLibrary.Filter.FieldOperationType.Equal, lds.LookupTables.LT_NAMEColumn.ColumnName, "projectManager"); lookupfilter.Criteria = existinglookup; string lookupxml = lookupfilter.GetXml(); lds = l.ReadLookupTablesMultiLang(lookupxml, false); Resourcewe.ResourceDataSet resourceDs=new ClassLibrary1.Resourcewe.ResourceDataSet(); PSLibrary.Filter resourceFilter = new Microsoft.Office.Project.Server.Library.Filter(); resourceFilter.FilterTableName = resourceDs.Resources.TableName; //resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_UIDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None)); //resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_GROUPColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None)); PSLibrary.Filter.FieldOperator existingResource = new Microsoft.Office.Project.Server.Library.Filter.FieldOperator(PSLibrary.Filter.FieldOperationType.Equal, resourceDs.Resources.RES_NAMEColumn.ColumnName, resourcename); resourceFilter.Criteria = existingResource; String filterXml = resourceFilter.GetXml(); resourceDs = r.ReadResources(filterXml, false); String groupname = resourceDs.Resources[0].RES_GROUP; lookupguid[0] = lds.LookupTables[0].LT_UID; if (groupname == "Project Managers") { LookUpTable1.LookupTableMultiLangDataSet.LookupTableStructuresRow lutStructureRow = lds.LookupTableStructures.NewLookupTableStructuresRow(); lutStructureRow.LT_UID = lookupguid[0]; lutStructureRow.LT_STRUCT_UID = Guid.NewGuid(); lds.LookupTableStructures.Rows.Add(lutStructureRow); LookUpTable1.LookupTableMultiLangDataSet.LookupTableValuesRow lutValueRow = lds.LookupTableValues.NewLookupTableValuesRow(); lutValueRow.LCID = 1033; lutValueRow.LT_VALUE_DESC = "This is root label A"; lutValueRow.LT_VALUE_DUR = 30; lutValueRow.LT_VALUE_DUR_FMT = (byte)PSLibrary.Task.DurationFormat.Hour; lutValueRow.LT_STRUCT_UID = lutStructureRow.LT_STRUCT_UID; lutValueRow.LT_UID = lutStructureRow.LT_UID; lds.LookupTableValues.Rows.Add(lutValueRow); bool validateOnly = false; bool autoCheckIn = true; l.UpdateLookupTablesMultiLang(lds, validateOnly, autoCheckIn); //lrow.LT_UID = new Guid(); //lrow.LT_STRUCT_UID = new Guid(); //lrow.SetLT_PARENT_STRUCT_UIDNull(); //lrow.LT_VALUE_TEXT = resourcename; //lrow.LT_VALUE_SORT_INDEX = (byte)PSLibrary.LookupTables.SortOrder.Ascending; } } }}  解决方案 Hey Nitin,What is the issue? Did you register the event & verified that code is not working ..or throwing exceptions?   这篇关于Event Handler 2007中的问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-16 01:48