ASP.NET文件上传范例

Standard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<%@ Import Namespace="System" %>  
<%@ Import Namespace="System.Web.HttpPostedFile" %>  
<%@ Import Namespace="System.Web.UI.HtmlControls.HtmlInputFile" %>  
<%
  'www.yemaosheng.com
  Response.expires   =   0      
  Response.addHeader("pragma","no-cache")    
  Response.addHeader("cache-control","private")
  Response.CacheControl   =   "no-cache"
  dim i=0
  if request.queryString("state")="" then
    For i=0 to Request.Files.Count-1  
      '使用Request.Files()来逐个获取上传的文件  
      dim myFile as HttpPostedFile=Request.Files(i)  
      response.write(request.Form("text_desc"))
      myFile.SaveAs(Server.MapPath(".") & "\upload\" & myFile.FileName)
    Next
  end if
%>
<form action="" method="post" enctype="multipart/form-data" name="form_file" id="form_file">
  <textarea name="text_desc" id="text_desc"></textarea>
  <input type="file" name="filename">
  <input type="hidden" name="state" value="1">
  <input type="hidden" name="site" value="yemaosheng.com">
  <input type="submit" name="Submit" value="Submit">
</form>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.