天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

ASP.NET FileUpload 上傳圖片實例

復制代碼 代碼如下:
<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
復制代碼 代碼如下:
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
值得注意的是,FileUpload 默認上傳文件最大為4MB。這是在網上找到的。
如果要增加,則可以在Machine.config里面進行修改
復制代碼 代碼如下:
<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技術ASP.NET FileUpload 上傳圖片實例,轉載需保留來源!

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

主站蜘蛛池模板: av影音先锋天堂网 | 亚洲乱码高清午夜理论电影 | 国产亚洲精品在线视频 | 内射人妻骚骚骚 | 一一本之道高清视频在线观看中文字幕 | 51成人精品午夜福利AV免费七 | 久久国产亚洲电影天堂 | 亚洲欧美一区二区三区导航 | 色迷迷导航 | 洗濯屋H纯肉动漫在线观看 羲义嫁密着中出交尾gvg794 | 日本不卡不码高清免费 | 天上人间影院久久国产 | 好大太快了快插穿子宫了 | 亚洲精品无码一区二区三区四虎 | 无遮挡午夜男女XX00动态 | 女性酥酥影院 | 亚洲香蕉视频在线播放 | 胖老太与人牲交BBWBBW高潮 | 97在线精品视频免费 | 最近中文字幕2019国语4 | 国产成人在线视频 | 亚洲视频第二页 | 久久久这里有精品999 | 卫生间被教官做好爽HH视频 | 精品无码一区二区三区中文字幕 | 在线观看国产高清免费不卡 | 久久女婷五月综合色啪 | 李亚男三级| 色人阁影视 | 亚洲熟少妇在线播放999 | 婷婷亚洲五月色综合久久 | 最新高清无码专区 | 夜色帮首页 | 色多多污污在线观看网站 | c了瑜伽老师嗷嗷叫一节课视频 | 精品午夜久久影视 | 2019久久视频这里有精品15 | 久久精品免视看国产 | 花蝴蝶高清在线视频免费观看 | 无修肉动漫在线观看影片 | 拔萝卜视频免费看高清 |