我在上传文件的时候是用时间作为文件名称保存的,但文件的中文名称也保存到数据库里面去了,现在客户下载的时候看到的文件名称是时间名称,能否在客户点击"保存"的那一刻让保存的文件名称变成数据库里那个事先保存的中文名称呢? 

解决方案 »

  1.   


    System.Drawing.Image image,newimage;                                     //定义image类的对象
                    protected string imagePath;                                              //图片路径
                    protected string imageType;                                              //图片类型
                    protected string imageName;
                    protected System.Web.UI.WebControls.RadioButtonList choice;                                              //图片名称
                    System.Drawing.Image.GetThumbnailImageAbort callb =null;                 //提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行,如果此方法确定GetThumbnailImage方法应提前停止执行,则返回true,否则返回false
    CODE:  [Copy to clipboard]
    --------------------------------------------------------------------------------private void btn_upload_Click(object sender, System.EventArgs e)
                    {
                            string mPath,img_source,img_small;
                            string pid = Request.QueryString["pid"];
                            string typeid = Request.QueryString["typeid"];
                            string typef = Request.QueryString["typef"];                        if(""!= upImage.PostedFile.FileName)
                            {
                                    imagePath = upImage.PostedFile.FileName;
                                    //取得图片类型
                                    imageType = imagePath.Substring(imagePath.LastIndexOf(".")+1);
                                    //取得图片名称
                                    imageName = DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+imagePath.Substring(imagePath.LastIndexOf("\\")+1);
                                    if("jpg"!= imageType && "gif"!= imageType )
                                    {
                                            Response.Write("<script language='javascript'>alert('对不起!请您选择jpg或者gif格式的图片!');</script>");
                                            return;
                                    }
                                    else
                                    {
                                            
                                            mPath = Server.MapPath("../../picture");                                                                        //建立虚拟路径
                                            upImage.PostedFile.SaveAs(mPath+"\\"+imageName);                                                        //保存到虚拟路径
                                            img_source = "picture/" + imageName;                          //显示原图
                                            image = System.Drawing.Image.FromFile(mPath+"\\"+imageName);                                                //为上传的图片建立引用
                                            newimage = image.GetThumbnailImage(184,148,callb,new System.IntPtr());                                        //生成缩略图
                                            newimage.Save(Server.MapPath("../../picture")+"\\small"+imageName);                                                //把缩略图保存到指定的虚拟路径
                                            image.Dispose();                                                                                        //释放image对象占用的资源
                                            newimage.Dispose();                                                                                        //释放newimage对象的资源
                                            img_small = "picture/" + "small" + imageName;                 //显示缩略图                                        
                                            string imgid = pub.AddImage(txt_name.Text,img_source,img_small,txt_author.Text,Int32.Parse(pid),Int32.Parse(typeid));
                                            if (imgid != "")
                                            {
                                                    string UserChoice = choice.SelectedValue;
                                                    switch(UserChoice)
                                                    {
                                                            case "1":
                                                                    Response.Redirect ("index.aspx?typeid="+typeid+"&typef="+typef+"&pid="+pid+"");
                                                                    break;
                                                            case "2":
                                                            {
                                                                    txt_name.Text = "";
                                                                    txt_author.Text = "";
                                                            }
                                                                    break;
                                                    }
                                            }
                                            else
                                            {
                                                    txtMessage.Text ="不好意思,上传图片失败!";                                        }
                                    }
                            }        
                    }
      

  2.   

    add a headerResponse.ContentType = "......";
    Response.AddHeader("Content-Disposition", "attachment; filename=\"" + YourFileNameHere + "\"");
      

  3.   

    <asp:TemplateColumn HeaderText="生產排程" SortExpression="filename">
    <ItemTemplate>
    <a href='<%#String.Format("../uploadfile/{0}", DataBinder.Eval(Container.DataItem, "filename"))%>' target=_blank><%#String.Format("{0}", DataBinder.Eval(Container.DataItem, "filename"))%></a>
    </ItemTemplate>
    </asp:TemplateColumn>思归,我写的下载的语句是这样的,请问你写的是什么意思啊?
      

  4.   

    你是怎么存上传的文件的?是存在数据库里还是在服务器的硬盘上?如果是后者,那么你给用户的是直接的连接,那么无法动态改动文件名的,建议<a href='<%#String.Format("download.aspx?file={0}&originfile={1}", DataBinder.Eval(Container.DataItem, "filename"), DataBinder.Eval(Container.DataItem, "oldfilename"))%>' target=_blank><%#String.Format("{0}", DataBinder.Eval(Container.DataItem, "filename"))%></a>在download.aspx里,大概这么做string s = Request.QueryString["file"];
    string filename = Server.MapPath("../uploadfile/" + s);
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=\" + Request.QueryString["originfile"] + "\"");
    Response.WriteFile(filename);
    Response.End();
      

  5.   

    編譯器錯誤訊息: CS1026: 必須是 )行 40: Response.AddHeader("Content-Disposition", "attachment; filename=\" + Request.QueryString["originfile"] + "\"");
      

  6.   

    Response.AddHeader("Content-Disposition", "attachment; filename=" + Request.QueryString["originfile"]);
      

  7.   

    <asp:TemplateColumn HeaderText="開啓">
    <ItemTemplate>
    <a href='<%#String.Format("download.aspx?file={0}&filename={1}", DataBinder.Eval(Container.DataItem, "filename"), DataBinder.Eval(Container.DataItem, "filename"))%>' target=_blank><%#String.Format("{0}", DataBinder.Eval(Container.DataItem, "filename2"))%></a>
    </ItemTemplate>
    </asp:TemplateColumn>
    ---------------------------------------
    string s = Request.QueryString["filename"];
    string filename = Server.MapPath("../uploadfile/" + s);
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + Request.QueryString["filename"]);
    Response.WriteFile(filename);
    Response.End();如果保存的是英文名字就正常保存为英文名字.
    但如果保存的是中文名字就是
    CABI8RNT.
    这样的?
    而且每次点击显示的都不同
    为什么啊?
      

  8.   

    try the following, didn't test, so it might not work1. change DataBinder.Eval(Container.DataItem, "filename") toHttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem, "filename").ToString(),System.Text.Encoding.GetEncoding("GB2312"))2. Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Text.Encoding.UTF8.UrlEncode(HttpUtility.UrlDecode(Request.QueryString["filename"],System.Text.Encoding.GetEncoding("GB2312")));
      

  9.   

    Response.AddHeader("Content-Disposition", "attachment; filename=" +HttpUtility.UrlEncode(HttpUtility.UrlDecode(Request.QueryString["filename"],System.Text.Encoding.GetEncoding("utf-8")),System.Text.Encoding.UTF8));例外詳細資訊: System.ArgumentException: 路徑中有不合法的字元。
    行 40: string s = Request.Params["filename"];
    行 41: string filename = Server.MapPath("../uploadfile/" + s);如果:
    string filename = Server.MapPath("../uploadfile/護具一廠一課細排程.xls");
    那么这样是可以下载,但会让繁体数据库里的繁体字(个别繁体字)变成乱码啊
      

  10.   

    如果把数据库里可能变成乱码的繁体字去掉,那么
    行 41: string filename = Server.MapPath("../uploadfile/" + s);
    就可以下载,为什么?<asp:TemplateColumn HeaderText="下載" SortExpression="filename"> <ItemTemplate>
    <a href='<%#String.Format("../uploadfile/{0}", DataBinder.Eval(Container.DataItem, "filename"))%>' target=_blank title="下載"><%#String.Format("{0}", DataBinder.Eval(Container.DataItem, "filename"))%></a>
    </ItemTemplate>
    </asp:TemplateColumn>
    为什么这样不会出现乱码呢,我的意思是字体没有问题,不会有简体字.这点你放心.
      

  11.   

    你试下面这个编码了么?我没测试, so it might not work, but seehttp://groups.google.com/group/microsoft.public.cn.dotnet.framework.aspnet/browse_frm/thread/c1318f57f88dc467/7bdd03bc27bb29c8?tvc=1&q=content-disposition+attachment+gb2312&hl=en#7bdd03bc27bb29c81.<a href='<%#String.Format("download.aspx?filename={0}", HttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem, "filename").ToString())))%>' target=_blank title="下載"><%#String.Format("{0}", DataBinder.Eval(Container.DataItem, "filename"))%></a>
    2. in download.aspx:string s = Request.Params["filename"];
    string filename = Server.MapPath("../uploadfile/" + HttpUtility.UrlDecode(s)));...
    Response.AddHeader("Content-Disposition", "attachment; filename=" + s);?