streamreader

VCF Vcard import c#

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 03:36:54
问题 iam trying to write a class which imports *.vcf files (Vcard), because i didn´t found a adequate .net class to solve that job. So i decided to treat the *.vcf file like a *.txt file. I just import the whole file, line by line, with a StreamReader. Finally i save the line into a List object. The Code: private List<string> vcardList = new List<String>(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(

how to convert Image to string the most efficient way?

元气小坏坏 提交于 2019-12-07 14:14:41
问题 I want to convert an image file to a string. The following works: MemoryStream ms = new MemoryStream(); Image1.Save(ms, ImageFormat.Jpeg); byte[] picture = ms.ToArray(); string formmattedPic = Convert.ToBase64String(picture); However, when saving this to a XmlWriter, it takes ages before it's saved(20secs for a 26k image file). Is there a way to speed this action up? Thanks, Raks 回答1: There are three points where you are doing large operations needlessly: Getting the stream's bytes Converting

Read Oracle BLOB field

会有一股神秘感。 提交于 2019-12-07 07:07:08
问题 I try to read an Oracle BLOB field and show the content i a richTextBox. The examples i find with google are almost the same but still i can't get it to work. I know that the BLOB field contains serialized data. This is what i have so far: (the connecetion en reader work fine) private void button1_Click_1(object sender, EventArgs e) { //testen of een blob is uit te lezen OracleCommand cmd = new OracleCommand(); cmd.Connection = OraConnection.conn; cmd.CommandText = "select id, blobfield from

StreamReader and binary data

走远了吗. 提交于 2019-12-07 03:32:23
问题 I have this text file what contains different fields. Some fields may contain binary data. I need to get all the data in the file but right now when using StreamReader then it wont read the binary data block and data what comes after that. What would be the best solution to solve this problem? Example: field1|field2|some binary data here|field3 Right now i read in the file like this: public static string _fileToBuffer(string Filename) { if (!File.Exists(Filename)) throw new

vb.net Reading from a .txt file and displaying the contents

那年仲夏 提交于 2019-12-07 02:11:24
I'm making a simple program which reads and writes .txt files. I've got the program to write to and save a .txt file however I'm having some trouble reading from .txt files. Here's what I've got so far: Using openTxt As New OpenFileDialog() If openTxt.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim displayForm As New Form Dim textReader As New System.IO.StreamReader(openTxt.FileName) displayForm.ListBox1.Text = textReader.ReadToEnd textReader.Close() displayForm.Show() Else MessageBox.Show("Not a text file") End If End Using What I would like to happen is when the text has been read it

Why disposing StreamReader makes a stream unreadable? [duplicate]

限于喜欢 提交于 2019-12-06 20:33:56
问题 This question already has answers here : Can you keep a StreamReader from disposing the underlying stream? (8 answers) Closed 4 years ago . I need to read a stream two times, from start to end. But the following code throws an ObjectDisposedException: Cannot access a closed file exception. string fileToReadPath = @"<path here>"; using (FileStream fs = new FileStream(fileToReadPath, FileMode.Open)) { using (StreamReader reader = new StreamReader(fs)) { string text = reader.ReadToEnd(); Console

VCF Vcard import c#

佐手、 提交于 2019-12-06 16:29:42
iam trying to write a class which imports *.vcf files (Vcard), because i didn´t found a adequate .net class to solve that job. So i decided to treat the *.vcf file like a *.txt file. I just import the whole file, line by line, with a StreamReader. Finally i save the line into a List object. The Code: private List<string> vcardList = new List<String>(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(@"H:\VS.vcf")) { string line; while ((line = reader.ReadLine()) != null) { vcardList.Add(line); } } }

C# Reading stream from TcpClient

为君一笑 提交于 2019-12-06 14:55:34
I'm making a server - client program using TcpClient and server. To send from the server I use: static void send(string data) { sw.WriteLine(data + Environment.NewLine); } And when the client connects I'm sending some text: client = listener.AcceptTcpClient(); sr = new StreamReader(client.GetStream()); sw = new StreamWriter(client.GetStream()); string line; try { send("Hello world"); } //More code And to read from client: string data; data = sr.ReadLine(); if(data != string.Empty || data != null) { MessageBox.Show(data); } I tried putting inside while(true) and it froze, I tried putting inside

Override StreamReader's ReadLine method

喜你入骨 提交于 2019-12-06 14:30:52
问题 I'm trying to override a StreamReader's ReadLine method, but having difficulty doing so due to inability to access some private variables. Is this possible, or should I just write my own StreamReader class? 回答1: Assuming you want your custom StreamReader to be usable anywhere that a TextReader can be used there are typically two options. Inherit from StreamReader and override the functions that you want to have work differently. In your case this would be StreamReader.ReadLine. Inherit from

How to read byte[] with current encoding using streamreader

折月煮酒 提交于 2019-12-06 13:35:35
问题 I would like to read byte[] using C# with the current encoding of the file. As written in MSDN the default encoding will be UTF-8 when the constructor has no encoding: var reader = new StreamReader(new MemoryStream(data)). I have also tried this, but still get the file as UTF-8: var reader = new StreamReader(new MemoryStream(data),true) I need to read the byte[] with the current encoding. 回答1: A file has no encoding. A byte array has no encoding. A byte has no encoding. Encoding is something