把文件的名字存在数据库中,实际文件名用Guid表示,将Guid和文件的实际名称的关联存到数据库里。下载时改文件头的名字为实际名称。

解决方案 »

  1.   

    <a href="xx.rar">ss</a>
    显示给用户的名字和实际的名字本来就可以不同的,具体怎么实现都可以啊!
      

  2.   

    上传时防止产生重复文件名,并且以文件名加日期加序列号再加后缀组成的。
    private string GetFileName(string strFileName,string strExt)
            {
                int intNo = 1;
                FileInfo fi = new FileInfo(strFileName + intNo.ToString() + strExt);            //如果文件存在
                while(fi.Exists)
                {
                    intNo += 1;
                    fi = new FileInfo(strFileName + intNo.ToString() + strExt);
                }
                return fi.Name;
            }
    这是我在程序中用到的方法,这是调用
     private void btnAddFile_ServerClick(object sender, System.EventArgs e)
            {
                if (upFile.PostedFile.ContentLength == 0)
                {
                    this.showMessage("请选择要上传的文件");
                    return;
                }
                //上传文件
                string strFileName = upFile.PostedFile.FileName;
                
                FileInfo fi = new FileInfo(strFileName);
                //文件的后缀
                string strExt = fi.Extension;            strFileName = strFileName.Substring(strFileName.LastIndexOf(@"\")+1);            //判断是否有重名的文件
                ListItem li = lstFile.Items.FindByText(strFileName);
                if (li != null)
                {
                    this.showMessage("已存在相同名称的文件");
                    return;
                }
                
                //产生文件的不重复的名称
                string strFullName = string.Empty;
                strFullName = Server.MapPath("../") + @"Doc\" + strFileName.Substring(0,strFileName.Length - strExt.Length) + DateTime.Now.ToString("yyyyMMdd");
                strFullName = this.GetFileName(strFullName,strExt);            string strFilePath = Server.MapPath("../") + @"Doc\" + strFullName;
                upFile.PostedFile.SaveAs(strFilePath);            //将文件添加到列表中
                li = new ListItem(strFileName,strFullName);
                if (li != null)
                {
                    lstFile.Items.Add(li);
                }
            }
    至于下载我觉得无所谓,你如果想实现的话,可以将文件名的最后几位日期和数字截掉显示出来。
      

  3.   

    上传文件时可以用GUID加以识别,是自动生成的唯一标识符,绝对不会重复的,只要加上这个就可以把后面的一切操作省略,减少了很多麻烦.
      

  4.   

    http://community.csdn.net/Expert/topic/3130/3130241.xml?temp=.9143946
      

  5.   

    做个原名和新名的对照表不久可以了么?----------------------------------------------------------------------
    欢迎试用ASP.NET大文件上传组件(AspnetUpload 1.0 Release & 无刷新进度条)
    http://bestcomy.europe.webmatrixhosting.net
    ----------------------------------------------------------------------
      

  6.   

    <a href="新文件名.rar" title="原文件名">原文件名</a>=================================
    新一代论坛 http://www.xlfancy.com
    1. 所见即所得的Web文本编辑  
    2. 程序代码的高亮显示: 
       Ada、C、C++、C#、Delphi、ILasm、JS.NET、MASM、VB、VB.NET  
    3. 奇快无比的“引用”“编辑”“回复”。任意的同时多次“引用”
       多个不同的发言。
    4. 绝妙的帖子中上传附件的下载记数
      

  7.   

    在ASP时代要上传一个文件是很麻烦的事,有了ASP.Net事情就变得简单.这里我给出一个实例,希望能对朋友们有帮助.文件上传的实例, 来自http://www.chinabs.net">中国BS网
    <%@ Import Namespace="System.IO" %>
    <%@ page Language="C#" debug="true" %>
    <html>
    <head>
    <title>上传文件 , http://www.chinabs.net </title>
    <script language="C#" runat="server">
    //This method is called when the "upload" button id pressed
    public void UploadFile(object sender , EventArgs E)
    {
    //检查上传文件不为空
    if(myFile.PostedFile!=null)

    string nam = myFile.PostedFile.FileName ;
    //取得文件名(抱括路径)里最后一个"."的索引
    int i= nam.LastIndexOf(".");
    //取得文件扩展名
    string newext =nam.Substring(i);
    //这里我自动根据日期和文件大小不同为文件命名,确保文件名不重复
    DateTime now = DateTime.Now; 
    string newname=now.DayOfYear.ToString()+myFile.PostedFile.ContentLength.ToString(); 
    //保存文件到你所要的目录,这里是IIS根目录下的upload目录.你可以改变.
    //注意: 我这里用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替
    myFile.PostedFile.SaveAs(Server.MapPath("\\upload\\"+newname+newext)); 
    //得到这个文件的相关属性:文件名,文件类型,文件大小
    fname.Text=myFile.PostedFile.FileName;
    fenc.Text=myFile.PostedFile.ContentType ;
    fsize.Text=myFile.PostedFile.ContentLength.ToString();
    }

    </script>
    </head>
    <body>
    <center>
    <h3> 文件上传的实例, 来自<a href="http://www.chinabs.net">中国BS网</a></h3>
    <form id="uploderform" method="post" action="FileUpload.aspx" enctype="multipart/form-data" runat="server" >
    <table border="1" cellspacing="2" cellpadding="2" >
    <tr> <td><h5>选择要上传的文件:</h5></td</tr>
    <tr>
    <td>
    <input type="file" id="myFile" runat="server" NAME="myFile">
    </td>
    </tr>
    <tr><td>
    <input type="button" value="上 传" OnServerClick="UploadFile" runat="server" ID="Button1" NAME="Button1">
    </td></tr>
    </table>
    </form>
    <br>
    <br>
    <table border="1" cellspacing="2">
    <tr><td><b>文件资料</b></td>
    <td>&nbsp;</td> 
    </tr>
    <tr>
    <td>文件名 :</td>
    <td><asp:label id="fname" text="" runat="server" /></td></tr>
    <tr>
    <td>文件类型 :</td>
    <td><asp:label id="fenc" runat="server" /></td></tr>
    <tr>
    <td>文件大小 :(in bytes)</td>
    <td><asp:label id="fsize" runat="server" /></td></tr>
    </table>
    <br>
    <br>
    <br>
    </center>
    </body>
    </html>
      

  8.   

    表结构如下
    newname oldname
    new1     old1
    new2     old2
    new3     old3
    怎样把表字段oldname中的值传入到这个函数中DownLoadFile(string FilePath)此函数功能是下载功能
    Public Sub DownLoadFile(ByVal FilePath As String)
            HttpContext.Current.Response.Buffer = True
            HttpContext.Current.Response.Clear()        Dim FilePathAndName As String = HttpContext.Current.Server.MapPath(FilePath)
            If Not File.Exists(FilePathAndName) Then
                HttpContext.Current.Response.Write("<h1>sorry:</h1>" + FilePathAndName + "  No Found!")
                HttpContext.Current.Response.End()
                Return
            End If        Dim separator() As Char = "\".ToCharArray()
            Dim MyFileStream As FileStream
            Dim FileSize As Integer        MyFileStream = New FileStream(FilePathAndName, FileMode.Open)
            FileSize = CType(MyFileStream.Length, Integer)        Dim Buffer(FileSize - 1) As Byte
            MyFileStream.Read(Buffer, 0, CType(FileSize, Integer))
            MyFileStream.Close()        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + FilePathAndName.Split(separator)(FilePathAndName.Split(separator).Length - 1))
            HttpContext.Current.Response.AppendHeader("Content-Length", FileSize.ToString())
            HttpContext.Current.Response.ContentType = "application/octet-stream"        HttpContext.Current.Response.BinaryWrite(Buffer)
            HttpContext.Current.Response.Flush()
        End Sub