FAQ Database Discussion Community


File.AppendText attempting to write to wrong location

c#,file,console,streamwriter
I have a C# console application that runs as a scheduled task within Windows Task Scheduler. This console app writes to a log file that when runs within debug mode creates and writes to the file within the application folder itself. However, when it runs in the task scheduler it...

Writing a File to the Specified Folder

c#,streamwriter,visual-studio-express,savefiledialog
This question is in conjunction with my other: Write a text file to a sub-folder. This time, I have a program that has a text folder to open a file, then extract data from that file. Then I can save it by saying where to save it. private void btnExtract1_Click(object...

Specified argument was out of the range of valid value to get data from network in c#

c#,sockets,buffer,streamwriter
I am trying to send a command to a sensor and get the data from it using this code : const int PORT_NO = 3000; const string SERVER_IP = "192.168.2.44"; //---listen at the specified IP and port no.--- IPAddress localAdd = IPAddress.Any; TcpListener listener = new TcpListener(localAdd, PORT_NO); Console.WriteLine("Listening..."); listener.Start();...

C#, Split after 2 ;'s in same line

c#,visual-studio-2010,csv,streamreader,streamwriter
I'm generating a list of from/to coordinate points, together with the distance/time between those points. For illustration: the header of the end product looks like this writer.WriteLine("fromX" + ";" + "fromY" + ";" + "toX" + ";" + "toY" + ";" + "distance" + ";" + "time"); The process of...

Overwriting lines in a txt file while searching for the lines

c#,streamreader,streamwriter
I'm working on a video game with C#. I have a list of users with their coin amounts in a .txt file, and I want for their amounts to be overwritten when they save. I can't figure out how to use SteamWriter within SteamReader without a "file already being used"...

Waiting for ThreadPool to finish

c#,multithreading,threadpool,streamwriter
I developed an application that saves 10000 lines of lorem ipsum in .txt file on the disk. I used StreamWriter to actually write these lines, and ThreadPool to distribute the computational process to the available threads/cores. The saving is very fast, even with 1 million lines, but the problem is,...

How to run 2 StreamWriters in parallel [closed]

c#,multithreading,async-await,task-parallel-library,streamwriter
Recently I was working on a project to write a csv file and an XML file at the same time. They contain the same metadata information, how to open two StreamWriters in C# at the same time?

FileStream writing buffer to file

c#,filestream,streamwriter
I'm trying to upload a .srt file through an API that takes File as a parameter. The file is stored on the server, and I'm using FileStream and StreamWriter to write to it: string path = Server.MapPath("~/App_Data/captions/" + entryId) + ".srt"; FileStream f = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter s...

Loading cell values in dataGridView from text file C#

c#,datagridview,streamreader,streamwriter
I am using a StreamWriter to write all values on all exisiting cells in a dataGridView, that writer is working perfect. But my reader isn't doing its work very good. This is my writer code(which has no problem): StreamWriter writer = new StreamWriter(valuePath); foreach (DataGridViewRow row in dataGridView1.Rows) { foreach...

StreamWriter not appending to file, instead creating a new file in different directory

c#,file,text,file-io,streamwriter
I am attempting to write from one file to a temp file after making certain changes to some of the data in the source file. This was working until I extracted this logic into its own function. After running some tests I noticed that only the first line was being...

How to delay the StreamWriter loop?

c#,loops,streamwriter
I'm trying to use this newbie-handy console "outputer". When I try to apply the loop on it, it either goes nuts producing huge amounts of lines in output file or not working at all if try to use delay. Extremely simplified version of my issue: C#: using (StreamWriter writer =...

Shortest way to save DataTable to Textfile

c#,datatable,streamwriter
I just found a few answers for this, but found them all horribly long with lots of iterations, so I came up with my own solution: Convert table to string: string myTableAsString = String.Join(Environment.NewLine, myDataTable.Rows.Cast<DataRow>(). Select(r => r.ItemArray).ToArray(). Select(x => String.Join("\t", x.Cast<string>()))); Then simply save string to text file, for...

c# windows app writing text to file

c#,windows,file,streamwriter
Having real problems with writing to a text file using following code using HCP1.Common; using System; using System.Collections.Generic; using System.IO; using System.Linq; using Windows.UI.Xaml.Media.Imaging; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using...

Unable to Remove Carriage Returns and Line Feeds Without Using Debug.Write()

c#,streamwriter
I am trying to output serial data from a GUI in Visual C# onto a text file, however, when I output it, it prints one character on each line. I have tried to replace the carriage returns and line feeds using .TrimEnd('\r','\n'), .Trim(), and .Replace("\r\n", "").Replace("\n", "").Replace("\r", ""). The problem:...

Powershell - Streamwriter

powershell,streamwriter
I need to write to many files as quickly as possible but I'm not getting the results I want using Streamwriter the way I'm using. For example, if I write... $File = "c:\somefile" $Contents = get-content $File $Contents | set-content $File So read the contents of the file, do nothing,...

Delete, copy, and paste string in an array in a text file to a new arry in a text file

c#,arrays,streamreader,streamwriter,file.readalllines
I need some help with file streaming. I have a program that will record names into a string array that will be written to a .txt file. Then if a user wants to delete a specific string from the array in the .txt file. the program will search for the...

I'm trying to write text to a .txt file but it doesn't work [closed]

c#,asp.net,streamwriter,textwriter
I'm trying to write some info to a text file when there is an error in the application. I added this code to the Application_Error method in global.asax but it still dont work: void Application_Error(object sender, EventArgs e) { string path = Server.MapPath("Error.txt"); Exception ex = Server.GetLastError(); if (!File.Exists(path)) {...

Get the BackColor of all cells in dataGridView C#

c#,winforms,datagridview,streamwriter
I want to get the BackColor of all the cells and write them into a text file, so the output would be: YellowGreen Orange SteelBlue, etc. This is what I've tried: void GetColors() { string path = Application.StartupPath + @"/test.txt"; StreamWriter sw = new StreamWriter(path); int n = 0; DataGridViewColumn...

PrintStream Error with no reason?

java,streamwriter,datainputstream,printstream
I am making a server client system in which the client will write a message to the server and the server will save it as a string and print it in the console. But when ever the System tries to read the line I get "PrintStream error" in the console....

C# server logging to text file from console

c#,console,streamwriter
I currently have a client which is communicating with a server on localhost. When the client communicates with the server, the server keeps track of what is happening, eg. string response = "Location updated for " + uname + ": " + uloc; Console.WriteLine(response); I am trying to keep a...

What is the right CSV encoding for c# to open with Excel?

c#,excel,csv,encoding,streamwriter
I write a CSV with my C# CSVWriter based on a StreamWriter. In my data I have a lot of special characters like "Bávaro". So when I use UTF-8 or ASCII to encode my CSV I can't get the "á" but I can open it in Excel afterwards perfectly. When...

C# StreamReader Load Data and post to Form

c#,streamreader,streamwriter
I've been struggling to figure out exactly the best way to handle my situation for a few days now. I'm not able to get the program to function the way I desire. What I have is a .txt file, that has two columns, and 11 seperate lines. It looks as...

Why i can see my StreamWriter lines only at the end of my loop

c#,streamwriter
I have Simple console application and list of files. Every loop over my list i want to write the current file name into simple txt file: String path = @"C:\log.txt"; // location whre to save my txt file List<string> files = new List<string>(); // my files list using (FileStream fs...

how to write formatted text into a file

winforms,c++-cli,streamwriter
I was trying to write to a file from textbox input with date: Here is a part of the code: DateTime dt=System::DateTime::Now; System::IO::StreamWriter^ history = gcnew StreamWriter("history.txt"); history->WriteLine(textBox1->Text); history->WriteLine(dt); history->Close(); But the output is like this: text 09/02/2015 23:26:07 But I want it to be like: text 09/02/2015 23:26:07 And...

Why is my array of struct not resizing with Array.Resize?

c#,arrays,struct,resize,streamwriter
I have an array of struct's declared as public struct classMates { public string first; public string last; public string ID; } I am using StreamReader to read in a .txt file and my variables correspond to their relevant value. ie. first == first name, ID == phone number. My...

Is it possible to make StreamWriter overwrite line without closing the .txt?

c#,streamwriter,overwrite
If StreamWriter has an auto-updating output like some list: Cute cat. Angry dog. Huge elephant. Eternal sunshine. or 1 2 3 4 How is it possible to force StreamWriter to write this list in one line? Dog overwrites cat, elephant overwrites dog, sunshine overwrites elephant and so on. Thus we...

BufferedWriter, FileWriter, Output Stream…What's the most modern way to do these things?

java,file,logging,streamwriter,bufferedwriter
I'm trying to programically create a new a file in java, and write a string array to that file. If the file already exists, I just want to append another string array (This is like a log file). Whats the most 'modern' way to do something like this? Is FileWriter...

Notepad only gets 768 entries of what should be 1000 entries on a Streamwriter text file generator

c#,streamwriter,notepad
I'm making a simple program which is supposed to take an array of 1000 entries of 2 columns and put it into text format and then output it to a file. Something kind of weird happens. The file only receives either 950 or 768 entry rows, not 1000 as it...

Summing duplicate values while reading in data

c#,asp.net,streamwriter
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 | Price ABC | Shoe | Trainers | 3.99 ABC | Shoe | Trainers | 4.99 ABC | Shoe | Trainers...

Saving txt file going to wrong location

c#,winforms,streamwriter,savefiledialog
I'm trying to save a text file log to a specific location from my Windows Form project. I set the InitialDirectory to Path.GetFullPath(filePath) where I pass in filePath which is set as a simple path of "C:\MyWork\EventLogs\" The log saves on Exit of the program (when a user closes or...