i convert the byte array file to a file in a readable format,when i display the file in a webpage it shows the content in unreadable format,how can i display the content in a readable format in webpage.if i use a word application it shows the correct answer.how can i dispaly it.here i attached my codings
rdr = cmd.ExecuteReader();{
while (rdr.Read()){r2 = ((
fs.Write(r2, 0, r2.Length);
fs.Close();}
StreamReader str =null;
str = File.OpenText("D:/karthi/resume/r1.txt");
TextBox2.Text = content;
thank u

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Feb 21, 2011, 11:17 PM EST
Just try this!
string str = null;
try {
FileStream reader = new FileStream("D:/karthi/resume/r1.txt", FileMode.Open,FileAccess.Read);
char[] buffer = new char[32];
StringBuilder sb = new StringBuilder();
int count;
while ((count = reader.read(buffer, 0, buffer.length)) > -1)
{
sb.append(buffer, 0, count);
}
reader.close();
str = sb.toString();
}
catch (IOException ex)
{
str = "Failed to load text";
}
yourTextBox.Text = str;
It works fine.
If you feel this will work for you please Make this is ANSWER
krithika muthukrishnanRank #8,369 · 223 reputationPosted Feb 22, 2011, 1:00 AM EST
error : The type or namespace name 'StringBuffer' could not be found (are you missing a using directive or an assembly reference.error will occur how can i solve this.
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Feb 22, 2011, 1:12 AM EST
Just place the cursor on that StringBuilder and press CTRL+.(Dot) else right click on StringBuilder and choose Resolve. it will add reference automatically.
krithika muthukrishnanRank #8,369 · 223 reputationPosted Feb 22, 2011, 1:28 AM EST
Error 1 'System.IO.FileStream' does not contain a definition for 'read' and no extension method 'read' accepting a first argument of type 'System.IO.FileStream' could be found (are you missing a using directive or an assembly reference?)
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Feb 22, 2011, 1:42 AM EST
The reference fot StringBuilder is System.Text
.Net library - mscorlib (in mscorlib.dll).
krithika muthukrishnanRank #8,369 · 223 reputationPosted Feb 22, 2011, 1:51 AM EST
the error :
Error 1 The best overloaded method match for 'System.IO.Stream.Read(byte[], int, int)' has some invalid arguments
Error 2 Argument '1': cannot convert from 'char[]' to 'byte[]'
will occur.how can i solve this
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Feb 22, 2011, 2:24 AM EST
Just download the project created as your need.
I attached the project in this reply.
Thanks. Dont forget to make this as ANSWER.
And also read my articles.
Madhu KRank #1,514 · 1.1K reputationPosted Feb 22, 2011, 3:14 AM EST
krithika muthukrishnanRank #8,369 · 223 reputationPosted Feb 22, 2011, 7:01 PM EST
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Feb 23, 2011, 4:38 AM EST
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ReadingTextFile
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string pathSource = @"d:\sample.txt";
try
{
using (FileStream fsSource = new FileStream(pathSource,
FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
byte[] bytes = new byte[fsSource.Length];
int numBytesToRead = (int)fsSource.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
int n = fsSource.Read(bytes, numBytesRead, numBytesToRead);
if (n == 0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
numBytesToRead = bytes.Length;
string str = System.Text.ASCIIEncoding.ASCII.GetString(bytes);
textBox1.Text = str;
}
}
catch (FileNotFoundException ioEx)
{
Console.WriteLine(ioEx.Message);
}
}
// Clear text box
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
}
}
}
This the Code.
krithika muthukrishnanRank #8,369 · 223 reputationPosted Feb 23, 2011, 7:37 PM EST
i retrieve the binary data from a table and i want to convert the binary file to a text file and display it in a web page.
i understand ur coding when i used this the content thar are displayed in a text box is not in text format.here i attached the codings.
Suthish NairRank #92 · 22.8K reputationPosted Feb 24, 2011, 1:09 AM EST
What is the actual format of the data (file that uploaded) that you retrieving from database.
Is it .doc or .txt.
If its .doc then how can you able to display it in a .txt file.