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++)
 
相关文档:
译文原文地址
http://www.cnblogs.com/hl13571/archive/2008/01/28/1056671.html
英文原文地址
Understanding Single Sign-On in ASP.NET 2.0
理解ASP.NET 2.0中的单点登录
Published: 16 Jan 2008
摘要
在这篇文章中,Masoud讨论了应用ASP.NET中统一身份验证模型进行跨应用程序验证的问题,包括:Membership Prov ......
大家知道,Microsoft为了更好地预防恶意用户和攻击者的攻击,在默认情况下,没有将 IIS6.0 安装到 Windows Server 2003 家族的成员上。而且,当我们最初安装 IIS6.0 时,该服务在高度安全和"锁定"模式下安装。在默认情况下,IIS6.0 只为静态内容提供服务即,诸如 ASP、ASP.NET、在服务器端的包含文件、WebDAV 发布和 FrontP ......
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 ......
3 mistakes to avoid when using jQuery with ASP.NET AJAX
AJAX, ASP.NET, JavaScript, jQuery By Dave Ward on June 5th, 2008
Over the past few weeks, I think I have definitely embodied Jeff Atwood’s claim that we’re all amateurs, learning together. Despite my best efforts to thoroughly tes ......