博客
关于我
asp.net代码练习 work016 fileupload文件上传
阅读量:312 次
发布时间:2019-03-03

本文共 1254 字,大约阅读时间需要 4 分钟。

webform1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="work016.WebForm1" %>

webform1.aspx.cs

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace work016{    public partial class WebForm1 : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {        }        protected void Button1_Click(object sender, EventArgs e)        {            //判断是否上传文件,如果是txt之类的文件,0字节也认为是没有文件            if (FileUpload1.HasFile)            {                //通过相对路径,获取到服务器的绝对路径                string savePath = Server.MapPath("~/upload");                //路径不存在,创建                if (!System.IO.Directory.Exists(savePath))                {                    System.IO.Directory.CreateDirectory(savePath);                }                //路径后,加上文件名                savePath = savePath + string.Format("\\{0}",FileUpload1.FileName);                //保存                FileUpload1.SaveAs(savePath);                //提示                Literal1.Text = string.Format("upload/{0}",FileUpload1.FileName);            }        }    }}

 

转载地址:http://firm.baihongyu.com/

你可能感兴趣的文章
MySQL 中的外键检查设置:SET FOREIGN_KEY_CHECKS = 1
查看>>
Mysql 中的日期时间字符串查询
查看>>
mysql 中索引的问题
查看>>
MySQL 中锁的面试题总结
查看>>
MySQL 中随机抽样:order by rand limit 的替代方案
查看>>
MySQL 为什么需要两阶段提交?
查看>>
mysql 为某个字段的值加前缀、去掉前缀
查看>>
mysql 主从
查看>>
mysql 主从 lock_mysql 主从同步权限mysql 行锁的实现
查看>>
mysql 主从互备份_mysql互为主从实战设置详解及自动化备份(Centos7.2)
查看>>
mysql 主从关系切换
查看>>
MYSQL 主从同步文档的大坑
查看>>
mysql 主键重复则覆盖_数据库主键不能重复
查看>>
Mysql 事务知识点与优化建议
查看>>
Mysql 优化 or
查看>>
mysql 优化器 key_mysql – 选择*和查询优化器
查看>>
MySQL 优化:Explain 执行计划详解
查看>>
Mysql 会导致锁表的语法
查看>>
mysql 使用sql文件恢复数据库
查看>>
mysql 修改默认字符集为utf8
查看>>