再asp.net中实现sharepoint里面调用outlook address book的功能

 我们可以利用COM Component  SpreadsheetLauncher和MsSvAbw.AddrBoookWrapper实现再asp.net Webpage中调用outlook 地址簿 

<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">
        
<SCRIPT language="VBScript">
            
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, NothingNothingTrue)
                    
                    
'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
        
</SCRIPT>
        
<SCRIPT language="JavaScript">   
                                                    
            
function btnSelectContacts_Click()
            
{
                ImportFromAddressBook();
            }


            
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>

posted on 2005-09-23 09:36  zz  阅读(987)  评论(0编辑  收藏  举报

导航