网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP.NET技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.ASP.NET实现页面间值传递的几种方.
.得到内网可用的SqlServer 及某数.
..Net开发漫谈:关于命名空间和目.
.通过Remoting service上传文件.
.101个微软提供的Visual Studio 2.
.ASP.NET应用程序资源访问安全模型.
.ASP.NET 2.0 Treeview Checkboxe.
.用完HttpWebResponse时别忘了调用.
.asp.net身份验证和授权.
.ASP.NET中利用VWD操作数据库.
.如何实现ASP.NET网站个性化?.
.asp.net 2.0 主题中多CSS文件引用.
.ASP.net:Literal控件用法 .
.结合ASP.NET与JavaScript开发电子.
.js操作listbox.
.ASP.NET中散列加密密码.
.asp.net报表解决方法.
.在ASP.NET中访问SQL 2005报表服务 .
.使用ASP.NET Atlas开发检测密码强.
.如何实现Asp与Asp.Net共享Session.

asp.net 2的文件上传

发表日期:2006-9-27


在asp.net 2.0中,上传文件时变的比较方便了,因为有了fileupload控件,使用十分简单,
if (FileUpload1.HasFile)
            try
            {
                FileUpload1.SaveAs("d:\\luceneData\\" + FileUpload1.FileName);
                Label1.Text = "File name: " +
                     FileUpload1.PostedFile.FileName + "<br>" +
                     FileUpload1.PostedFile.ContentLength + " kb<br>" +
                     "Content type: " +
                     FileUpload1.PostedFile.ContentType;
            }
            catch (Exception ex)
            {
                Label1.Text = "ERROR: " + ex.Message.ToString();
            }
        else
        {
            Label1.Text = "You have not specified a file.";
        }
还可以在web.config文件中,突破默认上传限制的4MB,比如
<httpRuntime
executionTimeout="110"
maxRequestLength="11000"
requestLengthDiskThreshold="80"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="5000"
enableKernelOutputCache="true"
enableVersionHeader="true"
requireRootedSaveAsPath="true"
enable="true"
shutdownTimeout="90"
delayNotificationTimeout="5"
waitChangeNotification="0"
maxWaitChangeNotification="0"
enableHeaderChecking="true"
sendCacheControlHeader="true"
apartmentThreading="false" />

设置maxRequestLenth属性,这里为11000KB,即11MB。

而对于多文件上传,也很简单,比如一个例子
string filepath = "d:\\luceneData\\";
        HttpFileCollection uploadedFiles = Request.Files;

        for (int i = 0; i < uploadedFiles.Count; i++)
        {
            HttpPostedFile userPostedFile = uploadedFiles[i];

            try
            {
                if (userPostedFile.ContentLength > 0)
                {
                    Label1.Text += "<u>File #" + (i + 1) +
                       "</u><br>";
                    Label1.Text += "File Content Type: " +
                       userPostedFile.ContentType + "<br>";
                    Label1.Text += "File Size: " +
                       userPostedFile.ContentLength + "kb<br>";
                    Label1.Text += "File Name: " +
                       userPostedFile.FileName + "<br>";

                    userPostedFile.SaveAs(filepath + "\\" +
                       System.IO.Path.GetFileName(userPostedFile.FileName));

                    Label1.Text += "Location where saved: " +
                       filepath + "\\" +
                       System.IO.Path.GetFileName(userPostedFile.FileName) +
                       "<p>";
                }
            }
            catch (Exception Ex)
            {
                Label1.Text += "Error: <br>" + Ex.Message;
            }
        }

    }


http://www.cnblogs.com/jackyrong/archive/2006/09/26/514969.html

上一篇:两个截取字符串的实用方法(超过一定长度自动换行) 人气:5893
下一篇:在Asp.net的HttpCookie中写入汉字,读取时为乱码的解决方法! 人气:6185
浏览全部asp.net 2.0的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐