2012-06-14 46 views
0

我在Silverlight控件中工作,我需要從XML文件同步上傳一些靜態數據。該文件位於同一個Web服務器中。我能得到的URI的控制,像這樣:從Silverlight控件導航URL

HtmlPage.Document.DocumentUri.ToString(); 

與顯示控制包容性的查詢返回的URI:

http://example.com:8085/MyWeb/CustomPage.aspx?waid=a1a5780a8ddea6c517ae1-b4ef&nid=id78 

我從需要的只有http://example.com:8085/MyWeb(這將永遠除了主機名/端口相同外)我不想硬編碼,因爲這將部署在多個服務器上。所以,我想要做的是獲得網站的URI。我在DocumentUri對象中嘗試了幾個東西,如localpath,host,AbsolutePath和其他東西,但沒有一個能夠給我所需要的東西。我怎麼能做到這一點,而不需要大量的操縱。 謝謝!

回答

1

嘗試以下操作:

var absoluteUri = Application.Current.Host.Source.AbsoluteUri; 
int lengthWithoutParams = absoluteUri.IndexOf("?") < 0 ? absoluteUri.Length : absoluteUri.IndexOf("?"); 
string uploadUrl = absoluteUri.Substring(0, lengthWithoutParams).Replace("/ClientBin/<YourXAPfile>.xap", filePath); 

最後:

HtmlPage.Window.Navigate(new Uri(uploadUrl)); 
0

嘗試:

System.Windows.Browser.HtmlPage.Window.Navigate(new Uri("urlString"));