2009-06-26 10 views
6

私はonet.xmlでWebパーツ接続を指定する必要があります。したがって、このサイト定義を使用してサイトが作成されると、前記ウェブパーツは既に接続されて使用可能になります。 onet.xmlの特定のWebパーツに指定する必要があるプロパティサイト定義内のWebパーツ接続

答えて

3

私はまた、昨年、いつかこの壁にぶつかった!以前の.dwp形式と同じように、新しい.webpart形式のWebパーツで接続を指定できなくなったように見えます。私は、kpinhackのようなサイト定義のカスタム機能も含めて終わりました。 Webパーツを接続するための私のコードを以下に示します。このメソッドは、異なる種類の2つのWebパーツを接続するためのもので、同じページの同じ種類のWebパーツを複数サポートしていません。しかし、私はあなたが一般的なアイデアをキャッチすると確信しています。

private void ConnectWebParts(SPWeb web, string pageName, Type providerType, Type consumerType) 
{ 
    SPFile file = web.GetFile(pageName); 
    SPList list = null; 
    if (file.InDocumentLibrary) 
    { 
    list = file.Item.ParentList; 
    if (list.ForceCheckout) file.CheckOut(); 
    } 

    SPLimitedWebPartManager webPartManager = 
    web.GetLimitedWebPartManager(
     pageName, 
     System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared); 

    WebPart provider = null; 
    foreach (WebPart wp in webPartManager.WebParts) 
    { 
    if (wp.GetType() == providerType) 
    { 
     provider = wp; 
     break; 
    } 
    } 

    foreach (WebPart consumer in webPartManager.WebParts) 
    { 
    if (consumer.GetType() != consumerType) continue; 

    ProviderConnectionPointCollection providerConnections = webPartManager.GetProviderConnectionPoints(provider); 
    ProviderConnectionPoint providerConnection = providerConnections[0]; 

    ConsumerConnectionPointCollection consumerConnections = webPartManager.GetConsumerConnectionPoints(consumer); 
    ConsumerConnectionPoint consumerConnection = consumerConnections[0]; 

    SPWebPartConnection con = webPartManager.SPConnectWebParts(provider, providerConnection, consumer, consumerConnection); 
    webPartManager.SPWebPartConnections.Add(con); 
    } 

    if (list != null) 
    { 
    if (list.ForceCheckout) 
    { 
     file.CheckIn("Added Web Part Connections"); 
    } 

    if (list.EnableVersioning && list.EnableMinorVersions) 
    { 
     file.Publish("Added Web Part Connections"); 
    } 
    } 
} 
+0

フィーチャーコードを提供していただきありがとうございます。本当に助けになりました –

0

私は 'OnActivated'-Eventhandlerを実装することで、SiteProvisioning-FeatureでWebPartを設定します。こうすることで、ウェブサイトの作成時にコードが実行され、好きなようにエラーを処理できます(何らかの理由でウェブサイトを作成したときにWebPartを利用できない場合)。

+0

これは、サイト定義でのWebパーツ接続を提供するための唯一の方法ですか? onet.xmlにwebpart接続プロパティを指定することはできません。私はsharepoint 2003では、2つのWebパーツproeprtiesが "connectionid"と "connections"であったと思います。同じものを使うことはできませんか?もしそうなら、どのように? –

+0

はソリューションに感謝kpinhack。 –

0

あなたのWebパーツを宣言した後、同封<のWebPart>要素の中にあなたの接続を宣言する< AllUsersWebPart>タグを使用する必要があります。

example

関連する問題