streamwriter

Started Process from .NET but RedirectedStandardOutput doesn't support UTF-8

喜你入骨 提交于 2019-12-11 08:38:41
问题 I am trying to call php's HTML purifier from .NET using this code: Process myProcess = new Process(); myProcess.StartInfo.FileName = "C:\Path\to\php.exe"; myProcess.StartInfo.Arguments = "C:\Path\to\purify.php"; myProcess.StartInfo.UseShellExecute = false; myProcess.StartInfo.RedirectStandardOutput = true; myProcess.StartInfo.RedirectStandardInput = true; myProcess.Start(); StreamWriter myStreamWriter = myProcess.StandardInput; String inputText; inputText = txtCodes.Text; if (inputText.Length

Summing duplicate values while reading in data for different types of outputs

怎甘沉沦 提交于 2019-12-11 08:30:52
问题 I am reading in 5000 rows of data from a stream as follows from top to bottom and store it in a new CSV file. ProductCode |Name | Type | Size | Price ABC | Shoe | Trainers | 3 | 3.99 ABC | Shoe | Trainers | 3 | 4.99 ABC | Shoe | Trainers | 4 | 5.99 ABC | Shoe | Heels | 4 | 3.99 ABC | Shoe | Heels | 5 | 4.99 ABC | Shoe | Heels | 3 | 5.99 ... Instead of having duplicate entries, I want the CSV to have one row but with the Price summed: E.g. If I want a csv file with only ProductCode, Name and

StreamWriter not updating its path on new day

↘锁芯ラ 提交于 2019-12-11 07:18:09
问题 I have a program that's writing to a log file called "appname_yyyyMMdd.log", where appname is the name of my app, and yyyyMMdd is the current date; a sample log file name might be "loglistener_20110615.log" . Anyway, my app creates the log file fine, and it updates it as planned. However, once the date changes, the app doesn't log anything, and it doesn't create a new file. In other words, since today is 6/15, I need it to create a file called "loglistener_20110616.log" after midnight tonight

How to append data to file using SaveFileDialog

旧城冷巷雨未停 提交于 2019-12-11 06:27:07
问题 I want to write data to file, so I use SaveFileDialog object: Public Class Form3 Inherits Form Public callerForm3To1 As Form1 Dim fileStream As Stream = Nothing Dim fileSW As StreamWriter = Nothing Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load SaveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" SaveFileDialog1.FilterIndex = 2 SaveFileDialog1.RestoreDirectory = True FlagWriteToFile = False If SaveFileDialog1.ShowDialog() = DialogResult.OK Then

How to edit a text file in c# with StreamWriter?

青春壹個敷衍的年華 提交于 2019-12-11 04:03:37
问题 I have a method to edit a word from a text file file and display it on the command prompt. Now I an trying to make a method to edit a word from a text file and write it to a new file. I would also like to mention that I cannot use the File or Regex class since I am not allowed to use it for my assignment. Here is my code for the StreamReader: public void EditorialControl(string fileName, string word, string replacement) { List<string> list = new List<string>(); using (StreamReader reader =

How do I force write to file using StreamWriter?

核能气质少年 提交于 2019-12-11 02:18:30
问题 I always use streamwriter writer = new StreamWriter(file) to write to file. The problem is it wont actually write to file until writer.close() . If between class create and class close something bad happens (and the program never reaches writer close), I wont get any information in the file. How to force write between create and close? 回答1: Make sure you have your code wrapped in a using statement: using (var writer = new StreamWriter(file)) { // do your writing } This will help "clean up" by

Date Modified isn't updated while StreamWriter is open

蓝咒 提交于 2019-12-10 23:38:57
问题 I have a logging solution and write to a textfile which is open when aplication is running. I use StreamWriter to write to file. My logger code is simply (to open stream and to write): public void Open(string filePath, bool append) { if (this.logWriter != null) throw new InvalidOperationException( "Logger is already open"); if (!Directory.Exists(Path.GetDirectoryName(filePath))) Directory.CreateDirectory(Path.GetDirectoryName(filePath)); this.logWriter = new StreamWriter(filePath, append);

Winrt StreamWriter & StorageFile does not completely Overwrite File

不想你离开。 提交于 2019-12-10 19:35:10
问题 Quick search here yielded nothing. So, I have started using some rather roundabout ways to use StreamWriter in my WinRT Application. Reading works well, writing works differently. What' I'm seeing is that when I select my file to write, if I choose a new file then no problem. The file is created as I expect. If I choose to overwrite a file, then the file is overwritten to a point, but the point where the stream stops writing, if the original file was large, then the old contents exist past

.Net StreamWriter.BaseStream, what does this definition mean? “Gets the underlying stream that interfaces with a backing store.”

时光怂恿深爱的人放手 提交于 2019-12-10 19:24:23
问题 I was reading about StreamWriter today, and came across this property, BaseStream . I was looking for a definition and found this "Gets the underlying stream that interfaces with a backing store." from here MSDN - StreamWriter.BaseStream I understand what a BaseStream is for StreamReader, because it's definition is very simply: Returns the underlying stream. But what does the definition of the StreamWriter.BaseStream mean?? Or more clearly, what does this part of the definition mean

StreamWriter not creating new file

安稳与你 提交于 2019-12-10 17:46:59
问题 I'm trying to create a new log file every hour with the following code running on a server. The first log file of the day is being created and written to fine, but no further log files that day get created. Any ideas what might be going wrong? No exceptions are thrown either. private void LogMessage(Message msg) { string name = _logDirectory + DateTime.Today.ToString("yyyyMMddHH") + ".txt"; using (StreamWriter sw = File.AppendText(name)) { sw.WriteLine(msg.ToString()); } } 回答1: The use of