无法在类中访问FileUpload控件的属性 [英] Can not access property of FileUpload control within a class

查看:84
本文介绍了无法在类中访问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

推荐答案

尝试如下,似乎你指的是错误的FileUpload

try like below, it seems you referring to wrong FileUpload
public static void Upload(System.Web.UI.WebControls.FileUpload FileUpload1)
{

}


这篇关于无法在类中访问FileUpload控件的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆