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
Suthish NairPosted Feb 24, 2011, 6:09 AM
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.
krithika muthukrishnanPosted Feb 24, 2011, 12:37 AM
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.
Jaganathan BantheswaranPosted Feb 23, 2011, 9:38 AM
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 muthukrishnanPosted Feb 23, 2011, 12:01 AM
Madhu KPosted Feb 22, 2011, 8:14 AM
Jaganathan BantheswaranPosted Feb 22, 2011, 7:24 AM
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.
krithika muthukrishnanPosted Feb 22, 2011, 6:51 AM
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 BantheswaranPosted Feb 22, 2011, 6:42 AM
The reference fot StringBuilder is System.Text
.Net library - mscorlib (in mscorlib.dll).
krithika muthukrishnanPosted Feb 22, 2011, 6:28 AM
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 BantheswaranPosted Feb 22, 2011, 6:12 AM
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 muthukrishnanPosted Feb 22, 2011, 6:00 AM
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 BantheswaranPosted Feb 22, 2011, 4:17 AM
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