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]
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.
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.