Asp.Net下的文件上传功能实现
刚学习.Net没有多长时间,以前都是看别人的文章,学习前辈们的经验和技巧,自己受益匪浅。今天也来个原创的,发个文件上传的代码。主要实现的功能有:1.可以控制允许上传的文件类型;2.上传之后自动以时间命名;3.自动创建上传文件要保存的目录。
不足之处:没有对允许上传的文件大小做限制。其他不足之处还望各位指出,以便改进。第一次发文章,鲜花、砖头自己准备!呵呵~~~
要引入命名空间 System.IO;
#region 上传文件
protected void btn_upload_Click(object sender, EventArgs e)
{
bool fileOK = false;
//文件的上传路径
string path = Server.MapPath("~/UpLoadFiles/Files/");
//判断上传文件夹是否存在,若不存在,则创建
if (!Directory.Exists(path))
{
//创建文件夹
Directory.CreateDirectory(path);
}
if (upload.HasFile)
{
//如果选择了文件则执行
//获取上传文件的类型
string fileExtesion = System.IO.Path.GetExtension(upload.FileName).ToLower();
//允许上传的类型
string[] allowExtesions = { ".doc", ".xls", ".rar", ".zip", ".ppt" };
for (int i = 0; i < allowExtesions.Length; i++)
 
相关文档:
问题描述:
Asp.Net中datalist等web控件里面,放多个单选按钮的时候可以同时多选,可以采取以下放法。
问题解决:
最理想的解决之道,用javascript:
<script language="javascript" type="text/javascript">
function clickit() {
var dom=document.all;
& ......
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Sy ......
大家知道,Microsoft为了更好地预防恶意用户和攻击者的攻击,在默认情况下,没有将 IIS6.0 安装到 Windows Server 2003 家族的成员上。而且,当我们最初安装 IIS6.0 时,该服务在高度安全和"锁定"模式下安装。在默认情况下,IIS6.0 只为静态内容提供服务即,诸如 ASP、ASP.NET、在服务器端的包含文件、WebDAV 发布和 FrontP ......
1.简单验证
在ASP.Net MVC中,验证是在Controller层,而错误呈现是在View层,Controller层是通过ModelState属性进行验证的,ModelState的状态是通过AddModelError()方法进行 添加的。
而在View层,是通过Html的辅助方法进行呈现的,这两个辅助方法分别是
Html.ValidationMessage()
Html.ValidationSummary()
Controller ......
JSON Serialization and Deserialization in ASP.Net
I was looking around for a simple example which would just do an object serialization to a JSON format, and then deserializing back to the original object. I found few examples on MSDN, but did seem to be too long ......