Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9020953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:08:36+00:00 2026-06-16T05:08:36+00:00

Using hostfile in C# I can block websites but I couldn’t unblock them. String

  • 0

Using hostfile in C# I can block websites but I couldn’t unblock them.

String path = @"C:\Windows\System32\drivers\etc\hosts";
StreamWriter sw = new StreamWriter(path, true);
sitetoblock = "\r\n127.0.0.1\t" + txtException.Text;
sw.Write(sitetoblock);
sw.Close();

MessageBox.Show(txtException.Text + " is blocked", "BLOCKED");
lbWebsites.Items.Add(txtException.Text);
txtException.Clear();

Here I need some help to unblock a specific site which is selected from listbox(lbWebsites). Is there a way to remove them from host file? I tried a lot and looked other solutions but something goes wrong in every solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:08:37+00:00Added an answer on June 16, 2026 at 5:08 am

    You may use a StreamReader to read the hosts file into a string. Then, initialize a new instance of a StreamWriter to write the content gathered back excluding the website you want to unblock.

    Example

    string websiteToUnblock = "example.com"; //Initialize a new string of name websiteToUnblock as example.com
    StreamReader myReader = new StreamReader(@"C:\Windows\System32\drivers\etc\hosts"); //Initialize a new instance of StreamReader of name myReader to read the hosts file
    string myString = myReader.ReadToEnd().Replace(websiteToUnblock, ""); //Replace example.com from the content of the hosts file with an empty string
    myReader.Close(); //Close the StreamReader
    
    StreamWriter myWriter = new StreamWriter(@"C:\Windows\System32\drivers\etc\hosts"); //Initialize a new instance of StreamWriter to write to the hosts file; append is set to false as we will overwrite the file with myString
    myWriter.Write(myString); //Write myString to the file
    myWriter.Close(); //Close the StreamWriter
    

    Thanks,

    I hope you find this helpful 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
Using import datetime in python, is it possible to take a formatted time/date string
m3 http://img245.imageshack.us/img245/461/65254534.jpg Chrome using the windows' HOST file: m1 http://img266.imageshack.us/img266/9380/59750633.jpg Android emulator: m2 http://img821.imageshack.us/img821/7363/19470766.jpg
I read a similar post but I am not using ubuntu, and do not
I can access the elmah.axd file, to view errors, when browsing using the localhost
Using HTML 5, I want to play multiple sounds simultaneously. how can I do
Using Rails 3, but I guess doesn't matter. I put this in the template
Using C#, I want to show the image in the Access column but failed
I've been using dynamic libraries and GetProcAddress stuff for quite some time, but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.