Silverlight获取SharePoint当前登录用户信息2008-10-27 14:35:51 来源:中国自学编程网 作者:佚名 点击:
如果要在部署到SharePoint里的Silverlight程序中获取当前登录SP的用户信息,可以直接调用宿主html页面中的javascript代码来实现: ![]() 如果要在部署到SharePoint里的Silverlight程序中获取当前登录SP的用户信息,可以直接调用宿主html页面中的javascript代码来实现: <listName>User Information List</listName><viewName></viewName><query><Query><Where> <Eq><FieldRef Name=\"ID\"/><Value Type=\"Counter\">{1}</Value></Eq></Where></Query> </query><viewFields><ViewFields><FieldRef Name=\"Name\"/></ViewFields></viewFields><rowLimit>1</rowLimit> <queryOptions><QueryOptions/></queryOptions><webID></webID></GetListItems>{2}",
soapPrefix, UserID, soapPostfix); // TODO: We need to dynamically generate the endpoint address using HtmlPage.Document.DocumentUri. // Send data to Sharepoint List WebClient client = new WebClient(); client.Headers["Content-Type"] = "text/xml; charset=utf-8"; client.Headers["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/GetListItems"; client.UploadStringCompleted += new UploadStringCompletedEventHandler(GetUserNameCompleted); client.UploadStringAsync(new Uri( "http://yewen/_vti_bin/Lists.asmx?op=GetListItems", UriKind.Absolute), request); // should be the root url of sharepoint } void GetUserNameCompleted(object sender, UploadStringCompletedEventArgs e) { if (e.Error == null) { XElement root = XElement.Parse( e.Result ); foreach (XElement element in root.Descendants("{#RowsetSchema}row")) { UserName = (string)element.Attribute("ows_Name"); GetGroups(); } } } private void GetGroups() { // Create the xml request for the list string request = String.Format("{0}<GetGroupCollectionFromUser xmlns=\"http://schemas.microsoft.com/sharepoint/soap/directory/\"><userLoginName>{1}</userLoginName></GetGroupCollectionFromUser>{2}", soapPrefix, UserName, soapPostfix); // TODO: We need to dynamically generate the endpoint address using HtmlPage.Document.DocumentUri. // Send data to Sharepoint List WebClient client = new WebClient(); client.Headers["Content-Type"] = "text/xml; charset=utf-8"; client.Headers["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/directory/GetGroupCollectionFromUser"; client.UploadStringCompleted += new UploadStringCompletedEventHandler(GetGroupsCompleted); client.UploadStringAsync(new Uri( "http://yewen/graceland/_vti_bin/UserGroup.asmx?op=GetGroupCollectionFromUser", UriKind.Absolute), request); } // BAD CODES HERE, Should replace with other ways void GetGroupsCompleted(object sender, UploadStringCompletedEventArgs e) { if (e.Error == null) {
|