⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upfile.ascx.cs

📁 网开商城系统网开商城系统网开商城系统网开商城系统
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class mycontrols_upfile : System.Web.UI.UserControl
{
    private string _filepath;
    public string Filepath
    {
        get { return _filepath; }
        set { _filepath = value; }
    }
    public string getpath()
    {
        this.Filepath = this.fileimages.Text;
        return Filepath;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
            string name = this.FileUpload1.FileName;//文件名字
            string size = this.FileUpload1.PostedFile.ContentLength.ToString();//文件大小
            string type = this.FileUpload1.PostedFile.ContentType;//文件类型ype == "image/pjpeg" || type == "image/gif" || type == "x-png"
            //string type2 = name.Substring(name.LastIndexOf(".") + 1);//文件类型
            string path = Server.MapPath("~/fileload/") + "//" + name;//实际路径
            string datapath = "fileload/" + name;
            if (Convert.ToInt32(size) > 2048)
            {
                this.Label1.Text = "上传失败文件大于2m";

            }

            if (type == "image/gif" || type == "image/bmp" || type == "image/pjpeg" || type == "image/x-png")
            {

                this.FileUpload1.SaveAs(path);
                this.Label1.Text = "上传成功";
                this.fileimages.Text = datapath;
            }
            else
            {

                this.Label1.Text = "文件类型不对上传失败";
            }
       
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -