2011-09-14 57 views

回答

1

我不确定你的意思,所以如果这不是你的问题的解决方案,请忽略此答案。

我假设你的意思是,你希望从URL中的代码隐藏下载的图像,存储在本地 形象,这一形象成为浏览器。

要做到这一点,你可以使用以下命令:

标记

<asp:Image ID="image1" runat="server" /> 

代码隐藏

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!IsPostBack) 
    { 
     string imageName = "downloaded-image.png"; 
     string imagePath = Path.Combine(Server.MapPath(@"~\Images"), imageName); 
     string imageUrl = "https://encrypted.google.com/images/logos/ssl_logo.png"; 

     WebClient client = new WebClient(); 
     client.DownloadFile(imageUrl, imagePath); 

     image1.ImageUrl = string.Format(@"~\Images\{0}", imageName); 
    } 
} 

希望这有助于。