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

2021-06-28 09:05

阅读:657

标签:text   obj   ef6   click   field   als   server   image   来源   

原文发布时间为: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 + "
大小:" + size + "
类型:" + type1 + "
后缀名:" + type2 + "
实际路径:" + ipath + "
虚拟路径:" + wpath;
        }
        else
        {
            Image1.Visible = false;
            FileUpload1.SaveAs(fpath);
            Label1.Text = "你上传的文件名称:" + name + "
大小:" + size + "
类型:" + type1 + "
后缀名:" + type2 + "
实际路径:" + fpath;
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        LinkButton1.Text = HiddenField1.Value;
    }
}

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

标签:text   obj   ef6   click   field   als   server   image   来源   

原文地址:http://www.cnblogs.com/handboy/p/7143819.html


评论


亲,登录后才可以留言!