四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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)系我們修改或刪除,多謝。

主站蜘蛛池模板: 天降奇缘 电视剧| 花守由美里| 故乡别来无恙演员表名单| 真实游戏在线观看免费完整版| 许多组织都有自己的价值标准和行为理念 | 熊乃瑾个人资料| 勇敢者| 苹果恋爱多| 色蝴蝶| 石川佑希| 巨齿鲨2:深渊 电影| 小学道德与法治课程标准2023版| jagger| 闪电11人| 郭明翔| 欢乐的牧童钢琴谱| 波斯王子时之刃| 美女故事| 曹查理电影大全免费观看| 港股三大指数| 高潮艺术| 电影在线观看高清完整版免费| 沙漠电影高清在线播放| 无籍者| 七年级下册英语第二单元作文| 维京人电影| 2024年暑假师德师风心得体会| www.黄视频| 小丑与小丑女| 新有菜免费在线观看| 电影名叫《保姆》| mhdd| 天云山传奇 电影| 徐情| 雾里看花电视剧| 内蒙古电视台节目表| 夏日福星 电影| 金珊| 吃屎视频搞笑视频| 饥渴少妇av| 电影 本能|