FileUpload控制項小例

2022-05-03 01:45:09 字數 2046 閱讀 9822

第1個上傳方法說明:

1.未選擇檔案,或者選擇的是txt空檔案,則上傳失敗,

2.可上傳,txt,word格式檔案。rar檔案失敗。

第2個: 使用擴充套件的input type="file"控制項來實現這個功能,它的accept屬性來保證上傳檔案的檔案型別。

**:code

@ page language="

c#"%>

doctype html public 

"-//w3c//dtd xhtml 1.0 transitional//en""

">

<

script runat="

server

">

protected

void

button1_click(

object

sender, eventargs e)

catch

(exception ex) 

else

}void

uploadfile(

object

serder, eventargs e)

script

>

<

html xmlns="

">

<

head runat="

server

">

<

title

>

無標題頁

title

>

head

>

<

body

>

<

form id="

form1

"runat="

server

"enctype="

multipart/form-data

">

<

div>

<

asp:fileupload id="

fileupload1

"runat="

server

"/>

<

asp:button id="

button1

"runat="

server

"text="

upload

"onclick="

button1_click

"/><

br />

<

asp:label id="

label1

"runat="

server

"forecolor="

red"

>

asp:label

><

br />

<

br />

<

br />

<

br />

<

br />

<

br />

<

br />

<

input id="

butimage

"runat="

server

"accept="

img/jpeg

"type="

file

"/><

br />

<

input id="

yesbutton

"runat="

server

"onserverclick="

uploadfile

"type="

button

"value="

提交"/><

br />

<

asp:label id="

labcontent1

"runat="

server

">

asp:label

><

br />

div>

form

>

body

>

html

>

FileUpload控制項上傳

if fileupload1.hasfile 判斷裡fileupload是否有此檔案位址 定義乙個陣列裡面放檔案格式 arraylist arry new arraylist arry.addrange strpic 定義乙個可變陣列,用於放檔案格式 if arry.contains strend ...

FileUpload控制項應用

目的 使用fileupload控制項來達到控制網頁檔案上傳的目的。根目錄下建有 webpage 檔案 前台html 如下 後台 如下 protected void uploadfile click object sender,eventargs e for int i 0 i allowedexte...

FileUpload控制項的配置

2011 10 17 01 12 397人閱讀 收藏 舉報 微軟自帶上傳控制項fileupload介紹 其預設能上傳大小為4096 kb 如果使用fileupload控制項上傳檔案超過4096kb就會是執行的網頁頁面執行掛掉。但是我們可以對fileupload控制項上傳大小進行重新配置,避免這種問題...