C#: Remove line from textfile

by Pieter Brinkman 26. January 2010 03:29

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.

[code:c#]

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

[/code]

 

Tags: , ,

ASP.Net | Linq | C#

Some tips for the Asp.net dropdown control

by Pieter Brinkman 30. December 2008 04:41

I always have problems implementing the Asp.Net dropdown control. Here are some simple tips to make your life (with dropdown controls) easier.

Adding an default item with data binded dropdown

To add an default listItem to your data binded dropdown list you just have to add a ListItem on the first place (0) of your control

[code:c#]

CountryDropdown.DataSource = countryList;
CountryDropdown.DataValueField = "CountryId";
CountryDropdown.DataTextField = "CountryName";
CountryDropdown.DataBind();

//Add the item
CountryDropdown.Items.Inser(0, new ListItem("-- Choose a Country --"));

[/code]


Getting the selected value

[code:c#]

CountryDropdown.Items[CountryDropdown.SelectedIndex].Text;

[/code]


Setting dropdown listitem by value

[code:c#]

dropDownList.SelectedIndex = dropDownList.Items.IndexOf(dropDownList.Items.FindByValue(option.OptionValue));

[/code]

 

Validation on a dropdownlist

[code:c#]

<asp:RequiredFieldValidator id="reqGroupDDL"
        Text="Choose group"
        InitialValue="selectGroup"
        ControlToValidate="GroupDDL"
        Runat="server" />

[/code]


Hope it helps.

Tags: , , ,

ASP.Net | Controls

Run website on IIS7 (Vista) in classic mode

by Pieter Brinkman 3. December 2008 06:07

If you run your website on IIS7 you can run into the following HTTP errors: 500.22, 500.23

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.


If you don't want to change your web.config and still want to run the website on IIS7 you have to change the Application Pool of your Website.

Open IIS, go to your Application Pools, find your Application Pool and double click the Managed PipeLine Mode.

 

Set the Manage Pipeline mode from Integrated to Classic.


Set IIS7 Application Pool Defaults
You can also set the Manage pipeline mode in the Application Pool Defaults. You can do this in IIS7 by clicking on Set Application Pool Defaults.

 

And then change the Managed Pipline Mode to Classic.

 


The other way is changing your web.config to work with IIS7. You can get more information about this by reading this post.

 

Tags: , ,

ASP.Net

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About Me

My name is Pieter Brinkman I am a .NET Software Engineer for Achmea IT in De Meern, The Netherlands. My interests are mainly web applications created with ASP.NET, MSSQL and Silverlight.

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

RecentComments

Comment RSS

Most comments

club penguin cheats club penguin cheats
4 comments
us United States
Web Design Company Web Design Company
2 comments
Web design Web design
2 comments
gb United Kingdom