Questions tagged [writealltext]

29 questions
15
votes
3 answers

File.WriteAllText and Concurrent Accesses

Suppose I'm writing a very long string to a file using File.WriteAllText, and another thread or process is trying to read the same file. Would it throw any exception? In other words, what is the FileShare parameter that the File.WriteAllText method…
Feyyaz
  • 3,147
  • 4
  • 35
  • 50
4
votes
2 answers

Write text to file in C# with 513 space characters

Here is a code that writes the string to a file System.IO.File.WriteAllText("test.txt", "P …
amyn
  • 922
  • 11
  • 24
3
votes
6 answers

File.WriteAllText is inserting a space after every character

File.WriteAllText is inserting a space after every letter and quotation. Example: Original File "JobID" "ParentJobID" New File " J o b I D " " P a r e n t J o b I D " CODE using System; using System.IO; using System.Collections.Generic; using…
Jake H.
  • 563
  • 2
  • 11
  • 23
2
votes
1 answer

How to create a text file and append text to the existing file?

I'm trying to save my textbox1 content into a text file to my computer. What I want to do is to create a save directory and when it's set up, I will save the content of textbox1 to that txt file. Not just once, I want to append the content of the…
Newbie TJ
  • 35
  • 5
2
votes
1 answer

Performance wise: File.Copy vs File.WriteAllText function in C#?

I have file content in string and I need to put the same content in 3 different files. So, I am using File.WriteAllText() function of C# to put the content in first file. now, for other 2 files, I have two options: Using File.Copy(firstFile,…
Vivek Agrawal
  • 113
  • 11
2
votes
4 answers

Text file doesn't get saved but no errors (C#)

I've been looking on many websites now for the answer, but all working answers only work for the richTextbox, and I'm using the normal textbox. I'm trying to save the contents of the textbox to a file of choice, but for some reason the file doesn't…
DutchLearner
  • 335
  • 3
  • 13
1
vote
0 answers

UnauthorizedAccessException on WriteAllText c#

Given an existing temp directory (d:\temp), we run the following code [Test] public void Test() { for (int i = 0; i < 10000; i++) { Console.WriteLine(i); File.WriteAllText(@"d:\temp\file.txt", " "); …
xpuser
  • 11
  • 2
1
vote
1 answer

calling File.WriteAllText while computer crashes results in loss of data

I have following code to save data: File.Copy("data.txt", "data_backup.txt", true); File.WriteAllText("data.txt", JsonConvert.SerializeObject(new { bool1, string1, decimal1, decimal2, int1, datetime, object1, …
LukAss741
  • 771
  • 1
  • 7
  • 24
1
vote
1 answer

File Save Location Not Always Updated

I am using the FolderBrowserDialog to let the user select a location to save files, and/or create a new folder. It is working 99% of the time, however in some instances when the user clicks the Create New Folder button, changes the name, then…
Smith Stanley
  • 461
  • 1
  • 8
  • 25
1
vote
1 answer

File.ReadAllText prevents Form from closing on x button click

I have a weird problem. I want to write the visible textBox.Text to an "ini" file on FormClosing (right before the form shuts down), so I double clicked that event under the main form's Properties panel and filled the associated function as…
betaFlux
  • 183
  • 1
  • 3
  • 12
1
vote
3 answers

Can't write string to text file two times

i have a two strings with a c# program named eMail & password and i have a regex that check if the text match or not, if the two strings are verified it will save these two strings in 2 different textfiles this is my code: string eMail =…
1
vote
2 answers

File.WriteAllText issue

I am trying to save a number of different forms to a text file, currently I have: Temperature Wind Rain Cloud The issue that I'm having is that it only saves the "Cloud" data. Is there a way I can save all the information on submission and have…
Josh
  • 23
  • 1
  • 9
1
vote
1 answer

How do I write to an opened file in vb.net

How do I write to an opened file in vb.net I'm using this function right now My.Computer.FileSystem.WriteAllText(filepath, createString(), True) However, if the file is opened, it will give an error saying that the file is being used by another…
sicKo
  • 1,241
  • 1
  • 12
  • 35
0
votes
1 answer

Saving changes to file opened via dropdownlist

So I had help in getting my code to work, turns out I had something missing in my Combobox control. What I'm trying to achieve: I'm selecting a file via a drop-down list, once selected, my RichTextBox shows the contents of the entire file. I want to…
Dude85
  • 41
  • 1
  • 5
0
votes
3 answers

WriteAllText method returns the last row, instead of the entire rows of the file

I have a code that: reads a text file, replaces all "spaces" with ";", removes the repetition of the character ";" and saves a new file with all changes. But instead of writing all the rows in the file, it writes only the last row. static void…
Alex27
  • 87
  • 10
1
2