Thursday, June 11, 2015

Text file keeps prompting to be downloaded instead of displaying in browser

Hello Blog, It's been a long time without a post.

Here is one that made it my way recently.

Agency customer:  Hey we have a bunch of text files hosted on website x and two of them are prompting to be downloaded, and if we download and view them they don't look the same as the others.  The other files simply display the text in the browser just fine. What's up?


A scheduled process sends the files to the web. Developer reruns the job, same results. I take a look at the two files that are having the issue and compare against a couple not having the issue. Turns out the two text files having the issue have nulls in them. Take the nulls out, post a test copy and they work fine, happily displaying in the browser. Update developer he needs to remove the nulls form the file he produces, which he does, and done, no more crisis.  But lets say you need to test the scenario as I did. Here is a quick way to do that. Open your text file with NotePad++.

Note the little Nul symbols.  Simply find and replace them.  You can't simply type nul in though. Here is how you can do it with NotePad++.



Open the file in NotePad++, you'll see the NULs.  You can't just type "NUL" into Find what: and expect for them to display.  You'll need to change the Search Mode to Extended.  Then you can simply put \0 (that is a backslash followed by a zero), then if wanting to simply strip them out leave the Replace with: field empty.  Click Replace all.  Save as something else so that you still have the original if needed.  Then upload that file and see if it takes care of the issue.  Of course, if wanting to replace NUL with something else put the replacement in the Replace with: field.

Happy times with your text files on the web!







No comments: