建立家用服务器|软件站|第三日
生活随笔
收集整理的這篇文章主要介紹了
建立家用服务器|软件站|第三日
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
相比音樂(lè)上傳,修改了只能上傳4M文件的情況。
通過(guò)編輯web.config來(lái)做到的。
下面是代碼:
uploadfiles.aspx 1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="uploadfiles.aspx.cs" Inherits="uploadfiles" %> 2 3 <!DOCTYPE html> 4 5 <html> 6 <head runat="server"> 7 <title></title> 8 </head> 9 <body> 10 <asp:Literal ID="Literal1" runat="server"></asp:Literal> 11 <hr /> 12 <form method="post" runat="server"> 13 <asp:FileUpload ID="FileUpload1" runat="server" /> 14 <asp:Button ID="Button1" runat="server" Text="上傳文件" οnclick="Button1_Click" /> 15 </form> 16 17 </body> 18 </html> uploadfiles.aspx.cs 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 using System.IO; 8 using System.Text; 9 10 public partial class uploadfiles : System.Web.UI.Page 11 { 12 protected void Page_Load(object sender, EventArgs e) 13 { 14 DirectoryInfo dir = new DirectoryInfo(Server.MapPath("./files")); 15 FileInfo[] files = dir.GetFiles("*.*"); 16 StringBuilder sb = new StringBuilder(); 17 for (int i = 0; i < files.Length; i++) 18 { 19 20 sb.Append("<a href='" + "files/" + files[i].Name + "'>" + files[i].Name + "</a><br />"); 21 } 22 Literal1.Text = sb.ToString(); 23 } 24 protected void Button1_Click(object sender, EventArgs e) 25 { 26 if (FileUpload1.FileName != "" && FileUpload1.FileName != null) 27 { 28 string filepath = FileUpload1.FileName; 29 filepath = Server.MapPath("./files") + "\\" + filepath; 30 FileUpload1.SaveAs(filepath); 31 } 32 33 DirectoryInfo dir = new DirectoryInfo(Server.MapPath("./files")); 34 FileInfo[] files = dir.GetFiles("*.*"); 35 StringBuilder sb = new StringBuilder(); 36 for (int i = 0; i < files.Length; i++) 37 { 38 39 sb.Append("<a href='" + "files/" + files[i].Name + "'>" + files[i].Name + "</a><br />"); 40 } 41 Literal1.Text = sb.ToString(); 42 43 } 44 } web.config <?xml version="1.0"?> <!--有關(guān)如何配置 ASP.NET 應(yīng)用程序的詳細(xì)信息,請(qǐng)?jiān)L問(wèn)http://go.microsoft.com/fwlink/?LinkId=169433--> <configuration><system.web><httpRuntime executionTimeout="600" maxRequestLength="951200" useFullyQualifiedRedirectUrl="true" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableVersionHeader="true"/> <compilation debug="true" targetFramework="4.0"/></system.web> </configuration>這很簡(jiǎn)單,甚至是粗劣。以后再繼續(xù)完善。
轉(zhuǎn)載于:https://www.cnblogs.com/yexinwei/archive/2013/01/17/2864352.html
總結(jié)
以上是生活随笔為你收集整理的建立家用服务器|软件站|第三日的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 一淘网挑战百度意在造势 人才储备成最大障
- 下一篇: 网站登录入口| 网站收录入口| 网站登录