0

我的图像有问题 我有一个图像,它位于“C:\Mh\mahesh1”之类的根目录中,并尝试通过以下方式上传,但无法正常工作。

Defaults.aspx.cs 
namespace UITI
{
  public partial class _Default : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
        string img = MapPath("~Mh/mahesh1.jpg");
        myimages.ImageUrl = img;
    }
   }
 }

 Defaults.aspx
 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"           Inherits="UITI._Default" %>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 <html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
 <title>Untitled Page</title>
 </head>
 <body>
 <form id="form1" runat="server">
 <div>
 <asp:Image ID="myimages" runat="server"  BorderStyle="Double" />
 </div>
 </form>
 </body>
 </html>

我也尝试过 Default.aspx.cs 页面,例如:

namespace UITI
{
  public partial class _Default : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
        string img = ResolveClientUrl ("~/Mh/mahesh1.jpg");   
        myimages.ImageUrl = img;
    }
  }
 }

怎么做?。

4

1 回答 1

0

试试看

string img = Server.MapPath("~/Mh/mahesh1.jpg");
    myimages.ImageUrl = img;

或者

编辑

string img = ResolveUrl("~/Mh/mahesh1.jpg");

myimages.ImageUrl = img;

如果它不起作用,请检查您的文件夹路径(~/Mh/mahesh1.jpg)。你的路径不正确。我上面的代码对我有用

新编辑

string img = **ResolveUrl("mahesh1.jpg");**

myimages.ImageUrl = img;

先看看 试试这个直接把正确的网址

**myimages.ImageUrl = @"~/Mh/mahesh1";**

问题在这里: 您的 mahesh1 图像位于任何其他文件夹中(对于项目文件夹或任何其他驱动器或桌面)。所以您遇到了这个问题。您可以使用任何其他图像。或将您的 mahesh1 重命名为 mahes123(如果您喜欢名称)图像,然后检查。

于 2013-03-07T07:45:22.923 回答