2010-12-11 58 views
0

我想添加一個額外的需要幫助使用C#正則表達式

ASP插入標記標籤之間的內容:基於控件ID的SiteMapDataSource

標記標籤在委派控制之間= 「TopNavigationDataSource」。

我需要幫助,使用C#正則表達式來添加這個特定的標記。

這將是輸入

<的SharePoint:DelegateControl RUNAT = 「服務器」 控件ID = 「TopNavigationDataSource」>

<Template_Controls> 
     < asp:SiteMapDataSource 
      ShowStartingNode="False" 
      SiteMapProvider="SPNavigationProvider" 
      id="topSiteMap" 
      runat="server" 
      StartingNodeUrl="sid:1002"/ > 
    </Template_Controls> 
</SharePoint:DelegateControl> 

缺貨穿戴應..

< SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" > 
    <Template_Controls> 
     < asp:SiteMapDataSource 
      ShowStartingNode="True" 
      SiteMapProvider="MyCustomNavigationProvider" 
      id="customSiteMap" 
      runat="server"/ > 
     < asp:SiteMapDataSource 
      ShowStartingNode="False" 
      SiteMapProvider="SPNavigationProvider" 
      id="topSiteMap" 
      runat="server" 
      StartingNodeUrl="sid:1002"/ > 
    </Template_Controls> 
</SharePoint:DelegateControl> 

注意:我不能使用任何第三方/免費的dll。

什麼是最好的,以實現這一目標任務..

任何幫助,將不勝感激..

感謝 迪普

回答

0

如果你絕對需要使用正則表達式,你可以這樣做像:

yourMarkup = new Regex(@"\< SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" \>\s*\< Template_Controls \>\s*\< asp:SiteMapDataSource") 
    .Replace(yourMarkup, @"< SharePoint:DelegateControl runat=""server"" ControlId=""TopNavigationDataSource"" > 
    <Template_Controls> 
     < asp:SiteMapDataSource 
      ShowStartingNode=""True"" 
      SiteMapProvider=""MyCustomNavigationProvider"" 
      id=""customSiteMap"" 
      runat=""server""/ > 
     < asp:SiteMapDataSource"); 
+0

謝謝你Frederic ..但我有兩個委託控制在頁面中...這將做一個完整的替換..有沒有什麼辦法,我只能做一次基於委託控制的控制ID 。也有可能使用String.Replace來實現這一點嗎? – 2010-12-11 08:17:51

+0

@ user209291,您可以通過將'SharePoint:DelegateControl'添加到匹配表達式來爲正則表達式提供更多上下文。我相應地更新了我的答案。使用'String.Replace()'是可能的,但更復雜:空白變得重要,所以你必須確保你的標記格式與你的問題中的格式一致。 – 2010-12-11 08:26:56

+0

感謝您的支持 那麼有沒有關於白色空間bcoz內容將存儲在數據庫中的承授人。所以我只能堅持Regx。附加的標記添加是一些功能,用戶可以將其打開/關閉,因爲代碼適用於On場景。我怎麼把它關掉額外的標記。 謝謝 Deepu – 2010-12-11 13:49:14