Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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

C#
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();
               }
Posted

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.
 
Share this answer
 
If that is just at the beginning of the file then they are the UTF8 Byte Order Marks[^].
 
Share this answer
 
Comments
sucharita dutta 30-Nov-14 6:26am    
Thanks. But the characters are not only at the beginning of the files.Most of the spaces are getting replaced by those characters in the entire file. but not all the spaces.Couln't identify the particualr scenario when the spaces are replaced by those characters.

Any solution?
Richard MacCutchan 30-Nov-14 6:36am    
You need to look at the source file to see what it contains, and check your download settings to ensure that your MIME type, and other settings, are correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900