星期一, 4月 05, 2010

[Asp.Net] 實作下載檔案連結與檔名編輯問題解決

 下載檔案連結實作如下:
gfa = new Module_Command.GetFileAttach(this.supportFileID, "2");
                            Attach = gfa.Execute();
                            gfa.UnExecute();
                            if (Attach != null)
                            {
                                dtOneFile = (DataTable)Attach;
                                filePath = "course/"
                                + dtOneFile.Rows[0]["CourseID"].ToString()
                                +"/"
                                + dtOneFile.Rows[0]["HomeWorkID"].ToString()
                                +"/attachment/"
                                + dtOneFile.Rows[0]["SupportFileName"].ToString();

                                filename = dtOneFile.Rows[0]["SupportFileName"].ToString();
                                filename = filename.Replace(" ", "%20");


                                //if (context.Request.Browser.Browser == "IE")
                                userAgent = context.Request.Headers.Get("User-Agent");
                                if (userAgent.Contains("MSIE 7.0"))
                                    filename = context.Server.UrlPathEncode(dtOneFile.Rows[0]["SupportFileName"].ToString());


                                context.Response.ContentType = "application/download";
                                context.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + ";");


Reference: 
ASP.NET 如何設定強制下載檔案並正確處理中文檔名的問題  
【茶包射手專欄】Cassini's Response Header Encoding

 

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails