设为首页 收藏本站
查看: 1285|回复: 0

[经验分享] 再asp.net中实现sharepoint里面调用outlook address book的功能

[复制链接]

尚未签到

发表于 2015-9-13 10:50:47 | 显示全部楼层 |阅读模式
  我们可以利用COM Component  SpreadsheetLauncher和MsSvAbw.AddrBoookWrapper实现再asp.net Webpage中调用outlook 地址簿

DSC0000.gif <HEAD>
        <title>Default</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
DSC0001.gif DSC0002.gif         <SCRIPT language="VBScript"> DSC0003.gif
DSC0004.gif             Function OpenABW()
            
                'define local variables used in this method
                Dim objAddrBkWrap
                Dim objContacts
                Dim objABWOp
                Dim objContact
               
                'Initialize variables for the messages displayed to the user during the contact importing process
                const L_NeedSharePointAddrBook_Text = "To import contacts, you must have an Address Book compatible with Windows SharePoint Services and you must have Internet Explorer 5.0 or greater."
                const L_SelectUsers_Text = "Select Users to Import 选择用户"
                const L_Add_Text = "Add 添加"
               
                'Initialize the return value to an be an emptystring
                OpenABW = ""
               
                'Turn on our simple error handling (which is essentially disabling errors from being raised to the browser)
                On Error Resume Next

                'Create an instance of the Sharepoint Address Book Import component, which is defined in Msosvabw.dll               
                Set objAddrBkWrap = CreateObject("MsSvAbw.AddrBookWrapper")               


                If not IsObject(objAddrBkWrap) then
                    
                    'We don't have a valid object, so tell the user the import couldn't be performed
                    MsgBox L_NeedSharePointAddrBook_Text
                    OpenABW = ""

                Else
                    
                    'Using the new Sharepoint Address Book Import object, prompt the user to select some entries (Contacts)
                    'which are returned in the objContacts collection variable
                    'objABWOp = objAddrBkWrap.AddressBook(, 1, , , , objContacts, , , True)
                    objABWOp = objAddrBkWrap.AddressBook(L_SelectUsers_Text&"", 1, L_Add_Text&"", "", "", objContacts, Nothing, Nothing, True)
                    
                    'Display the list of selected Address Book Entries - for debugging purposes                    
                    'call window.alert("objContacts.count: " + cstr(objContacts.count))
                    
                    'if we have a valid return value from the previous method, then process the selections
                    If objABWOp <> 0 then
                        OpenABW = ""
                    Else
                        'Process the selected Address Book Entries by iterating through them and building an XML document
                        'containing all of the selected Contacts and their information.  
                        OpenABW = ProcessABWCollection(objContacts)
                    End If
                        
                End If

                'turn off our "On Error Resume Next" error handling
                On Error GoTo 0
            End Function


            Function EnsureImport()
                'This method creates an instance of the SharePoint.SpreadsheetLauncher component to ensure the
                'presence and availability of the component

                Dim objEnsureImport

                'Initialize the return value to false (0)                  
                EnsureImport = 0
                    
                'Turn on our simple error handling (which is essentially disabling errors from being raised to the browser)
                On Error Resume Next
                    
                'The Sample in the SDK indicates that you should use the ProgID "SharePoint.SpreadsheetLauncher.1"
                'however, WSS clearly uses the ProgID without specifying the version number.
                'Set objEnsureImport = CreateObject("SharePoint.SpreadsheetLauncher.1")
                Set objEnsureImport = CreateObject("SharePoint.SpreadsheetLauncher")

                'Return whether or not we can do the import               
                if not IsObject(objEnsureImport) then
                    EnsureImport = -1
                else
                    objEnsureImport.EnsureImport()
                end if
                    
                'turn off our "On Error Resume Next" error handling
                On Error GoTo 0
            End Function
DSC0005.gif         </SCRIPT>
        <SCRIPT language="JavaScript">   
                                                   
            function btnSelectContacts_Click()
DSC0006.gif DSC0007.gif             {
                ImportFromAddressBook();
DSC0008.gif             }

            function ImportFromAddressBook()   
            {
                var strXMLContacts = "";
            
                //Verify that the Sharepoint Address Book (Contact) Import components are installed and available
                if (EnsureImport() == 0)   
                {
                    //Now prompt the user to select Address Book Entries and conver their selections into an XML structure
                    strXMLContacts = DoImportFromAddressBook();
                /**/                        
                        Form1.xmlContacts.value = strXMLContacts;
                        Form1.submit();
                }
            }
            
            function DoImportFromAddressBook()   
            {
                //Simple call the OpenABW (ABW - Address Book Wrapper) and return the XML data string containing all of
                //the data for the selected Address Book Entries (contacts)        
                return OpenABW();            
            }

               
            function ProcessABWCollection(col)   
            {
                try
                {
                    
                    //Define a string array containing a list of all of the Property names for working with a Contact object
                    var rgstProps  = new Array("FirstName", "LastName", "SMTPAddress", "CompanyName", "JobTitle", "HomeTelephoneNumber",
                        "BusinessTelephoneNumber", "MobileTelephoneNumber", "BusinessFaxNumber", "BusinessAddressStreet",
                        "BusinessAddressCity", "BusinessAddressState", "BusinessAddressPostalCode", "BusinessAddressCountry", "Body");
                        
                    //Also, define a string array containing a list of all the Field names for a contact
                    //NOTE:  These could be different values, but the positions of items in this array need to match up
                    //with the Properties array
                    var rgstFields = new Array("FirstName", "Title", "Email", "Company", "JobTitle", "HomePhone", "WorkPhone", "CellPhone",
                        "WorkFax", "WorkAddress", "WorkCity", "WorkState", "WorkZip", "WorkCountry", "Comments");

                    //define the member variables for this method
                    var st;
                    var objContactItem;
                    var result="";
                           
                    //Get a new Enumerator object for working with the passed collection of Address Book Entries (contacts)        
                    var e = new Enumerator(col);

                    //If there were no items selected, then simply return
                    if (e.atEnd())
                    {            
                        return "";
                    }
                    
                    for (; !e.atEnd(); e.moveNext())
                    {
                        objContactItem = e.item();
                        result=result+objContactItem.SMTPAddress+";";
                    }
                    return result;
        /**/
                }        
                catch (excp)
                {
                    window.alert("An error occured processing the list of selected Address Book Entries (contacts).");
                    return null;
                }        
            }
        </SCRIPT>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 72px" runat="server"
                TextMode="MultiLine" Width="536px" Height="120px"></asp:TextBox>
            <INPUT id="btnSelectContacts" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 16px"
                onclick="javascript:return btnSelectContacts_Click();" type="button" value="Select Contacts">
            <INPUT ID="xmlContacts" runat="server" type="hidden" name="xmlContacts" style="Z-INDEX: 103; LEFT: 288px; POSITION: absolute; TOP: 24px">
        </form>
    </body>
</HTML>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-112962-1-1.html 上篇帖子: Web版OutLook,利用POP接收邮件服务器邮件 下篇帖子: outlook 中添加 yahoo邮箱
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表