欢迎访问我的博客 https://javascript.shop

net3:文件上传与图片显示以及HiddenField隐藏字段值的使用

原文发布时间为:2008-07-29 —— 来源于本人的百度文章 [由搬家工具导入]

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 Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Image1.Visible = false;
    }
    protected void upload_Click(object sender, EventArgs e)
    {
        string name = FileUpload1.FileName;
        string size = FileUpload1.PostedFile.ContentLength.ToString();
        string type1 = FileUpload1.PostedFile.ContentType.ToString();
        string type2 = name.Substring(name.LastIndexOf(".") + 1);
        string ipath = Server.MapPath("image") + "\\" + name;
        string fpath = Server.MapPath("upfile") + "\\" + name;
        string wpath="image\\"+name;

        if (type2 == "JPG" || type2 == "GIF" || type2 == "PNG" || type2 == "BMP"||type2 == "jpg" || type2 == "gif" || type2 == "png" || type2 == "bmp")
        {
            FileUpload1.SaveAs(ipath);
            Image1.Visible = true;
            Image1.ImageUrl = wpath;
            Label1.Text = "你上传的文件名称:" + name + "<br>大小:" + size + "<br>类型:" + type1 + "<br>后缀名:" + type2 + "<br>实际路径:" + ipath + "<br>虚拟路径:" + wpath;
        }
        else
        {
            Image1.Visible = false;
            FileUpload1.SaveAs(fpath);
            Label1.Text = "你上传的文件名称:" + name + "<br>大小:" + size + "<br>类型:" + type1 + "<br>后缀名:" + type2 + "<br>实际路径:" + fpath;
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        LinkButton1.Text = HiddenField1.Value;
    }
}

posted @ 2017-07-10 00:48  孑孓子  阅读(180)  评论(0编辑  收藏  举报
欢迎访问我的博客 https://javascript.shop