帮忙解决一下“Myweb.Manage.ProductEdit”不实现接口成员“Myweb.Components.IUploadFile.UploadImg(s
代码如下:接口定义用方法:
namespace
{
interface IUploadFile
{
// bool DelFile(string file);
string UploadImg(string UploadPath_s, System.Web.HttpPostedFile Upfile);
}
public class UploadFile : Page, IUploadFile
{
/// <summary>
/// 上传文件
/// </summary>
/// <param name="UploadPath_s">路径</param>
/// <param name="UploadType_s">类型</param>
/// <param name="kj">控件名</param>
/// <returns>imgurl</returns>
public string UploadImg(string UploadPath_s, HttpPostedFile Upfile)
{
string imgurl = "";
double upload_file_size = System.Configuration.ConfigurationManager.AppSettings["Upload_file_size"].ToFloat();
string UploadType = System.Configuration.ConfigurationManager.AppSettings["Upload_img_type"];
string UploadPath = UploadPath_s;
int len = Upfile.ContentLength;
if (len > 0)
{
if (len > 1024 * 1024 * upload_file_size)
{
return "size";
}
string filePath = Upfile.FileName;
string extname = filePath.Substring(filePath.LastIndexOf(".")).ToLower();
if (!UploadType.Contains(extname))
{
return "type";
}
string filename = string.Format("{0:yyyyMMddHHmmss}", DateTime.Now);
imgurl = UploadPath + filename + extname;//图片路径
if (!Directory.Exists(Server.MapPath("~/" + UploadPath)))
Directory.CreateDirectory(Server.MapPath("~/" + UploadPath)); //如果目录不存在则建立
string savepath = Server.MapPath("~/" + UploadPath) + filename + extname;
Upfile.SaveAs(savepath);
return imgurl;
}
return "";
}
}
}
接口调用:
public partial class ProductEdit : Base_Page, IUploadFile
{
#region 上传图片
private bool UploadImg()
{
IUploadFile U = new UploadFile();
string imgpath = U.UploadImg("UpLoadFile/Pro/", pic.PostedFile);
if (imgpath != null)
{
ViewState["ImgUrl"] = imgpath;
return true;
}
else
{
return false;
}
}
#endregion
}