2009-09-24 59 views
-4

问题是我设置图像URL单击lnkFV链接按钮。但图像不在页面上查看。
上传一个视图图像

<tr> 
    <td style="width: 160px; height: 15px"> 
     <asp:Label ID="Label4" runat="server" Text="Style Front View"> 
     </asp:Label> 
    </td> 
    <td style="width: 222px; height: 15px"> 
      <asp:FileUpload id="filFrontView" runat="server"> 
      </asp:FileUpload> 
    </td> 
    <td style="width: 72px; height: 15px"> 
      <asp:LinkButton id="lnkFV" runat="server" OnClick="lnkFV_Click"> 
      View image</asp:LinkButton> 
    </td> 
    <td colspan="3" rowspan="1"> 
     <asp:Image id="Image1" runat="server"> 
     </asp:Image></td> 
    </tr> 

ASP代码

protected void lnkFV_Click(object sender, EventArgs e) 
{ 
    // new Help().Perform("Do you really want to proceed"); 
    try 
    { 
     file = Path.GetFileName(filFrontView.PostedFile.FileName); 
     // file = Path.GetFileName(filFrontView.PostedFile.FileName); 
     tempF = "F:\\Visual Studio 2005\\User\\temp\\" + file; 
     temp = "~\\temp\\" + file; 
     filFrontView.SaveAs(Server.MapPath(temp)); 
     // filFrontView.SaveAs(temp); 
     string filePath = MapPath(temp); 
     Image1.ImageUrl = tempF; 
    } 
    catch (Exception ee) 
    { 
    } 
} 
+1

什么是错误? – 2009-09-24 12:45:47

+0

图像未查看。 – Suchinthaka 2009-09-24 12:47:59

+0

您使用的是ASP.NET Ajax吗?该文件是否正确保存?你是否遇到异常?需要更多细节。 – 2009-09-24 12:49:08

回答

3

这是你的问题?

tempF = "F:\\Visual Studio 2005\\User\\temp\\" + file; 
// ... other stuff ... 
Image1.ImageUrl = tempF; 

它看起来像你设置ImageUrl属性为一个字符串,是本地计算机的图像的路径。对于没有在Web服务器上运行浏览器的用户来说,这不起作用。 ImageUrl应该可能是图像的相对路径,相对于当前页面或Web应用程序的虚拟根目录。

页面最终呈现时,HTML源代码的外观如何?

您还必须确保将该图像保存到可通过网络访问的文件夹中。 F:\Visual Studio 2005\User\temp文件夹似乎不太适合这里的账单。一般来说,如果您希望自己的网站上可见的图片在您的网站上可见,我认为您会希望使用相对路径而不是硬编码这样的路径。