我必須在我的Silverlight應用程序中打開並讀取一個xml文件。我不能把這個文件放在資源中(我的老師的意願)。我試圖用這個代碼:Silverlight,從外部應用程序包打開xml
XmlReader reader = XmlReader.Create("products.xml");
,但得到了一個錯誤:
Cannot find file 'products.xml' in the application xap package.
此xml文件目前位於旁邊調試文件夾中的.xap
我應該怎麼做,使之工作? (萬一)
XML文件:
<products>
<product>
<name>nameA</name>
<desc>descA</desc>
<image>imgA</image>
</product>
<product>
<name>nameB</name>
<desc>descB</desc>
<image>imgb</image>
</product>
<product>
<name>nameC</name>
<desc>descC</desc>
<image>imgC</image>
</product>
</products>
錯誤陷入了安東尼的代碼returnResult(args.Result);
:
System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid. Check InnerException for exception details. ---> System.Net.WebException: An exception occurred during a WebClient request. ---> System.NotSupportedException: The URI prefix is not recognized.
in System.Net.WebRequest.Create(Uri requestUri)
in System.Net.WebClient.GetWebRequest(Uri address)
in System.Net.WebClient.OpenReadAsync(Uri address, Object userToken)
--- The end of stack trace of inner exceptions (my translation) ---
in System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
in System.Net.OpenReadCompletedEventArgs.get_Result()
in ProjektAI.MainPage.<>c__DisplayClass1.<GetStreamFromUri>b__0(Object s, OpenReadCompletedEventArgs args)
如果這是家庭作業,您應該在其上安裝#homework標籤 –
Normal Silverlight僅支持讀取隔離存儲中的文件或使用OpenFileDialog –