轉貼:http://ttyp.cnblogs.com/archive/2005/06/01/165621.html
一般我們使用這個treeview控制項時都是在虛擬目錄下複製webctrl_client目錄到預設網站的根目錄下,其實這對開發人員只是很簡單的一個步驟,但是在打包部署的時候確碰到了問題,假設你的網站是安裝在虛擬目錄下,你怎麼使你的安裝程式自動複製這個目錄到相應的地方去呢,這是個問題.於是google,下載了http://www.microsoft.com/china/MSDN/library/archives/library/DNAspp/html/aspnet-usingtreeviewieWebcontrol.asp裡wencontrols的代碼並安裝,查看treeview.cs,終於找到主要是AddPathToFilename這個函數來控制目錄得,而這個函數在BaseRichControl.cs的抽象類別裡定義
// --------------------------------------------------------------------
// Common Files
// --------------------------------------------------------------------
/**//// <summary>
/// Adds the common file path to the filename.
/// </summary>
/// <param name="filename">The filename to qualify with the common path.</param>
/// <returns>The full path of the filename with the common path.</returns>
protected string AddPathToFilename(string filename)
{
return AddPathToFilename(Context, filename);
}
/**//// <summary>
/// Static version of AddPathToFilename so that classes not deriving from
/// BaseRichControl can still find the common files path.
/// </summary>
/// <param name="context">The context from which to get the configuration.</param>
/// <param name="filename">The filename to qualify with the common path.</param>
/// <returns>The full path of the filename with the common path.</returns>
internal static string AddPathToFilename(HttpContext context, string filename)
{
return FindCommonPath(context) + filename;
}
/**//// <summary>
/// Finds the path for client files used be server controls.
/// </summary>
/// <param name="context">The context from which to get the configuration.</param>
/// <returns>The path name.</returns>
private static string FindCommonPath(HttpContext context)
{
// Look at the current configuration for the path
if (context != null)
{
NameValueCollection table = (NameValueCollection)context.GetConfig(ConfigName);
if (table != null)
{
string path = (string)table[CommonFilesKey];
if (path != null)
{
return CleanupPath(path);
}
}
}
// Return the default path with version number
Assembly assembly = typeof(BaseRichControl).Assembly;
Version version = assembly.GetName().Version;
return DefaultCommonFilesRoot + version.Major.ToString() + "_" + version.Minor.ToString() + "/";
}
,本來開始的想法是改這個函數,後來發現其實它還有個可配置的路徑介面,還是先配置吧!
於是在web.config加入以下節
<configSections>
<section name="MicrosoftWebControls" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<MicrosoftWebControls>
<add key="CommonFiles" value="/web/treepath/"></add>
</MicrosoftWebControls>
注意:configSections一定要放在第一個子節最前面.
剪下預設網站的webctrl_client目錄到虛擬目錄web/treepath/下,運行程式,樹型介面出現了,只是前面的加減號出現問題,再右鍵查看WEB代碼,發現SystemImagesPath屬性還是指到webctrl_client目錄下,看了SystemImagesPath的代碼,把treeview控制項的SystemImagesPath設定為空白,再次運行程式,OK!全部通過,treeview的圖片目錄再也不需要依賴預設網站的圖片目錄了,打包也變的方便了,如果是幾個網站在一個機器上,你也可以設定自己獨立的treeview圖片風格了,嘿嘿,再此寫下這些供大家參考
----------------------------------------
實驗了,果然好用,不過有個問題是,打包安裝後還要修改web.config檔案,感覺有些麻煩。如果需要修改,還不如安裝後,將webctrl_client\1_0直接拷貝到web的根節點上呢