Click here to Skip to main content
15,891,136 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Inserting webcontrol in repeter and datalist Pin
eyeseetee7-Mar-08 0:17
eyeseetee7-Mar-08 0:17 
GeneralRe: Inserting webcontrol in repeter and datalist Pin
shames(Sam)7-Mar-08 0:23
shames(Sam)7-Mar-08 0:23 
GeneralProblem with online test paper [modified] Pin
Deepak Nigam6-Mar-08 23:26
Deepak Nigam6-Mar-08 23:26 
GeneralRe: Problem with online test paper Pin
eyeseetee6-Mar-08 23:44
eyeseetee6-Mar-08 23:44 
GeneralRe: Problem with online test paper Pin
Deepak Nigam6-Mar-08 23:55
Deepak Nigam6-Mar-08 23:55 
GeneralRe: Problem with online test paper Pin
eyeseetee7-Mar-08 0:18
eyeseetee7-Mar-08 0:18 
GeneralRe: Problem with online test paper Pin
Deepak Nigam7-Mar-08 0:54
Deepak Nigam7-Mar-08 0:54 
Question~/Web.config read from project root but written to ...\Common7\IDE\~\Web.config ?? Pin
Dieko6-Mar-08 22:54
Dieko6-Mar-08 22:54 
Hey all,

I'm trying to edit my Web.config in runtime, but I get some weird behaviour. Probably something simple I couldn't find on the net. But I'm new to this, so bear with me.

In my code I open the ~/Web.config file and it reads it from the rood of my project folder. When I try to save it to ~/Web.config, it writes it to C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\~\Web.config instead.
How can the same relative path point to 2 places? Read from here but write to there ?!? How do I solve this?

Here is my sample code:

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="webconfig._Default" %><br />
<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<br />
<html xmlns="http://www.w3.org/1999/xhtml" ><br />
<head runat="server"><br />
    <title>Untitled Page</title><br />
</head><br />
<br />
<body><br />
    <form id="form1" runat="server"><br />
    <div><br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br />
        <hr /><br />
        <br /><br />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /><br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="save Web.Config" /><br /><br />
        <asp:TextBox ID="TextBox3" runat="server" Width="754px"></asp:TextBox></div><br />
    </form><br />
</body><br />
</html><br />


Default.aspx.cs
using System;<br />
using System.Data;<br />
using System.Configuration;<br />
using System.Collections;<br />
using System.Web;<br />
using System.Web.Security;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.WebControls.WebParts;<br />
using System.Web.UI.HtmlControls;<br />
<br />
namespace webconfig<br />
{<br />
    public partial class _Default : System.Web.UI.Page<br />
    {<br />
        System.Configuration.Configuration config;<br />
<br />
        protected void Page_Load(object sender, EventArgs e)<br />
        {<br />
            config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/Web.config");<br />
            TextBox1.Text = System.Web.Configuration.WebConfigurationManager.AppSettings["myKey"];<br />
        }<br />
<br />
        protected void Button1_Click(object sender, EventArgs e)<br />
        {<br />
            System.Web.Configuration.WebConfigurationManager.AppSettings["myKey"] = TextBox2.Text;<br />
            config.SaveAs("~/Web.config");<br />
            TextBox3.Text = config.FilePath;<br />
        }<br />
    }<br />
}<br />


Web.config
<?xml version="1.0"?><br />
<br />
<configuration><br />
<br />
	<appSettings><br />
		<add key="myKey" value="ABCD"/><br />
	</appSettings><br />
    <connectionStrings/><br />
  <br />
    <system.web><br />
        <compilation debug="true" /><br />
        <authentication mode="Windows" /><br />
    </system.web><br />
	<br />
</configuration><br />

GeneralRe: ~/Web.config read from project root but written to ...\Common7\IDE\~\Web.config ?? Pin
eyeseetee6-Mar-08 23:07
eyeseetee6-Mar-08 23:07 
GeneralRe: ~/Web.config read from project root but written to ...\Common7\IDE\~\Web.config ?? Pin
Dieko7-Mar-08 5:17
Dieko7-Mar-08 5:17 
Generalsms gateway Pin
meghamaharshi6-Mar-08 22:20
meghamaharshi6-Mar-08 22:20 
GeneralRe: sms gateway Pin
Christian Graus6-Mar-08 22:26
protectorChristian Graus6-Mar-08 22:26 
GeneralRe: sms gateway Pin
yogesh_kumar_agarwal6-Mar-08 22:37
yogesh_kumar_agarwal6-Mar-08 22:37 
GeneralSet a datatable value bold Pin
SreejithAchutan6-Mar-08 21:01
SreejithAchutan6-Mar-08 21:01 
GeneralRe: Set a datatable value bold Pin
Laddie6-Mar-08 21:11
Laddie6-Mar-08 21:11 
GeneralRe: Set a datatable value bold Pin
pmarfleet6-Mar-08 21:12
pmarfleet6-Mar-08 21:12 
GeneralRe: Set a datatable value bold Pin
Christian Graus6-Mar-08 21:22
protectorChristian Graus6-Mar-08 21:22 
Generalis it possible to apply a custom validation to a grid view Pin
jagan1236-Mar-08 20:34
jagan1236-Mar-08 20:34 
GeneralRe: is it possible to apply a custom validation to a grid view Pin
Christian Graus6-Mar-08 20:45
protectorChristian Graus6-Mar-08 20:45 
GeneralRe: is it possible to apply a custom validation to a grid view Pin
Laddie6-Mar-08 20:46
Laddie6-Mar-08 20:46 
GeneralRe: is it possible to apply a custom validation to a grid view Pin
jagan1236-Mar-08 20:50
jagan1236-Mar-08 20:50 
GeneralRe: is it possible to apply a custom validation to a grid view Pin
Christian Graus6-Mar-08 21:22
protectorChristian Graus6-Mar-08 21:22 
GeneralConvert the GridView data to CSV file Pin
salon6-Mar-08 20:28
salon6-Mar-08 20:28 
GeneralRe: Convert the GridView data to CSV file Pin
Laddie6-Mar-08 20:45
Laddie6-Mar-08 20:45 
GeneralRe: Convert the GridView data to CSV file Pin
salon7-Mar-08 0:05
salon7-Mar-08 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.