?
Solved

c# adding a line to a file

Posted on 2012-08-19
1
Medium Priority
?
595 Views
Last Modified: 2012-08-19
I need to add a line  to an existing file (using c#)
here comes my code:

 void AppendTxtData()
         {
            FileInfo fi = new FileInfo(@"c:\MyFolder\MyFile.txt");
            StreamWriter sw = fi.AppendText();
            sw.WriteLine("MyLine");
            sw.Flush();
            sw.Close();  
        }
 I need to replace the string "Myline" by a  variable and can't find the solution
Thanks for the help
0
Comment
Question by:luciepaul
1 Comment
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 38309953
sw.WriteLine(yourVariableName);
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question