PDA

View Full Version : سوال: ریختن کل یک فایل txt در یک متغیر



drsina
سه شنبه 14 آبان 1392, 17:09 عصر
سلام
شاید سوالم درست نباشه ، ولی میشه کل یک فایل تکست رو رووی یه متغیر string ریخت ؟!
کاری که من کردم اینه :


StreamReader sr = new StreamReader(Environment.CurrentDirectory + @"\Log.txt");


string line = sr.ReadLine();

while (line != null)
{
string temp = richTextBox1.Text;

richTextBox1.Text =temp + line;

line = sr.ReadLine();
}
MessageBox.Show(richTextBox2.Text);


حالا جواب نمیده !!! :لبخند:

به نظرتون بهتر راه برای اینکار چیه ؟!
یه متد تبدیل string به باینری دارم ، حالا میخوام ، به عنوان آرگومان محتویات یه فایل رو ارسال کنم.

drsina
سه شنبه 14 آبان 1392, 17:22 عصر
حل شد .



// Read the file as one string.
System.IO.StreamReader myFile = new System.IO.StreamReader("c:\\test.txt");
string myString = myFile.ReadToEnd();

myFile.Close();

// Display the file contents.
Console.WriteLine(myString);
// Suspend the screen.
Console.ReadLine();



ممنون