手上有支別人寫的.NET匯入程式時,其中資料來源在config中設定,原本是用相對位置:

<appSettings>
<
add key="DataPath" value="../../Data/"/>
</appSettings>

我把它調成包含磁碟機名稱的絕對路徑:

<appSettings>
<
add key="DataPath" value="X:/Source/Current&History/Data/"/>
</appSettings>

這一調可不得了,程式完全無法執行,並出現以下訊息!

An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in system.dll
Additional information: This is an unexpected token. The expected token is 'SEMICOLON'. Line 38, position 63.

我一開始以為是多了磁碟機代號跟分號(X:)的緣故,找了一陣子才發現問題出在&符號上,要改成&amp;才會過關。這個限制也適用於<a href="blah.aspx?a=1&amp;b=2">上,如果href的內容要自己組裝,記得用UrlEncode。

<appSettings>
<
add key="DataPath" value="X:/Source/Current&amp;History/Data/"/>
</appSettings>

XML Attribute不能直接標示特殊字元的問題,之前就處理過,沒想到時間一久已忘得一乾二淨,看來中年人搞IT的挑戰性的確比較高。


Comments

# by

無意間找資料找到你這來,覺得很棒,一定要留個言,回應一下

# by Jeffrey

晃先生,感謝您的鼔勵! 深夜剛Post完文章又看到這樣的留言,頓時又精神百倍起來了,呵~~~

Post a comment