AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 26.08.2008, 11:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
Fred Shen: Add an AX user to be a memebr of Sharepoint site group
Источник: http://fredshen.spaces.live.com/Blog...E4E3!226.entry
==============

In AX 4.0, it is allowed to link an AX user to a particular Sharepoint site group from main menu -> Administration -> Users -> User relations button -> Web sites tab. Unfortunately, this is removed from AX 2009.
However, we can still add this feature back if we like by using X++.
 
The example below show how easy can add an AX user to Sharepoint site owner groups by using X++ and CLRInterop.
Before you run this job, please add Microsoft.Sharepoint.dll (WSS 3.0) as a reference on AOT if it is not registered in GAC.
You can find this dll in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI on the server that Enterprise Portal resides.
 
static void AddAXUserToSharepointGroup(Args _args)
{
    Microsoft.SharePoint.SPWeb              spWeb;
    Microsoft.SharePoint.SPSite             spSite;
    Microsoft.SharePoint.SPGroupCollection  spGroupCollection;
    Microsoft.SharePoint.SPGroup            spGroup;
    Microsoft.SharePoint.SPUserCollection   spUserCollection;
    Microsoft.SharePoint.SPUser             spUser;
    EPWebSiteParameters                     epWebSiteParameters;
    UserInfo                                userInfo;
    SysUserInfo                             sysUserInfo;
    str                                     loginName;
    System.Exception                        ex;
    str                                     siteGroupName;
    ;
   
    try
    {
        //Sharepoint site registered in AX2009
        select firstonly epWebSiteParameters;
        select firstonly userInfo
            where userInfo.id == curUserId();
        select firstonly sysUserInfo
            where sysUserInfo.Id == curUserId();

        loginName           = userInfo.networkDomain + @"\" + userInfo.networkAlias;
        spSite              = new Microsoft.SharePoint.SPSite(epWebSiteParameters.InternalUrl);
        spWeb               = spSite.get_RootWeb();

        //Create a user in Sharepoint
        spUserCollection    = spWeb.get_SiteUsers();
        spUserCollection.Add(loginName, sysUserInfo.Email, userInfo.name, "");

        //Add the user to a site owner group
        spUser              = spUserCollection.get_Item(loginName);
        spGroupCollection   = spWeb.get_SiteGroups();
        siteGroupName       = CLRInterop::getAnyTypeForObject(spWeb.get_Title()) + " Owners"; //Or Visitors, Members
        spGroup             = spGroupCollection.get_Item(siteGroupName);
        spGroup.AddUser(spUser);
        spGroup.Update();
    }
    catch (exception::CLRError)
    {
        ex = CLRinterop::getLastException();   
        if (ex)
        {
            info(ex.ToString());          
        }
    }
    catch (exception::Internal)           
    {
        ex = clrinterop::getLastException();       
        if (ex)
        {
            info(ex.ToString());           
        }
    }

}
 


Источник: http://fredshen.spaces.live.com/Blog...E4E3!226.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05
Inside Dynamics AX 4.0: The Security Framework Blog bot DAX Blogs 0 31.10.2007 11:40
Fred Shen: Consuming a Web Service in Dynamics AX 4 Blog bot DAX Blogs 0 28.10.2006 16:40
Fred Shen: RefRecID in Dynamics AX 4 Blog bot DAX Blogs 0 28.10.2006 16:40
Fred Shen: Development Features of Dynamics Ax (Axapta) 4.0 Blog bot DAX Blogs 0 28.10.2006 16:40

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 22:46.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.