改变FileUpload文件上传控件的显示方式,确认后上传

一、Aspx页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FileUploadDemo.aspx.cs" Inherits="WebApplication1.FileUploadDemo" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.ddtop{ width:98%; height:30px; margin-top:5px; border:#EED97C 1px solid; margin-left:auto; margin-right:auto; margin-bottom:5px; background:#FFFCEB; font:"宋体"; font-size:14px; padding-left:10px; padding-top:10px;}
input{border-left:1px solid #333;border-top:1px solid #333;border-bottom:1px solid #ccc;border-right:1px solid #ccc;}
.button{ cursor:pointer; background-color:#1481E6;border:1px solid #fff;text-align:center;color:#fff;line-height:19px;}
.heigth_22{ height:22px;}
.width_70{ width:70px;}
</style>
<script type="text/javascript">
function setUpFileText(obj) {
var fileName = getFullPath(obj);
document.getElementById("upFileText").value = fileName;
} function getFullPath(obj) {
if (obj) {
// IE
if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
obj.select();
return document.selection.createRange().text;
}
// Firefox
else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
if (obj.files) {
return obj.files.item(0).name;
}
}
// Chrome
else if (window.navigator.userAgent.indexOf("Chrome") >= 1) {
if (obj.files) {
return obj.files[0].name;
}
}
return obj.value;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="ddtop">
<div>
<span><input type="text" id="upFileText" name="upFileText" readonly="readonly" /></span>
<span style="position: absolute; z-index: 2; cursor: pointer;">
<asp:FileUpload ID="fileUpload" runat="server" CssClass="width_70 heigth_22" Style="filter: alpha(opacity=0); opacity: 0; cursor: pointer;" onchange="setUpFileText(this)" accept="image/*" />
<asp:Button ID="btnOk" runat="server" Text="确定" CssClass="button width_70 heigth_22" OnClick="btnOk_Click" />
</span>
<span style="position: absolute; z-index: 1; cursor: pointer; height: 25px;">
<input type="button" name="btnUploadFile" id="btnUploadFile" value="上傳檔案" class="button width_70 heigth_22" />
</span>
</div>
</div>
</form>
</body>
</html>
二、Aspx后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO; namespace WebApplication1
{
public partial class FileUploadDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void btnOk_Click(object sender, EventArgs e)
{
if (this.fileUpload.HasFile)
{
string fileName = this.fileUpload.PostedFile.FileName; // 客户端文件路径
string extension = System.IO.Path.GetExtension(fileName);
if (extension.ToLower() != ".jpg" && extension.ToLower() != ".png")
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('只允许jpg 和 png!');", true);
return;
} string pathBase = "D:\\UploadFile";
if (!Directory.Exists(pathBase))
Directory.CreateDirectory(pathBase);
string webFilePath = Path.Combine(pathBase, fileName); // 数据库保存文件路径(相对全路径)
this.fileUpload.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件
ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('上傳成功,我們會盡快進行核對!');", true);
}
}
}
}
改变FileUpload文件上传控件的显示方式,确认后上传的更多相关文章
- 改变FileUpload文件上传控件的显示方式,选择文件后自动上传
一.Aspx页面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="File ...
- asp.net web常用控件FileUpload(文件上传控件)
FileUpload控件的主要中能:向指定目录上传文件,该控件包括一个文本框和一个浏览按钮. 常用的属性:FileBytes,FileContent.FileName.HasFile.PostedFi ...
- .Net 使用文件上传控件FileUpload上传图片
例1: 来源:http://long546324.iteye.com/blog/349946 Default.aspx文档: <%@ Page Language="C#" A ...
- 对FileUpload文件上传控件的一些使用方法说明
//创建时间:2014-03-12 //创建人:幽林孤狼 //说明:FileUpload文件上传控件使用说明(只是部分)已共享学习为主 //可以上传图片,txt文档.doc,wps,还有音频文件,视屏 ...
- jquery文件上传控件 Uploadify
(转自 http://www.cnblogs.com/mofish/archive/2012/11/30/2796698.html) 基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同 ...
- jquery文件上传控件 Uploadify 问题记录
Uploadify v3.2.1 首先引用下面的文件 <!--上传控件 uploadify--> <script type="text/javascript" s ...
- 因用了NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误的解决方法
今天遇到一个问题,就是“NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误”,百度后发现了一个解决方法,跟大家分享下: NeatUploa ...
- 给上传文件的input控件"美容"
作为一名前端程序猿呢,在工作中经常会遇到form表单这种东西.然而表单的其他input控件样式还是很好改变的.但是,唯独input类型是file的文件上传控件可能就没那么好打扮的漂亮.刚好菜鸟我最近工 ...
- ASP.NET使用文件上传控件上传图片
ASPX代码 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default. ...
随机推荐
- centos7 yum安装ffmpeg,以及ffmpeg的简单用法
yum install ffmpeg: 安装EPEL Release,因为安装需要使用其他的repo源,所以需要EPEL支持: yum install -y epel-release #如果出现缺少C ...
- easyui的tree节点的获取和选中
1.设置选中tree的节点 var node = $('#tt').tree('find', 1);//找到id为”tt“这个树的节点id为”1“的对象$('#tt').tree('select', ...
- linq2db sqlite应用
使用linq2db sqlite 的时候,找不到增加,删除的操作,原来是要引入一个新的命名空间LinqTODB. 1 using LinqToDB; 插入: 1 User uNew = new Use ...
- Linux date 命令
date命令用于打印或设置系统日期和时间,常见用法如下: [root@localhost ~]# date //查看当前时间 [root@localhost ~]# date +"%Y-%m ...
- 《转载》强大全面的C++框架和库推荐!
C++ 资源大全 关于 C++ 框架.库和资源的一些汇总列表,内容包括:标准库.Web应用框架.人工智能.数据库.图片处理.机器学习.日志.代码分析等. 标准库 C++标准库,包括了STL容器,算法和 ...
- Kindeditor视频上传问题处理
初始的时候,video这个标签kindeditor是不识别的,只要html处理或者全屏的时候,都会被排除掉.如果想要video存在,则需要设置属性filterMode :false 如果只是想要某个标 ...
- mysql存储emoji问题
前一段时间,项目中需要在数据库中存储emoji,由于编码格式不对,直接导致数据库报错,后来修改mysql的编码,就解决了 emoji符号实际上是文本,并不是图片,它们仅仅显示为图片 在mysql5.5 ...
- Express中间件的原理及实现
在Node开发中免不了要使用框架,比如express.koa.koa2拿使用的最多的express来举例子开发中肯定会用到很多类似于下面的这种代码 var express = require('exp ...
- ArcGIS AddIN异常:无法注册程序集 未能加载文件或程序集"ESRI.ArcGIS.Desktop.Addins"
异常: 无法注册程序集“D:\CodeXX\bin\Debug\XX.dll”.未能加载文件或程序集“ESRI.ArcGIS.Desktop.AddIns, Version=10.1.0.0, Cul ...
- /编写一个函数,要求从给定的向量A中删除元素值在x到y之间的所有元素(向量要求各个元素之间不能有间断), 函数原型为int del(int A ,int n , int x , int y),其中n为输入向量的维数,返回值为删除元素后的维数
/** * @author:(LiberHome) * @date:Created in 2019/2/28 19:39 * @description: * @version:$ */ /* 编写一个 ...