天天躁日日躁狠狠躁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 上傳圖片實例,轉載需保留來源!

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

主站蜘蛛池模板: 色 花 堂 永久 网站 | 日本一区二区三区在线观看网站 | 亚洲精品久久久无码一区二区 | 免费三级黄色 | 日日夜夜噜噜 | 成人做视频免费 | 亚洲片在线观看 | 一本道综合久久免费 | 无人区尖叫之夜美女姐姐视频 | 女人被躁到高潮嗷嗷叫免费 | BL文库好大粗黑强强肉NP | 成都电影免费中文高清 | 日本邪恶少女漫画大全 | 免费无码又爽又黄又刺激网站 | 久久中文字幕免费高清 | 暖暖 免费 日本 高清 在线1 | 出差无套内射小秘书 | 一二三四在线高清中文版免费观看电影 | 免费看毛片的网址 | 四虎影院2022 | 高潮久久久久久久久不卡 | 国产毛片女人高潮叫声 | 国产99r视频精品免费观看 | 97久久精品人人槡人妻人 | 又黄又爽又无遮挡在线观看免费 | 啊灬啊灬啊灬快灬深高潮啦 | 亚洲人成无码久久久AAA片 | 美女穿丝袜被狂躁动态图 | 永久免费无码AV国产网站 | 青青青青青青草 | 亚洲三区视频 | 伊人天天躁夜夜躁狠狠 | 国产亚洲精品久久久久久禁果TV | 一二三四韩国免费观看 | 最近最新中文字幕MV高清在线 | 秀婷程仪公欲息肉婷在线观看 | 蜜臀AV精品久久无码99 | 三级色视频| 野花香HD免费高清版6高清版 | 二级片免费看 | 高h辣h双处全是肉一对一 |