我有一个图像存储在服务器上的位置:
C:\inetpub\wwwroot\imageupload\images
在我的代码中,我想使用文件夹图像中的图像,所以我尝试如下:
Server.MapPath("/images/sample1.jpg")
但我得到的错误是:
请帮我解决错误
关于要求发布代码的几个答案,如下所示
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Assembly="CS.Web.UI.CropImage" Namespace="CS.Web.UI" TagPrefix="cs" %>
<!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>
<cs:CropImage ID="wci1" runat="server" />
</body>
</html>
.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
wci1.Crop(Server.MapPath("/imageupload/images/sample1.jpg"));
/*
this part is just to show the image after its been cropped and saved! so focus on just the code above.
*/
Image img = new Image();
img.ImageUrl = "images/sample1.jpg?rnd=" + (new Random()).Next(); // added random for caching issue.
this.Controls.Add(img);
}
}