This works:
using (StreamWriter stw = new StreamWriter(Server.MapPath("\\xml\\file.xml")))
{
stw.Write(xmlEncStr);
}
This creates an empty file:
using (FileStream file = new FileStream(Server.MapPath("\\xml\\file.xml"), FileMode.CreateNew))
{
using (StreamWriter sw = new StreamWriter(file))
{
sw.Write(xmlEncStr);
...
Hi,
When i write using StreamWriter.WriteLine, it adds CRLF to the string and sends it (to the SerialPort).
When i read a string in the same C# program using StreamReader.ReadLine with data like below, it only reads upto the first CR represented by the first (char)13.ToString(), not the CRLF that is represented by the (char)13.ToString...
I would like to pre-pend(to the beginning) a file with a string in C#.
Currently, I am just replacing content of the file with my string plus original content.
I DO NOT WANT TO DO THIS, because streamwriter will mess-up encoded characters.
Is there a way to pre-pend a text file without changing it's original encoding(of each character)....
I am using an external library which allows logging using StreamWriter - now I want to add some handling based on the content of the logging. As I want to avoid to loop through the log file, I would like to write a class which inherits from StreamWriter.
What is the best way to inherit from StreamWriter with as few re-implementations of ...
System.Diagnostics.Process exposes a StreamWriter named StandardInput, which accepts only characters as far as I know.
But I need to send keystrokes as well, and some keystrokes don't map well to characters.
What should I do?
...
I'm using the Console.SetOut method to write all my Console.Out.WriteLines to a file, and this works. The only problem is that it only writes everything to the textfile when I close my application instead of it writing whenever a Console.Out.WriteLine happens.
Any ideas on how I can realise this?
How I do it:
Before Application.Run();
...
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 = _log...
Following on from my previous question...
The following code creates log files on a web server:
private void LogMessage(Message msg)
{
using (StreamWriter sw = File.AppendText(_logDirectory + DateTime.Now.ToString("yyyyMMddHH") + ".txt"))
{
sw.WriteLine(msg.ToString());
}
}
The log files are linked to from an admi...
Hi,
i want simultaneously read and write data into file. Can i use StreamReader and StreamWriter with only file? And why code below doesnt out numbers?
var stream = new FileStream(path,FileMode.Create,FileAccess.ReadWrite,FileShare.ReadWrite);
var sw = new StreamWriter(stream);
var sr = new StreamReader(stream);
for(int i=0;i<10;i++)...
Suppose you have a file that you are programmatically logging information into with regards to a process. Kinda like your typical debug Console.WriteLine, but due to the nature of the code you're testing, you don't have a console to write onto so you have to write it somewhere like a file. My current program uses System.IO.StreamWriter f...
I'm writing a utility that takes in a .resx file and creates a javascript object containing properties for all the name/value pairs in the .resx file. This is all well and good, until one of the values in the .resx is
This dealer accepts electronic orders.
/r/nClick to order {0} from this dealer.
I'm adding the name/value pairs to t...
I have a winform with two data grids, and multiple text boxes. I want to give the user the option to export this data to a text document in a location of their choice on their drive. I also want the text document to be pre-formatted, and the values from the text boxes and datagrids to be plugged in.
Is it possible to pre-format a txt ...
What is the difference between instantiating a Stream object, such as MemoryStream and calling the memoryStream.Write() method to write to the stream, and instantiating a StreamWriter object with the stream and calling streamWriter.Write()?
Consider the following scenario:
You have a method that takes a Stream, writes a value, and retu...
So here is my code
if (!File.Exists(pathName))
{
File.Create(pathName);
}
StreamWriter outputFile = new StreamWriter(pathName,true);
But whenever I run the program the first time the path with file gets created. However once I get to the StreamWriter line my program crashes because it says my fie is in use by another process. Is t...
How should I modify the following Vb.Net code to write str to the file in unicode?
Do I need to convert str to Unicode before writing to the file?
Using sw As StreamWriter = New StreamWriter(fname)
sw.Write(str)
sw.Close()
End Using
...
Hi,
I have a wevservice, and I would like to write logs into a textfile.
My problem is that i do not know what path to give when creating the streamwriter:
TextWriter tw = new StreamWriter("????");
Can you please help what path I should enter?
...
Hi
I'm seeing odd behaviour using the StreamWriter class writing extra data to a file using this code:
public void WriteToCSV(string filename)
{
StreamWriter streamWriter = null;
try
{
streamWriter = new StreamWriter(filename);
Log.Info("Writing CSV report header information ... ");
streamWriter.Writ...
So I'm using a StreamReader that uses a MemoryStream to write to a StreamWriter and inside of this application but the memory usage increases by 300mb (From one of the larger inputs) and does not deallocate after Im done using it:
StreamWriter log = new StreamWriter("tempFile.txt");
log.Write(reader.ReadToEnd());
log.Close();
reader.Di...
Hello,
I'm writing an application in C# (it's very basic, for a friend of mine), but I have a StreamWriter object that creates a local file in C:. I have to do Run as Administrator, and it works fine, but otherwise it crashes with "Access to the path 'C:\final.html' is denied."
I've never worked with any sort of security or permissions...
I am currently testing the performance of different methods for logging text data into a file. It seems that when I open/write/close a large amount of times, the extension used affects the performance. (.txt and .log are ~7 times faster)
Code used:
private static void TestWriteSpeed(FileInfo file)
{
Stopwatch watch = new Stopwatch(...