• sharepoint调用webservice


    1、先添加webservice,引用webservice地址如:http://10.119.188.XXX:8080/_vti_bin/UserGroup.asmx 

    2、直接用jquery调用该服务中的其中一个,下面以GetUserCollectionFromGroup为例子,判断某一组里有哪些成员,代码如下:

    调用webservice
     1 <script type="text/javascript">
     2    function myrole()
     3      {
     4          var soapEnv = '<?xml version="1.0" encoding="utf-8"?>' +     
     5              ' <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' + 
     6              '    <soap:Body>'+             
     7              '       <GetUserCollectionFromGroup xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/">'+    
     8              '        <groupName>IT论坛-管理员</groupName>'+             
     9              '      </GetUserCollectionFromGroup>'+                  
    10              '    </soap:Body>'+                  
    11              '  </soap:Envelope>'; 
    12                //alert(myLoginName); 
    13                   var checkUser=0;
    14                      $.ajax({
    15                     type: "POST",   
    16                     contentType: "text/xml; charset=\"utf-8\"" , 
    17                     url: "/_vti_bin/UserGroup.asmx", 
    18                     data: soapEnv,             
    19                     dataType: 'xml',
    20                     success: function(result) { 
    21                     //debugger;
    22                     $(result.xml).find("User").each(function(){
    23                    // alert($(this).attr("Name"));
    24                    checkUser=1;
    25                       var username=$(this).attr("Name");
    26                       var alt_name="图片占位符: "+ username+" ";
    27                     $("a:contains('"+username+"')").each(function(){
    28                                     
    29                                     if($(this).attr("class")!="ms-menu-a")
    30                                         $(this).html("信息室");
    31                         });
    32                      $(".ms-disc-bordered td img").each(function(){
    33                                         if($(this).attr("alt")==alt_name)
    34                                         //alert("123");
    35                                     $(this).attr("src","images/systemadmin.png");                                                         
    36                         });
    37                    });    
    38                         
    39                         
    40                                },
    41                      error:function(s){
    42                      alert(s.responseText);
    43                          //alert("error");
    44                         }  
    45                           });    
    46                          
    47 
    48      }
    49 $(document).ready(function(){
    50 //myWeb();
    51   myrole();
    52 });
    53 </script>

    上面的代码是把组里的成员变成我想要的名称,如果不需要可以直接删去;但是该方法有局限性,就是用户必须得登录才可以拿到数据;

    下面为不用登录就能拿到的方法,方法比较土:

    不需登录
     1 <%
     2  string cName="";
     3  SPSecurity.RunWithElevatedPrivileges(delegate()
     4                 {
     5                     SPSite site = new SPSite(siteApp.SiteUrl);
     6                     SPWeb web = site.OpenWeb();
     7                     SPGroup gc = web.SiteGroups["IT论坛-管理员"];
     8                     SPUserCollection swer = gc.Users;
     9                     foreach (SPUser u in swer)
    10                     {
    11                         cName+= u.Name+"|";
    12                     }
    13                                  
    14                 });
    15 %>
    16 <script type="text/javascript">
    17  
    18 $(document).ready(function(){
    19  
    20    var checkuser=0;
    21    var username='<%=cName%>';
    22    var array=username.split("|");
    23     // $("a:contains('"+username+"')").each(function(){                                
    24                     //if($(this).attr("class")!="ms-menu-a")
    25                     //$(this).html("信息室");
    26                     //    });
    27     if(("_spUserId" in window))//判断用户是否登录
    28       {    
    29          $(".ms-disc-bordered td span").each(function(){
    30                  for(var i=0;i<array.length;i++)
    31                     {
    32                         if($(this).has('a').text()==array[i])
    33                             $(this).replaceWith("信息室");
    34                     }   
    35                     });  
    36         $(".ms-disc-bordered td img").each(function(){
    37                   for(var i=0;i<array.length;i++)
    38                     {
    39                     var alt_name="图片占位符: "+ array[i]+" ";
    40                          if($(this).attr("alt")==alt_name)
    41                             $(this).attr("src","images/systemadmin.png");
    42                     }                                           
    43                     });
    44           }
    45         else
    46          {
    47                  $(".ms-disc-bordered td span").each(function(){
    48                  for(var i=0;i<array.length;i++)
    49                     {
    50                         if($(this).text()==array[i])
    51                             $(this).replaceWith("信息室");
    52                     }   
    53                     });  
    54                $(".ms-disc-bordered td img").each(function(){
    55                   for(var i=0;i<array.length;i++)
    56                     {
    57                     var alt_name="图片占位符: "+ array[i]+" ";
    58                          if($(this).attr("alt")==alt_name)
    59                             $(this).attr("src","images/systemadmin.png");
    60                     }                                           
    61                     }); 
    62                      
    63          }
    64 
    65 });
    66 </script>

    直接在页面处理<%%>里的直接拿改组成员信息;

    如果有更好办法,欢迎评论共同学习!

     $(document).ready(function () {
                $(".myname").focus();
              
                //  alert("123");
                //登录框处理开始
                //加载登录状态
                            $.ajax({
                                type: "POST", //访问WebService使用Post方式请求
                                contentType: "application/json;charset=utf-8", //WebService 会返回Json类型
                                url: "/WebService/AutoComplete.asmx/datas", //调用WebService
                                data: "{}", //Email参数
                                dataType: 'json',
                                beforeSend: function (x) { x.setRequestHeader("Content-Type", "application/json; charset=utf-8"); },
                                error: function (x, e) { },
                                success: function (data) { //回调函数,result,返回值
                                    var msg = data.d;
                                 
                                    $(".myname").mouseover(function () {
    
                                        $(".name").val(msg);
    
                                    });
                                }
    
                            });
    
            });
           
    

      

  • 相关阅读:
    ios 常用的数学函数
    iOS已发布应用中对异常信息捕获和处理
    iOS 制作framework步骤
    iOS 静态库和动态库.a和framework
    C#实现发送和接收pop3邮件方法
    C#实现给手机发送短信
    C#DataTable DataSet DataRow区别详解
    gridview合并相同的行
    ASP.NET导出EXCEl方法使用EXCEl对象
    ASP.NET导出EXCEl方法使用COM.EXCEL不使用EXCEl对象
  • 原文地址:https://www.cnblogs.com/double2012/p/2688515.html
Copyright © 2020-2023  润新知