2013-07-02 58 views
2

我在我的silverlight应用程序中调用了一个aspx页面,在目录上创建并注册一个txt文件。在silverlight中调用一个aspx页面,而不打开它

Uri ub = (new Uri(HtmlPage.Document.DocumentUri, "GenereInfos.aspx?&connexion=" + connexion + ";&id=" + this.Id)); 

     if (HtmlPage.IsPopupWindowAllowed) 
     { 
      HtmlPopupWindowOptions opt = new HtmlPopupWindowOptions(); 
      HtmlPage.PopupWindow(ub, "file", opt); 
     } 
     else 
     { 
      HtmlPage.Window.Navigate(ub); 
     } 

我必须去我的aspx页面生成我的txt文件,因为silverlight不允许它。

这里的问题是,会出现一个弹出窗口,或者页面将加载新的uri。

我想要的只是调用内部的ASP代码(完美的工作),而无需加载uri。

有没有办法做到这一点?

编辑: DGibbs的答案后,还有另外一个问题,现在:在那里

WShy我不能使用的GetResponse()?

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(new Uri 
        (HtmlPage.Document.DocumentUri, "GenereInfos.aspx?&connexion=" + connexion + ";&idPocedure=" + itmProcedure.IdProcedure)); 
      string response = new System.IO.StreamReader(req.GetResponse().GetResponseStream()).ReadToEnd(); 

这一点答案:Silverlight是asynchrnous,所以,我们不能说谁的GetResponse是同步的。

所以,叫我aspx页面的最佳方式,是使用Web客户端found here

+0

是它写在本地或远程目录? – screenmutt

+0

在本地,但我也可以选择一个远程目录(使用一个字符串就是我的aspx)。目前,我得到myDocuments文件夹来放置我的txt文件。 –

+0

[编写使用Silverlight一个文件](http://stackoverflow.com/questions/753646/can-i-write-a-file-on-the-clients-pc-using-silverlight) 如果此ISN你的最终目标,让我知道。 – screenmutt

回答

0

你可以只使用WebRequest

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri 
        (HtmlPage.Document.DocumentUri, "GenereInfos.aspx?&connexion=" + connexion + ";&id=" + this.Id)); 
string response = new System.IO.StreamReader(req.GetResponse() 
       .GetResponseStream()).ReadToEnd(); 
+0

这不会通过我的aspx页面。 –

+0

尝试编辑。我使用这个确切的代码来做同样的事情。 – DGibbs

+0

我不明白为什么我不能选择.GetResponse(),只有BeginGetResponse和EndGetResponse ... –

相关问题