C#: Remove line from textfile

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)

With the following code you can remove a line from a textfile (web.config). If the string is within a line the line will be removed.


string configFile = @"C:devweb.config";
List<string> lineList = File.ReadAllLines(configFile).ToList();
lineList = lineList.Where(x => x.IndexOf("<!--") <= 0).ToList();
File.WriteAllLines(configFile, lineList.ToArray());


VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
C#: Remove line from textfile Pieter Brinkman avatarAuthor: Pieter Brinkman ()

Pieter is Technical Marketing Manager for Sitecore Netherlands and owner of Gaatverweg.nl. He has more than ten years experience with software developing in multiple programming languages and with different Content Management Systems. Before joining Sitecore Pieter was a lead developer for multiple Sitecore and .Net projects, he joined Sitecore in 2011 as an Solution Architect in The Netherlands, after two years as an Solution Architect he joined the Technical Marketing department. In the role as Techinical Marketing Manager he is responsible for the Global MVP program and the Sitecore technical branding strategy. You can follow Pieter on twitter: @pieterbrink123 or Google+

C#: Remove line from textfile WebsiteC#: Remove line from textfile TwitterC#: Remove line from textfile Google PlusC#: Remove line from textfile Linkedin

Related posts

Asp.Net: keyboard sort items
Set CultureCode for RDLC (SQL reporting report)
WCF webservice error with DBML objects
SQLReporting service: Deployment

0 Responses to C#: Remove line from textfile

Comments
Tweets
Pingbacks
  • Click on a tab to select how you'd like to leave your comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>