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

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

None.gif < HEAD >
None.gif        
< title > Default </ title >
None.gif        
< meta  name ="GENERATOR"  Content ="Microsoft Visual Studio .NET 7.1" >
None.gif        
< meta  name ="CODE_LANGUAGE"  Content ="C#" >
None.gif        
< meta  name ="vs_defaultClientScript"  content ="JavaScript" >
None.gif        
< meta  name ="vs_targetSchema"  content ="http://schemas.microsoft.com/intellisense/ie5" >
ExpandedBlockStart.gifContractedBlock.gif        
< SCRIPT  language ="VBScript" > dot.gif
InBlock.gif            
Function OpenABW()
InBlock.gif            
InBlock.gif                
'define local variables used in this method
InBlock.gif
                Dim objAddrBkWrap
InBlock.gif                
Dim objContacts
InBlock.gif                
Dim objABWOp
InBlock.gif                
Dim objContact
InBlock.gif                
InBlock.gif                
'Initialize variables for the messages displayed to the user during the contact importing process
InBlock.gif
                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."
InBlock.gif                
const L_SelectUsers_Text = "Select Users to Import 选择用户"
InBlock.gif                
const L_Add_Text = "Add 添加"
InBlock.gif                
InBlock.gif                
'Initialize the return value to an be an emptystring
InBlock.gif
                OpenABW = ""
InBlock.gif                
InBlock.gif                
'Turn on our simple error handling (which is essentially disabling errors from being raised to the browser)
InBlock.gif
                On Error Resume Next
InBlock.gif
InBlock.gif                
'Create an instance of the Sharepoint Address Book Import component, which is defined in Msosvabw.dll                
InBlock.gif
                Set objAddrBkWrap = CreateObject("MsSvAbw.AddrBookWrapper")                
InBlock.gif
InBlock.gif
InBlock.gif                
If not IsObject(objAddrBkWrap) then
InBlock.gif                    
InBlock.gif                    
'We don't have a valid object, so tell the user the import couldn't be performed
InBlock.gif
                    MsgBox L_NeedSharePointAddrBook_Text
InBlock.gif                    OpenABW 
= ""
InBlock.gif
InBlock.gif                
Else
InBlock.gif                    
InBlock.gif                    
'Using the new Sharepoint Address Book Import object, prompt the user to select some entries (Contacts)
InBlock.gif
                    'dot.gifwhich are returned in the objContacts collection variable
InBlock.gif
                    'objABWOp = objAddrBkWrap.AddressBook(, 1, , , , objContacts, , , True)
InBlock.gif
                    objABWOp = objAddrBkWrap.AddressBook(L_SelectUsers_Text&""1, L_Add_Text&"""""", objContacts, NothingNothingTrue)
InBlock.gif                    
InBlock.gif                    
'Display the list of selected Address Book Entries - for debugging purposes                    
InBlock.gif
                    'call window.alert("objContacts.count: " + cstr(objContacts.count))
InBlock.gif
                    
InBlock.gif                    
'if we have a valid return value from the previous method, then process the selections
InBlock.gif
                    If objABWOp <> 0 then
InBlock.gif                        OpenABW 
= ""
InBlock.gif                    
Else
InBlock.gif                        
'Process the selected Address Book Entries by iterating through them and building an XML document
InBlock.gif
                        'dot.gifcontaining all of the selected Contacts and their information.  
InBlock.gif
                        OpenABW = ProcessABWCollection(objContacts)
InBlock.gif                    
End If
InBlock.gif                        
InBlock.gif                
End If
InBlock.gif
InBlock.gif                
'turn off our "On Error Resume Next" error handling
InBlock.gif
                On Error GoTo 0
InBlock.gif            
End Function
InBlock.gif
InBlock.gif
InBlock.gif            
Function EnsureImport()
InBlock.gif                
'This method creates an instance of the SharePoint.SpreadsheetLauncher component to ensure the 
InBlock.gif
                'dot.gifpresence and availability of the component
InBlock.gif

InBlock.gif                
Dim objEnsureImport
InBlock.gif
InBlock.gif                
'Initialize the return value to false (0)                  
InBlock.gif
                EnsureImport = 0
InBlock.gif                    
InBlock.gif                
'Turn on our simple error handling (which is essentially disabling errors from being raised to the browser)
InBlock.gif
                On Error Resume Next
InBlock.gif                    
InBlock.gif                
'The Sample in the SDK indicates that you should use the ProgID "SharePoint.SpreadsheetLauncher.1"
InBlock.gif
                'dot.gifhowever, WSS clearly uses the ProgID without specifying the version number.
InBlock.gif
                'Set objEnsureImport = CreateObject("SharePoint.SpreadsheetLauncher.1")
InBlock.gif
                Set objEnsureImport = CreateObject("SharePoint.SpreadsheetLauncher")
InBlock.gif
InBlock.gif                
'Return whether or not we can do the import                
InBlock.gif
                if not IsObject(objEnsureImport) then
InBlock.gif                    EnsureImport 
= -1
InBlock.gif                
else
InBlock.gif                    objEnsureImport.EnsureImport()
InBlock.gif                
end if
InBlock.gif                    
InBlock.gif                
'turn off our "On Error Resume Next" error handling
InBlock.gif
                On Error GoTo 0
InBlock.gif            
End Function
ExpandedBlockEnd.gif        
</ SCRIPT >
ExpandedBlockStart.gifContractedBlock.gif        
< SCRIPT  language ="JavaScript" > dot.gif    
InBlock.gif                                                    
InBlock.gif            
function btnSelectContacts_Click()
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ImportFromAddressBook();
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
function ImportFromAddressBook()    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
var strXMLContacts = "";
InBlock.gif            
InBlock.gif                
//Verify that the Sharepoint Address Book (Contact) Import components are installed and available
InBlock.gif
                if (EnsureImport() == 0)    
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//Now prompt the user to select Address Book Entries and conver their selections into an XML structure
InBlock.gif
                    strXMLContacts = DoImportFromAddressBook();
ExpandedSubBlockStart.gifContractedSubBlock.gif                
/**/InBlock.gif                        
InBlock.gif                        Form1.xmlContacts.value 
= strXMLContacts;
InBlock.gif                        Form1.submit();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
function DoImportFromAddressBook()    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//Simple call the OpenABW (ABW - Address Book Wrapper) and return the XML data string containing all of 
InBlock.gif
                //dot.gifthe data for the selected Address Book Entries (contacts)        
InBlock.gif
                return OpenABW();            
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif                
InBlock.gif            
function ProcessABWCollection(col)    
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
try 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
InBlock.gif                    
//Define a string array containing a list of all of the Property names for working with a Contact object
InBlock.gif
                    var rgstProps  = new Array("FirstName""LastName""SMTPAddress""CompanyName""JobTitle""HomeTelephoneNumber"
InBlock.gif                        
"BusinessTelephoneNumber""MobileTelephoneNumber""BusinessFaxNumber""BusinessAddressStreet"
InBlock.gif                        
"BusinessAddressCity""BusinessAddressState""BusinessAddressPostalCode""BusinessAddressCountry""Body");
InBlock.gif                        
InBlock.gif                    
//Also, define a string array containing a list of all the Field names for a contact
InBlock.gif
                    //NOTE:  These could be different values, but the positions of items in this array need to match up 
InBlock.gif
                    //dot.gifwith the Properties array
InBlock.gif
                    var rgstFields = new Array("FirstName""Title""Email""Company""JobTitle""HomePhone""WorkPhone""CellPhone"
InBlock.gif                        
"WorkFax""WorkAddress""WorkCity""WorkState""WorkZip""WorkCountry""Comments");
InBlock.gif
InBlock.gif                    
//define the member variables for this method
InBlock.gif
                    var st;
InBlock.gif                    
var objContactItem;
InBlock.gif                    
var result="";
InBlock.gif                            
InBlock.gif                    
//Get a new Enumerator object for working with the passed collection of Address Book Entries (contacts)        
InBlock.gif
                    var e = new Enumerator(col);
InBlock.gif
InBlock.gif                    
//If there were no items selected, then simply return
InBlock.gif
                    if (e.atEnd())
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{            
InBlock.gif                        
return "";
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
InBlock.gif                    
for (; !e.atEnd(); e.moveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        objContactItem 
= e.item();
InBlock.gif                        result
=result+objContactItem.SMTPAddress+";";
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
return result;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**/
ExpandedSubBlockEnd.gif                }
        
InBlock.gif                
catch (excp) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    window.alert(
"An error occured processing the list of selected Address Book Entries (contacts).");
InBlock.gif                    
return null;
ExpandedSubBlockEnd.gif                }
        
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        
</ SCRIPT >
None.gif    
</ HEAD >
None.gif    
< body  MS_POSITIONING ="GridLayout" >
None.gif        
< form  id ="Form1"  method ="post"  runat ="server" >
None.gif            
< asp:TextBox  id ="TextBox1"  style ="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 72px"  runat ="server"
None.gif                TextMode
="MultiLine"  Width ="536px"  Height ="120px" ></ asp:TextBox >
None.gif            
< INPUT  id ="btnSelectContacts"  style ="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 16px"
None.gif                onclick
="javascript:return btnSelectContacts_Click();"  type ="button"  value ="Select Contacts" >
None.gif            
< INPUT  ID ="xmlContacts"  runat ="server"  type ="hidden"  name ="xmlContacts"  style ="Z-INDEX: 103; LEFT: 288px; POSITION: absolute; TOP: 24px" >
None.gif        
</ form >
None.gif    
</ body >
None.gif
</ HTML >

转载于:https://www.cnblogs.com/musicz/archive/2005/09/23/242486.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值