• 总结:Sharepoint2010 Client Object Model 获得Sharepoint 网站当前用户


    方法一:用C# 代码,可以用于Silverlight

     

         public void GetCurrentUser()

            {

                ClientContext context = new ClientContext("http://localhost");

                Web site = context.Web;

     

                //context.Load(site);

                //context.ExecuteQuery();

     

                if (site != null)

                {

                    User user = site.CurrentUser;

     

                    context.Load(user);

                    context.ExecuteQuery();

     

                    string userName = user == null ? string.Empty : user.LoginName;

     

                    Console.WriteLine(userName);

                }

            }

     

    方法二:用ECMAScript Client Object Model

                   

                    <script type="text/javascript">

        ExecuteOrDelayUntilScriptLoaded(GetUser, "sp.js");

        var context = null;

        var site = null;

        var currentUser = null;

        function GetUser() {

            context = new SP.ClientContext.get_current();

            site = context.get_web();

            currentUser = web.get_currentUser();

            currentUser.retrieve();

            context.load(site);

            context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));

           

        }

        function onSuccessMethod(sender, args) {

            alert(site.get_currentUser());

        }

        function onFailureMethod(sender, args) {

            alert('failed');

        }

    </script>

  • 相关阅读:
    NO6 alias-unalias命令,递归创建目录,如何取消覆盖提示
    NO4 find&mv-&-特殊符号..和.
    NO5 grep-head-tail命令
    linux面试题:删除一个目录下的所有文件,但保留一个指定文件
    NO3 cat-xargs-cp-mv-rm-find命令
    Linux 快速删除已输入的命令
    NO2 pwd-touch-vim-vi-echo-重定向等命令
    NO1 ip-systemctl-fdisk
    SecureCRT:保存输出日志的方法
    WMware workstation 镜像文件
  • 原文地址:https://www.cnblogs.com/LeimOO/p/1911696.html
Copyright © 2020-2023  润新知