改变文件的名称发送到客户端? [英] Change name of file sent to client?

查看:99
本文介绍了改变文件的名称发送到客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从数据库提取信息,将其转换为.csv格式,并将该文件写入HTT presponse的网页。

I have a webpage that pulls information from a database, converts it to .csv format, and writes the file to the HTTPResponse.

string csv = GetCSV();
Response.Clear();
Response.ContentType = "text/csv";
Response.Write(csv);

这个工作得很好,并且该文件被发送到客户端,没有任何问题。然而,当该文件被发送到客户端,在当前页的名称被使用,而不是更友好的名称(如data.csv)。

This works fine, and the file is sent to the client with no problems. However, when the file is sent to the client, the name of the current page is used, instead of a more friendly name (like "data.csv").

我的问题是,我怎么能更改写入到输出流,而不该文件写入磁盘并重定向客户端文件的URL的文件的名称?

My question is, how can I change the name of the file that is written to the output stream without writing the file to disk and redirecting the client to the file's url?

编辑:感谢您的答复家伙。我得到了同样的答复4,所以我只是选择了第一个作为答案。

推荐答案

我相信这会为你工作。

Response.AddHeader("content-disposition", "attachment; filename=NewFileName.csv");

这篇关于改变文件的名称发送到客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆