1. 程式人生 > >net3:文件上傳與圖片顯示以及HiddenField隱藏字段值的使用

net3:文件上傳與圖片顯示以及HiddenField隱藏字段值的使用

pos protect path 來源 file ipa gif sender uri

原文發布時間為: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隱藏字段值的使用