问题描述
各位大侠:小弟有个问题请教大家,我想做一个下载列表,文件格式RAR,数据库该怎么样设计。下载页面该怎么代码该怎么写。我是新手不懂,希望大侠们讲的详细点。
解决方案
解决方案二:
数据库可以这么设计:编号,文件名称,文件路径,添加时间页面嘛用repeater或者gridview绑定数据源.至于下载嘛可以用LinkButton的postbackurl绑定路径,普通下载真的没什么,就是用postbackurl直接链接到文件,如:PostBackUrl="~/down/test.rar"
解决方案三:
能详细的吗?最好给个例子
解决方案四:
参考:ASP.NET上传和下载文件的代码上传:(可以实现依次上传多个文件)前台:<%@RegisterTagPrefix="ew1"Namespace="eWorld.UI"Assembly="eWorld.UI,Version=1.9.0.0,Culture=neutral,PublicKeyToken=24d65337282035f2"%><%@Pagelanguage="c#"Codebehind="webNewBid.aspx.cs"AutoEventWireup="false"Inherits="STAR.Web.main.Bidding.WebNewBid"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN"><HTML><HEAD><title>WebNewBid</title><metacontent="MicrosoftVisualStudio.NET7.1"name="GENERATOR"><metacontent="C#"name="CODE_LANGUAGE"><metacontent="JavaScript"name="vs_defaultClientScript"><metacontent="http://schemas.microsoft.com/intellisense/ie5"name="vs_targetSchema"><LINKhref="../../css/style.css"type="text/css"rel="stylesheet"><scriptlanguage="JavaScript">functionaddFile(){varstr='<BR><INPUTtype="file"size="50"NAME="File"runat="server">'document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)}</script></HEAD><bodyMS_POSITIONING="GridLayout"><formid="Form1"method="post"runat="server"><tableclass="fullwidth"align="center"><TR><TDvAlign="top">Attachment:</TD><TD><Pid="MyFile"><inputid="filMyFile"type="file"size="50"name="filMyFile"><inputonclick="addFile()"type="button"value="Add"></P><asp:labelid="lblAttachmentError"runat="server"ForeColor="Red"></asp:label><BR><asp:buttonid="btnUpload"runat="server"Text="Upload"></asp:button><asp:labelid="lblAttachment"runat="server"></asp:label></TD></TR></table></form></body></HTML>后台:usingSystem;usingSystem.Collections;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Drawing;usingSystem.Web;usingSystem.Web.SessionState;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.HtmlControls;usingSystem.Collections.Specialized;privatevoidbtnUpload_Click(objectsender,System.EventArgse){HttpFileCollectionfiles=HttpContext.Current.Request.Files;for(inti=0;i<files.Count;i++){if(i<files.Count&&i<10){if(files[i].FileName!=""||files[i]!=null){intFileSize=6*1024*1024;HttpPostedFilemyFile=files[i];stringstrFilePath=myFile.FileName.ToString().Trim();this.lblAttachmentError.Text="<"+strFilePath+">";//ShowfilenameintnFindSlashPos=strFilePath.Trim().LastIndexOf("\")+1;stringUploadFileName=strFilePath.Substring(nFindSlashPos);stringFileName=this.txtWorkOrder.Text+"_"+string.Format("{0:yyMMdd-hhmmss}",DateTime.Now)+"_"+UploadFileName;if(myFile.FileName.Trim()=="")//EmptyvalueinBrowseBox{this.lblAttachmentError.Text="Nofileselected.";return;}if(myFile.ContentLength!=0){if(myFile.ContentLength>FileSize){this.lblAttachmentError.Text="FileSizeislimitedto6MBonly.";return;}this.lblAttachment.Text+="<BR>"+FileName;this.lblAttachmentError.Text="";//strings=this.Request.PhysicalApplicationPath.ToString().Trim();//strings1=this.Request.ApplicationPath.ToString().Trim();//strings3=this.Server.MapPath("");myFile.SaveAs(this.Request.PhysicalApplicationPath.ToString().Trim()+@"uploads"+FileName);ArrayFileName[i]=FileName;////return;}else{this.lblAttachmentError.Text="Filenotfound.";return;}}}elsethis.lblAttachmentError.Text="UploadedFileexceedlimits.";}}下载:(我只给了后太代码)publicboolResponseFile(HttpRequest_Request,HttpResponse_Response,string_fileName,string_fullPath,long_speed){try{FileStreammyFile=newFileStream(_fullPath,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);BinaryReaderbr=newBinaryReader(myFile);try{_Response.AddHeader("Accept-Ranges","bytes");_Response.Buffer=false;longfileLength=myFile.Length;longstartBytes=0;Int16pack=10240;Int16sleep=Convert.ToInt16(Math.Floor(1000*pack/_speed)+1);if(!(_Request.Headers("Range")==null)){_Response.StatusCode=206;char[]splitChar=newchar[1];splitChar(0)="=";splitChar(1)="-";string[][0]range=_Request.Headers("Range").Split("a");startBytes=Convert.ToInt64(range(1));}_Response.AddHeader("Content-Length",(fileLength-startBytes).ToString());if((startBytes!=0)){_Response.AddHeader("Content-Range",string.Format("bytes{0}-{1}/{2}",startBytes,fileLength-1,fileLength));}_Response.AddHeader("Connection","Keep-Alive");_Response.ContentType="application/octet-stream";_Response.AddHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(_fileName,System.Text.Encoding.UTF8));br.BaseStream.Seek(startBytes,SeekOrigin.Begin);longmaxCount=Convert.ToInt64(Math.Floor((fileLength-startBytes)/pack)+1);longi;for(inti=0;i<=maxCount;i++){if((_Response.IsClientConnected)){_Response.BinaryWrite(br.ReadBytes(pack));Thread.Sleep(sleep);}else{i=maxCount;}}}catch(Exceptione){returnfalse;}finally{br.Close();myFile.Close();}}catch{returnfalse;}}