關於設定WebControls裡的treeview控制項的圖片路徑)

來源:互聯網
上載者:User
轉貼: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的根節點上呢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.