日期:2014-05-20  浏览次数:20754 次

silverlight中HttpResponse
我要写一个单击按钮,提示一个提示框,上面有保存和打开,代码如下

 HttpResponse Response = HttpContext.Current.Response;

  Response.ContentType = "application/soap+msbin1";
  //通知浏览器下载文件
  Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("Excel文件", System.Text.Encoding.UTF8));
  Response.BinaryWrite(bytes);
  Response.Flush();
  Response.End();


为什么不对啊,老是提示错误,求指点

------解决方案--------------------
Silverlight是客户端的,不是服务器端的,没有Response.AddHeader

Response.AddHeader需要写到服务器端的asp.net中
------解决方案--------------------
不明白你要干什么
你可以使用SaveFileDialog 
http://www.silverlightshow.net/items/Using-the-SaveFileDialog-in-Silverlight-3.aspx


代码
XML code
<UserControl x:Class="FileSaveDialogDemo.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">  
    <Canvas x:Name="LayoutRoot" Background="White">  
        <Button x:Name="btnSaveFile" Width="100" Height="20" 
                Content="Save File" Click="btnSaveFile_Click" 
                Canvas.Top="10" Canvas.Left="10"></Button> 
        <TextBlock x:Name="tblError" Canvas.Top="40" Canvas.Left="10"></TextBlock> 
    </Canvas> 
</UserControl>