Hi Brian,
Thanks for your followup.
I've rechecked the code and it does be a mistake in my code as I used
"Response.Write" to write out the byte[](binary data), this is incorrect. I
should use the "BinaryWrite" method for binary data(byte[] array).
"Response.Write" should be used for string text data.
Here I've pasted two methods both of which can do the work(one write out
binary data and another write out string data), you can have a look and
choose either one as you want:
>>>>>>>>binary approach>>>>>>>>>
protected void BinaryWriteMethod()
{
byte[] bytes = null;
string path = "e:\\temp\\temp.txt"; // This file exists and has
one sentence in it: The quick brown fox...etc.
bytes = System.IO.File.ReadAllBytes(path);
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "text/plain";
Response.ContentEncoding = Encoding.UTF8;
Response.AddHeader("Content-disposition", "attachment;
filename=sometext.txt");
Response.BinaryWrite(bytes);
Response.End();
}
>>>>>>>>>text string approach>>>>>>>>
protected void StringWriteMethod()
{
string path = "e:\\temp\\temp.txt"; // This file exists and
has one sentence in it: The quick brown fox...etc.
StreamReader sr = new StreamReader(path, Encoding.UTF8);
string data = sr.ReadToEnd();
sr.Close();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "text/plain";
Response.ContentEncoding = Encoding.UTF8;
Response.AddHeader("Content-disposition", "attachment;
filename=sometext.txt");
Response.Write(data);
Response.End();
}
BTW, for string text approach, you need to make sure the text
encoding(specified in code) matches the text file's text encoding.
Hope this helps. If there is still anything unclear, please don't hesitate
to let me know.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Brian Simmons" <centraso@newsgroup.nospam>
>References: <#c5n#jB4HHA.4672@TK2MSFTNGP05.phx.gbl>
<iKGdnaUWU_Dw7lnbnZ2dnUVZ8sqjnZ2d@bt.com>
<t-udnbOodYIv7lnbnZ2dnUVZ8qeknZ2d@bt.com>
<F5HBEhH4HHA.6140@TK2MSFTNGHUB02.phx.gbl>
<OBnTnXb5HHA.5984@TK2MSFTNGP04.phx.gbl>
<STsz1Vf5HHA.2340@TK2MSFTNGHUB02.phx.gbl>
>Subject: Re: Serve up file from outside web application directory
>Date: Fri, 24 Aug 2007 09:48:41 -0400
[quoted text clipped - 87 lines]
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
Steven Cheng[MSFT] - 30 Aug 2007 03:42 GMT
Hi Brian,
Any progress on this or does the further info in my last reply still helps
some? If you have any further questions on this, please don't hesitate to
let me know.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>References: <#c5n#jB4HHA.4672@TK2MSFTNGP05.phx.gbl>
<iKGdnaUWU_Dw7lnbnZ2dnUVZ8sqjnZ2d@bt.com>
<t-udnbOodYIv7lnbnZ2dnUVZ8qeknZ2d@bt.com>
<F5HBEhH4HHA.6140@TK2MSFTNGHUB02.phx.gbl>
<OBnTnXb5HHA.5984@TK2MSFTNGP04.phx.gbl>
<STsz1Vf5HHA.2340@TK2MSFTNGHUB02.phx.gbl>
<#MGOOWl5HHA.3940@TK2MSFTNGP05.phx.gbl>
>Hi Brian,
>
[quoted text clipped - 169 lines]
>>> This posting is provided "AS IS" with no warranties, and confers no
>>> rights.
Brian Simmons - 31 Aug 2007 15:36 GMT
Yes, thanks for the follow-up, your corrections solved the issue. Works
like a charm now.
> Hi Brian,
>
[quoted text clipped - 200 lines]
>>>> This posting is provided "AS IS" with no warranties, and confers no
>>>> rights.