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

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 默認(rèn)上傳文件最大為4MB。這是在網(wǎng)上找到的。
如果要增加,則可以在Machine.config里面進(jìn)行修改
復(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)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 久久免费精品一区二区 | 调教椅上的调教SM总裁被调教 | 亚洲麻豆精品成人A在线观看 | 亚洲欧洲日产国码中学 | 久久黄色免费网站 | 九九99国产香蕉视频 | 先锋影音av最新资源网 | 丹麦1o一19sex性hdhd| 国产亚洲精品V在线观看一 国产亚洲精品a在线观看app | 国产欧美日韩视频怡春院 | 91天堂国产在线 在线播放 | 调教玩弄奶头乳夹开乳震动器 | 久久精品视频免费 | 色多多污网站在线观看 | 做a爱片的全过程 | 秋霞电影网午夜一级鲁丝片 | 中文字幕va一区二区三区 | 日韩精品AV一区二区三区 | 久久久黄色大片 | a在线视频免费观看 | 国产精品嫩草影院一区二区三区 | 色播播影院 | 少妇内射视频播放舔大片 | 在线观看视频亚洲 | 小776论坛 | 午夜影院费试看黄 | www.一级毛片 | 人人碰国产免费线观看 | 午夜一个人在线观看完整版 | 欧美高清video mr.sexo | 无限资源在线观看完整版免费下载 | 插骚妇好爽好骚 | 日本污ww视频网站 | 成人在线免费看片 | 日本69xxxx | 人人爽天天碰狠狠添 | 欧美特级特黄a大片免费 | 久操久操久操 | 欧美香蕉大胸在线视频观看 | 美女扣逼软件 | 海角国精产品一区一区三区糖心 |