一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

ASP.NET FileUpload 上傳圖片實例

復(fù)制代碼 代碼如下:
<table style="width: 100%">
<tr>
<td>
<ASP:ValidationSummary ID="ValidationSummary1" runat="server" />
<br />
<ASP:FileUpload ID="FileUpload1" runat="server" />
 <ASP:Button ID="btn_upload" runat="server" OnClick="btn_upload_Click"
Text="Upload" />
  
<ASP:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="FileUpload1" Display="Static"
ErrorMessage="You should only can upload image file such as files with .jpg or gif extension"
OnServerValidate="Image_validate">*</ASP:CustomValidator>
</td>
</tr>
</table>

Add to code behind cs file
復(fù)制代碼 代碼如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
public partial class practice_FileUpload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_upload_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string path = @Page.MapPath("User_Edit.ASPx").Replace("User_Edit.ASPx", "") + "Documents//";
string s = path + Session["UserName"].ToString();
if (!System.IO.Directory.Exists(path + Session["UserName"].ToString()))
{
System.IO.Directory.CreateDirectory(path + Session["UserName"].ToString());
}
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath("~/Seeker/Documents/" + Session["UserName"].ToString() + "/" + this.FileUpload1.FileName));
}
}
}
protected void Image_validate(object source, ServerValidateEventArgs args)
{
string fileExt = Path.GetExtension(FileUpload1.FileName).ToLower();
string fileName = Path.GetFileName(FileUpload1.FileName);
if (fileExt != ".jpg" && fileExt != ".gif")
{
args.IsValid = false;
}
}
protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
{
Bitmap bmIP = new Bitmap(FileUpload1.PostedFile.InputStream);
if (bmIP.Width > 100 | bmIP.Height > 100)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
}

The default size of files uploaded by the FileUpload control is 4MB. This solution was found from the InterNET。
值得注意的是,F(xiàn)ileUpload 默認上傳文件最大為4MB。這是在網(wǎng)上找到的。
如果要增加,則可以在Machine.config里面進行修改
復(fù)制代碼 代碼如下:
<httpRuntime
executionTimeout = "110" [in Seconds][number
maxRequestLength = "4096" [number]
requestLengthDiskThreshold = "80" [number]
useFullyQualifiedRedirectUrl = "false" [true|false]
minFreeThreads = "8" [number]
minLocalRequestFreeThreads = "4" [number]
appRequestQueueLimit = "5000" [number]
enableKernelOutputCache = "true" [true|false]
enableVersionHeader = "true" [true|false]
apartmentThreading = "false" [true|false]
requireRootedSaveASPath = "true" [true|false]
enable = "true" [true|false]
sendCacheControlHeader = "true" [true|false]
shutdownTimeout = "90" [in Seconds][number]
delayNotificationTimeout = "5" [in Seconds][number]
waitChangeNotification = "0" [number]
maxWaitChangeNotification = "0" [number]
enableHeaderChecking = "true" [true|false]
/>

AspNet技術(shù)ASP.NET FileUpload 上傳圖片實例,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产成人精品午夜 | 成人欧美视频在线观看 | 91社区视频在线观看 | 国产老鸭窝毛片一区二区 | 欧美黑人粗硬大在线看 | 一区二区三区免费视频观看 | 午夜欧美成人久久久久久 | 国产成人黄色 | 免费播放一区二区三区 | 天天摸天天爽视频69视频 | 麻豆视频播放 | 国产91精品福利在线观看 | 性感美女一级毛片 | 高跟黑色丝袜国产91美女紫丝 | 精品国免费一区二区三区 | 中文字幕亚洲无线码在线一区 | 图片区小说区欧洲区 | 一区二区三区观看 | 亚洲欧美在线综合一区二区三区 | 国产成人福利免费观看 | 婷婷影院在线观看 | 九九婷婷| 2019天天干天天操 | 婷婷综合影院 | 欧美一级免费 | 东方伊人免费在线观看 | 国产精选在线 | 99精品视频在线观看 | 色噜噜狠狠狠综合曰曰曰88av | 国产一区国产二区国产三区 | 小明日韩在线看看永久区域 | 免费毛片在线视频 | 99精品视频在线视频免费观看 | 91精品国产91热久久久久福利 | 久久久久琪琪去精品色村长 | 久久久久久一级毛片免费野外 | 精品视频自拍 | 色哟哟免费在线观看 | 日韩在线一区二区三区视频 | 国内精品91最新在线观看 | 四虎永久在线精品视频播放 |