本文介绍了无法在类中访问FileUpload控件的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I am writting a class to do the file upload, I can not access the property 'FileName' and method 'SaveAs', and this is the error:
<b>"RoomBooking.FileUpload' does not contain a definition for 'FileName' and no extension method 'FileName' accepting a first argument of type 'RoomBooking.FileUpload' could be found (are you missing a using directive or an assembly reference?)"</b>
I can do this task in a normal aspx page without any error, and works perfectly. But does not work in a class. I need to perform more tasks after user click upload, that's why I put in a class.
<b>This is my code:</b>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace RoomBooking.Business
{
public class UploadFiles
{
public static string GetPath()
{
string strPath = HttpContext.Current.Server.MapPath("~/UploadFiles/");
return strPath;
}
public static void Upload(FileUpload FileUpload1)
{
string strFileName = FileUpload1.FileName;
string strFilePath = HttpContext.Current.Server.MapPath("~/UploadFiles/") + strFileName;
FileUpload1.SaveAs(strFilePath);
}
}
}
谢谢
Thanks
推荐答案
public static void Upload(System.Web.UI.WebControls.FileUpload FileUpload1)
{
}
这篇关于无法在类中访问FileUpload控件的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!