仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 675|回复: 8
打印 上一主题 下一主题

[学习教程] ASP.NET网页编程之ASP.NET 2 的文件上传

[复制链接]
谁可相欹 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:46:26 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
因为二次编译器太复杂,那么建议只是在安装程序的时候编译一次,而不类似java那样运行就编译。并且我觉得,一次痛苦,总比多次低效率要舒服多了。asp.net|上传在asp.net2.0中,上传文件时变的对照便利了,由于有了fileupload控件,利用非常复杂,
if(FileUpload1.HasFile)
try
{
FileUpload1.SaveAs("d:luceneData"+FileUpload1.FileName);
Label1.Text="Filename:"+
FileUpload1.PostedFile.FileName+"<br>"+
FileUpload1.PostedFile.ContentLength+"kb<br>"+
"Contenttype:"+
FileUpload1.PostedFile.ContentType;
}
catch(Exceptionex)
{
Label1.Text="ERROR:"+ex.Message.ToString();
}
else
{
Label1.Text="Youhavenotspecifiedafile.";
}
还能够在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。
而关于多文件上传,也很复杂,好比一个例子
stringfilepath="d:luceneData";
HttpFileCollectionuploadedFiles=Request.Files;
for(inti=0;i<uploadedFiles.Count;i++)
{
HttpPostedFileuserPostedFile=uploadedFiles[i];
try
{
if(userPostedFile.ContentLength>0)
{
Label1.Text+="<u>File#"+(i+1)+
"</u><br>";
Label1.Text+="FileContentType:"+
userPostedFile.ContentType+"<br>";
Label1.Text+="FileSize:"+
userPostedFile.ContentLength+"kb<br>";
Label1.Text+="FileName:"+
userPostedFile.FileName+"<br>";
userPostedFile.SaveAs(filepath+""+
System.IO.Path.GetFileName(userPostedFile.FileName));
Label1.Text+="Locationwheresaved:"+
filepath+""+
System.IO.Path.GetFileName(userPostedFile.FileName)+
"<p>";
}
}
catch(ExceptionEx)
{
Label1.Text+="Error:<br>"+Ex.Message;
}
}
}
C#中有两处地方用到new关键字,第一处也是最常见的一处是用在调用构造函数的时候,这种情况也是大家见的最多的一种。另一处是用在派生类中,作用有隐藏成员,切断继承关系等,相信第二处的用法大家明显要比第一处生疏。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-6-17 01:45

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表