在下载到客户端时,将附加在csv文件中 [英] � getting appended in the csv file when downloading to client

查看:83
本文介绍了在下载到客户端时,将附加在csv文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





使用下面的c#代码下载.csv文件。但是下载的文件在大多数空间中都包含了characters½字符。如何解决这个问题



  string  fullFilePath = System.Configuration.ConfigurationManager.AppSettings [  ExtractFileLocation] + filename; 
if (File.Exists(fullFilePath))
{



 HttpContext.Current.Response.AddHeader(  Content-disposition  attachment; filename = \ + filename.Replace(filename.Substring( 0 ,filename.LastIndexOf(' 。')),  testfile)+   \); 
HttpContext.Current.Response.ContentType = text / csv;
HttpContext.Current.Response.TransmitFile(fullFilePath);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.SuppressContent = true ;
HttpContext.Current.ApplicationInstance.CompleteRequest();
}

解决方案

我们无法回答这个问题:你需要准确看看发生了什么。

这不太可能是下载过程本身 - 或者每天下载的视频,音乐甚至图像文件都不会起作用,我们现在已经注意到了! :笑:

所以首先使用FTP将文件复制到你的服务器,这样它就完全是二进制相同的,然后用你的软件下载它。



然后使用二进制比较器比较原始文件和下载的版本:快速谷歌会找到许多,其中很多: Google [ ^ ]



然后看看到底有什么区别。我打赌没有一个,它是处理应用程序中的字符集或类似的人工制品。


如果它只是在文件的开头那么它们就是UTF8 字节顺序标记 [ ^ ]

Hi,

Downloading .csv file using the below c# code. But the downloded file is containing � characters in most of the spaces.How to resolve this issue

string fullFilePath = System.Configuration.ConfigurationManager.AppSettings["ExtractFileLocation"] + filename;
                if (File.Exists(fullFilePath))
                {


HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename=\"" + filename.Replace(filename.Substring(0, filename.LastIndexOf('.')), "testfile") + "\"");
                   HttpContext.Current.Response.ContentType = "text/csv";
                   HttpContext.Current.Response.TransmitFile(fullFilePath);
                   HttpContext.Current.Response.Flush();
                   HttpContext.Current.Response.SuppressContent = true;
                   HttpContext.Current.ApplicationInstance.CompleteRequest();
               }

解决方案

We can't answer that: you need to look at exactly what is happening.
It's unlikely to be the download process itself - or none of the video, music, or even image files downloaded daily would ever work, and we would have noticed that by now! :laugh:
So start by copying a file to your server using FTP so it in definitely binary identical, and then download it using your software.

Then compare the original file and the downloaded version using a binary comparer: a quick google will find you many, many of them: Google[^]

Then look and see exactly what the difference is. I'm betting there isn't one and that it's an artefact of character sets in the processing application or similar.


If that is just at the beginning of the file then they are the UTF8 Byte Order Marks[^].


这篇关于在下载到客户端时,将附加在csv文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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