码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-07-10 01:16:21      阅读:252      评论:0      收藏:0      [点我收藏+]

标签: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 + "<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;
    }
}

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!