.net简单的fileupload控件上传
前台代码:
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="filebut" runat="server" Text="上传" onclick="filebut_Click" />
后台代码:
protected void filebut_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile.FileName == "")
{
Response.Write("<script>alert('请选择上传文件!')</script>");
}
else
{
HttpFileCollection uploadfiles = Request.Files;
string filetiem = DateTime.Now.ToString();//当前时间
string fileusername = Session.Contents["userid"].ToString();//当前用户
string gongwid = Request.QueryString["id"];//文章id
for (int i = 0; i < uploadfiles.Count; i++)
{
HttpPostedFile mypost = uploadfiles[i];
try
{
string filepath = mypost.FileName;
string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);//获取文件名
string serverpath = Server.MapPath("UploadFile\\") + filename;//服务器上传地址
if (System.IO.File.Exists(serverpath))
{
Response.Write("<script>alert('文件已存在请重新命名!')</script>");
}
else
{
mypost.SaveAs(serverpath);
string filestrsql = "insert into OA_FILE(wjlj,wjm,gongwid,scr,scsj)values('" + serverpath + "','" + filepath + "','" + gongwid + "','" + fileusername + "','" + filetiem + "')";//sql执行语句
int sfcg = SqlHelper.wjsc(filestrsql);
if (sfcg > 0)
{
labzt.Text = "文件" + i + "上传成功!路径:" + serverpath + "\r\n";
}
}
}
catch (System.Exception ex)
{
labzt.Text = "上传错误!原因:" + ex.Message.ToString();
}
}
}
}
由于先前是准备多加价格fieldupload控件的,但是不是特别美观,但是实现了上传的功能。不懂的可以加我扣扣:441621682
.net简单的fileupload控件上传的更多相关文章
- WebForm使用FileUpload控件上传压缩二进制图片
fuImage 是FileUpload页面控件 ImageHelper.CompressionImage(fuImage.FileBytes, quality); /// <summary> ...
- fileupload控件上传、文件下载
常遇到上传下载的功能,这里把我习惯的用法写下来: 上传: string fileName = "";fileName = this.fu_pic.FileName;if (stri ...
- asp.net FileUpload 控件上传文件 以二进制的形式存入数据库并将图片显示出来
图片上传事件代码如下所示: byte[] binary = upload.FileBytes; StringBuilder sqlStrSb = new StringBuilder(); sqlStr ...
- asp:FileUpload 控件上传多文件
<asp:FileUpload runat="server" ID="imgUpload" AllowMultiple="true" ...
- FileUpload的控件上传excel
在一个使用FileUpload的控件上传excel,读取excel的数据 因为上传的路径一直被限定在C:\Program\IIS\Express 一直限制这个文件下, 想要解决这个问题. 在谷歌浏览器 ...
- MVC项目使用easyui的filebox控件上传文件
开发环境:WIN10+IE11,浏览器请使用IE10或以上版本 开发技术框架MVC4+JQuery Easyui+knockoutjs 效果为弹出小窗体,如下图 1.前端cshtml文件代码(只包含文 ...
- JS ajaxfileUpload 一次性上传多个input控件 上传多个文件
本方法适用于一次性上传多个input框输入的文件,如下图所示,任务是需要一次上传两个input框提供的两个文件. 具体方法: 1.修改ajax调用方法 如上图所示,只需要将ajaxFileUpload ...
- c#上传文件(一)使用 .net 控件上传文件
1.html代码: <body> <form id="form1" runat="server"> <div> <as ...
- upload控件上传json文件合并的两种方法
方法一: byte[] byte1 = FileUpload1.FileBytes; byte[] byte2 = FileUpload2.FileBytes; byte[] a1 = Encodin ...
随机推荐
- ASO--简单了解
ASO是“应用商店优化”的简称.ASO(App Search Optimization)就是提升你APP在各类APP应用商店/市场排行榜和搜索结果排名的过程. 类似普通网站针对搜索引擎的优化,即SEO ...
- Spring嵌套事务控制
A类 callBack_test() B类 testadd() C类 select(),得查询到B类testadd方法中新增的数据.以及初始化一些属性 场景:A类 嵌套 B类 B类嵌套C ...
- 设置Table边框的CSS
<!DOCTYPE html> <html> <head> <style> table, td, th { border: 1px solid blac ...
- leetcode 664. Strange Printer
There is a strange printer with the following two special requirements: The printer can only print a ...
- sphinx 针对tedfield搜索
query = "(user can be admin)" -> check all fields for the given words. If all words ar ...
- AppiumLibrary用户关键字
*** Settings *** Library AppiumLibrary Library AutoItLibrary Library os *** Keywords *** xpath应该匹配次数 ...
- Java-Runoob-高级教程-实例-字符串:08. Java 实例 - 字符串分割(StringTokenizer)
ylbtech-Java-Runoob-高级教程-实例-字符串:08. Java 实例 - 字符串分割(StringTokenizer) 1.返回顶部 1. Java 实例 - 字符串分隔(Strin ...
- bootstrap-table 行合并和列合并,以及固定列宽度等问题
列合并和列宽度固定: .setWidth { table-layout: fixed; } .setWidth > thead > tr > th { width: 80px; } ...
- 解决Linux主机上的 远程MySQL客户端无法连接的问题
无法连接到 MySQL 数据库可能的原因有: 1. PHP 无法连接 MySQL 可能是 PHP 配置不正确,没加上连接 MySQL 的功能. 2. MySQL 软件包升级,但没有升级数据库,或安装 ...
- HDU-ACM“菜鸟先飞”冬训系列赛——第9场
Problem A 题意 一对兔子每月生一对兔子,兔子在\(m\)月后成熟,问\(d\)月后有多少兔子 分析 可以发现,第i月的兔子数量取决于第i-1月与i-m月,故 \(a[i]=a[i-1]+a[ ...