upfile.ascx.cs

来自「网开商城系统网开商城系统网开商城系统网开商城系统」· CS 代码 · 共 59 行

CS
59
字号
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 + =
减小字号Ctrl + -
显示快捷键?