zoukankan      html  css  js  c++  java
  • 给InfoPath添加VSTA托管代码并从SharePoint列表查询数据

    在Loading事件中参加如下的代码:
          if (this.New) //假如是新的表单,就配置原始值 
          { 
            //取得当前用户在配置文件中FullName的值 
            using (SPSite site = new SPSite("http://oss")) //请把这个值换成你的SharePoint站点的URL 
            { 
              //以下根据当前用户登录名来取得用户的配置文件 
              ServerContext context = ServerContext.GetContext(site); 
              UserProfileManager profileManager = new UserProfileManager(context);       
              UserProfile u = profileManager.GetUserProfile(this.Application.User.LoginName); 
              string fullName = u[PropertyConstants.PreferredName].Value.ToString(); 
     
              windows xp athNavigator mainNavigator = this.MainDataSource.CreateNavigator();  //取得主数据源的检索游标 
     
              //配置申请人的节点值为用户名,即配置文件中PreferredName(名称)的属性          
              mainNavigator.SelectSingleNode("/my:myFields/my:申请人", this.NamespaceManager).SetValue(fullName);  
              
              //根据姓名从SharePoint的部门列表来查询部门 
              using (SPWeb web = site.AllWebs["/demo"]) //请把这个换成你的SharePoint站点的URL 
              { 
                SPQuery query = new SPQuery(); 
                //因为姓名字段,是从标题修改而来的,所以其内部名称为Title 
                query.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + fullName + "</Value></Eq></Where>"; 
                SPList list = web.Lists["部门人员"]; 
                SPListItemCollection items = list.GetItems(query); 
                if (items.Count > 0) //假如查找到了就配置部门的值 
                  mainNavigator.SelectSingleNode("/my:myFields/my:申请部门", this.NamespaceManager).SetValue(items[0]["部门"].ToString ());  
     
              } 
     
            } 
          } 
        }
  • 相关阅读:
    vanilla单词的意思
    快速排序实现
    python下载一些包出现time out的问题解决
    神经网络浅讲:从神经网络到深度学习
    神经网络基础知识
    TCP/IP
    查找机器学习相关数据集
    [数据治理]
    【算法】——LRU
    【大数据开发工程师】面试——HBase
  • 原文地址:https://www.cnblogs.com/IsNull/p/1800925.html
Copyright © 2011-2022 走看看