Complex Question on Designershttp://forums.asp.net/t/75635.aspx/1?Complex+Question+on+DesignersWed, 22 Nov 2006 16:10:01 -05007563575635http://forums.asp.net/p/75635/75635.aspx/1?Complex+Question+on+DesignersComplex Question on Designers I figure in developing Web Matrix the developer group dealt a lot with designers and how they work. I've asked around in the msnews newsgroups for some suggestions on how to accomplish the following and have not yet recieved any useful examples. Hopefully someone here can help. I am authoring a designer for a Component that will be used in a Web Form. It needs to retrieve values from the Web.Config file at Design Time to be used to acquire connection information to a SQL Server database for component configuration (retrieving human readable names for selection of items whose IDs will be the only thing stored in the component) If anyone can help at all in this, or can refer me to a better place for this discussion I wold much appreciate the help. Thanks, Ron 2002-10-28T12:00:58-05:0075904http://forums.asp.net/p/75635/75904.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers Currently control designers do not have access to the configuration at design-time. This is independent of the IDE - be it Web Matrix or VS.NET. 2002-10-28T16:57:11-05:0076113http://forums.asp.net/p/75635/76113.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers Any better suggestions with how to store and retrieve this information. The basic idea is that i'm developing a custom control that at runtime interacts with an httphandler that deals with authentication. I use a SQL Server database to store authentication information and the connection information for that database is stored in the web config (in its own specialized configuration section). I need to keep the configuration information in a single place so that the UI Designers i'm writing don't need to manually have a connection string set on each instance of the control. Any better ideas would be appreciated, Thanks. Ron 2002-10-28T22:52:18-05:0076221http://forums.asp.net/p/75635/76221.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers I agree this would be useful functionality to have... Since this is a custom control, you might be able to design-in the smarts for accessing config at runtime, based on the properties that have been set. For example, if you had a ConnectionString property, you could also have a ConnectionStringKey property, which was a key into . Maybe this would work? I understand that this doesn't have much of a design-time story associated with it though, but its pretty much a workaround for what the current architecture addresses (which should continue to improve...) . 2002-10-29T03:01:30-05:0076422http://forums.asp.net/p/75635/76422.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers I'm not sure I understand the solution you recommend, although it still doesnt address the problem. I'm not using to store my configuration values, as its more than just connection string. I'm using a custom configuration section and section handler in my code to deal with the complex config that this control is sitting on. Is there a way (through the VS IDE Specifically) to locate the disk location (inetpub or the VS.Net cache) of the web.config file? If I could find the location of the file on disk during development/design time I could simply load an XmlDocument object to read the configuration data. I am just curious if there is a way to do these things from within a designer. Basically I want my UITypeEditor to do the following when opened: 1) Learn the location of the project/application this component runs under and the location of the project/application's web.config file 2) Open the web.config file read-only in an XmlDocument object (or through a System.Configuration class) and read the custom config settings with my section handler (I suppose just by calling the method on the handler that reads the base configuration node 3) Use that configuration information to acquire, among other things, a connection string to a sql server database instance that can be used for UITypeEditor I'm writing a custom modal Windows Forms Dialog to be used for the UI Type Editor to acquire the necessary values. Once i can get the location of the web.config for the project at design time I will have what I need. Also, I know that this solution is pretty much a VS.Net only solution (the designer wouldn't work in Web Matrix) unless there is a core API shared between the two that could provide me with that location. Thanks, Ron 2002-10-29T12:22:44-05:0078376http://forums.asp.net/p/75635/78376.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers Here's one idea. You can add properties to your control that only show up in design mode using the attribute DesignOnlyAttribute. Perhaps you can provide a property that holds the file path to the web.config file that you are looking for here. [DesignOnlyAttribute(true)] public string WebConfigFilePath { get; set; } I have yet to use this property. Its unclear whether the property is persisted in some way from the docs. If it is, the user can set this once and forget it. 2002-10-31T16:44:01-05:0078907http://forums.asp.net/p/75635/78907.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers A property WebConfigFilePath would not help matters as the developer would still have know the path location themselves. I'm trying to make this component as easy to use as possible, hence the designer support. Adding complexity that depends on user interaction in this sense defeats the purpose of simplifying usability. 2002-11-01T12:55:26-05:0079081http://forums.asp.net/p/75635/79081.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers Hi, what you could do is get the assembly location of your control and from there move up in the directory and load the web.config file. Here is a way to get the path at design time. 1) Add a public string property to your webcontrol eg: controlPath 2) From the class that inherits from &quot;ControlDesigner&quot; you could add the following code to the GetDesignTimeHtml method : public override string GetDesignTimeHtml() { YourControl yourControl = (YourControl) Component; Type currentType = this.GetType(); System.ComponentModel.Design.ITypeResolutionService service = (ITypeResolutionService) this.GetService( typeof(System.ComponentModel.Design.ITypeResolutionService ) ); // Get the path from where the current control was loaded string path = System.IO.Path.GetDirectoryName(service.GetPathOfAssembly(currentType.Assembly.GetName())); yourControl.controlPath = path; // call the method on your control that will output the html return base.GetDesignTimeHtml(); } I've used a property controlPath on the control as example but instead you could do the loading of the web.config file, get your dsn, assign it to the correct control property and render the html properly. 2002-11-01T16:13:56-05:0079184http://forums.asp.net/p/75635/79184.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers The components i'm designing reside in their own assembly that will be likely be under the following folder location after they are installed: <b>:\Program Files\\\Common</b> When you add the assembly to the toolbox, the assembly path will be the above path and not the location of the web application, as a result the web.config will be inaccessible as it does not lie anywhere in the path. I'm still toying with a few ideas myself, and looking into the VS.Net IDE application objects to see if there's a way to use them. Thanks for the help. 2002-11-01T18:56:26-05:0079204http://forums.asp.net/p/75635/79204.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers I would like to applogize to thomas as I tweaked the code a bit and was able to get something working based on my requirements. The only thing i see as being a possible issue is the output path of the dll of the current web project. In my c# project it comes back as \bin\Debug\ while i know in vb.net projects this will be \bin\. Although I know i can test and move back on folders until i get to the folder before the \bin, i am not sure if i have any guarantee that this will work. This deserves further testing, and I thank you wholeheartedly for this solution. 2002-11-01T19:17:31-05:0079209http://forums.asp.net/p/75635/79209.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers well I see, but how will your web application pages access this assembly if its not in the gac or in any folder of your webapplication? Or maybe I am just missing something ;) .. 2002-11-01T19:22:57-05:0079217http://forums.asp.net/p/75635/79217.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers Turns out there's a problem. The path that is returned is the VSWebCache path, and since i'm using a file share for publishing the actual web.config file is in the \inetpub\wwwroot path of the file share. So no go for this solution. 2002-11-01T19:34:00-05:0079231http://forums.asp.net/p/75635/79231.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers Ok here's a question: I know as far as Add-ins are concerend, VS.Net passes it's EnvDTE._DTE object around to access the Design time environment. Is there any way to programatically acquire the DTE from within a Designer? If i can get the DTE from within the designer i'll have access to the information i need. 2002-11-01T19:52:35-05:0079235http://forums.asp.net/p/75635/79235.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers Didnt try with network shares I just did a quick try on a local machine and received the correct path of the assembly. Let us know if you find something, I am also very interested in finding a solution to this problem. 2002-11-01T19:59:38-05:0079328http://forums.asp.net/p/75635/79328.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers I did some searching on google groups and found a solution, i cleaned it up a bit and added an example of usage based on my own needs. you can download the examle from my site: <a href="http://www.chronicles.org/examples/DTEinDesigner.zip">DTEinDesigner.zip</a> Tested and it works perfectly. Grabs the current instance of the VisualStudio DTE from the RunningObjectTable by snagging the id of the executing process. I'm curious if any Web Matrix developers would have a similar way of accessing the matrix api? I would like to support as many IDE's as i can through the designer so things like Web Matrix and MX support would be nice too. Thanks, 2002-11-02T03:15:22-05:00582522http://forums.asp.net/p/75635/582522.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers Ron - Looks like the link is broken, can you post an updated one? I have the exact same issue right now. Thanks, Jon 2004-05-22T16:02:42-04:00584588http://forums.asp.net/p/75635/584588.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers The DTE is a decent way to get to the web.config. It involves lots of hopping through hoops, but you can get there. From theDTE, you can find out about the properties project you are in and also of the solution, thus you have access to the path etc. Knowing the path, you can open the web.config as an xml file. All of it can be done from inside a control designer. 2004-05-25T13:44:16-04:00706434http://forums.asp.net/p/75635/706434.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers This is a problem. You may want to have a look at http://www.peterblum.com/ADME/Home.aspx which is a free design mode extender kit for developers that allows a developer to access configurable information at design time. We've not used it yet so I can't comment on it's ease of use, efficiency, etc, etc but it looks like a reasonable solution to this problem. Let me know if anyone has used it, or if you try it out yourself. 2004-09-30T10:17:15-04:001473798http://forums.asp.net/p/75635/1473798.aspx/1?Re+Complex+Question+on+DesignersRe: Complex Question on Designers <p>I had similar problem as the virtual path on my prod and dev servers are different. I put an entry in my web.config which the library can open at design time and&nbsp;insert the correct virtual path to display design time images properly.&nbsp; My library has about 20 controls so I created a new class &quot;<font size="2">BaseControlDesigner&quot; </font> that extends &quot;<font size="2">ControlDesigner&quot;. And extend BaseControlDesigner from my controls. Heres the BaseControlDesigner class:</font></p> <p><font size="2">using System;<br> using System.ComponentModel.Design;<br> using System.Web.UI.Design;</font></p> <p><font size="2">namespace SurveyControls.Classes<br> {<br> &nbsp;public class BaseControlDesigner : ControlDesigner<br> &nbsp;{<br> &nbsp;&nbsp;public BaseControlDesigner()<br> &nbsp;&nbsp;{<br> &nbsp;&nbsp;}</font></p> <p><font size="2">&nbsp;&nbsp;public string ParentConfigPath()<br> &nbsp;&nbsp;{<br> &nbsp;&nbsp;&nbsp;Type currentType = this.GetType();<br> &nbsp;&nbsp;&nbsp;System.ComponentModel.Design.ITypeResolutionService service = (ITypeResolutionService) GetService(typeof(System.ComponentModel.Design.ITypeResolutionService )); <br> &nbsp;&nbsp;&nbsp;string AssemblyPath = System.IO.Path.GetDirectoryName(service.GetPathOfAssembly(currentType.Assembly.GetName()));<br> &nbsp;&nbsp;&nbsp;return AssemblyPath.Substring(0, AssemblyPath.LastIndexOf('\\'))&#43; &quot;<a href="file://web.config/">\\web.config</a>&quot;;<br> &nbsp;&nbsp;}<br> &nbsp;}<br> }</font></p> <p><font size="2">&nbsp;Another class is needed to read the web.config:</font></p> <p>&nbsp;using System;<br> using System.Xml;<br> using System.Xml.XPath;</p> <p>namespace SurveyControls.Classes<br> {</p> <p>&nbsp;public class Utils<br> &nbsp;{<br> &nbsp;&nbsp;public Utils()<br> &nbsp;&nbsp;{<br> &nbsp;&nbsp;}</p> <p>&nbsp;&nbsp;public static string GetVirtualPath(string ParentWebConfigPath)<br> &nbsp;&nbsp;{<br> &nbsp;&nbsp;&nbsp;String appSetting = &quot;na&quot;;<br> &nbsp;&nbsp;&nbsp;XmlDocument documentXml = new XmlDocument();<br> &nbsp;&nbsp;&nbsp;documentXml.Load(ParentWebConfigPath);<br> &nbsp;&nbsp;&nbsp;XPathNavigator navigator = documentXml.CreateNavigator();<br> &nbsp;&nbsp;&nbsp;XPathNodeIterator iterator = null;<br> &nbsp;&nbsp;&nbsp;iterator = navigator.Select(&quot;/configuration/appSettings/add&quot;);</p> <p>&nbsp;&nbsp;&nbsp;while (iterator.MoveNext())<br> &nbsp;&nbsp;&nbsp;{<br> &nbsp;&nbsp;&nbsp;&nbsp;navigator = iterator.Current;<br> &nbsp;&nbsp;&nbsp;&nbsp;if(navigator.GetAttribute(&quot;key&quot;, &quot;&quot;) == &quot;VirtualPath&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;appSetting = navigator.GetAttribute(&quot;value&quot;, &quot;&quot;);<br> &nbsp;&nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;&nbsp;}</p> <p>&nbsp;&nbsp;&nbsp;return appSetting;<br> &nbsp;&nbsp;}<br> &nbsp;}<br> }</p> <p>Now you can get webconfig info to your control at design time with a call to the util method:</p> <p>Utils.GetVirtualPath(ParentConfigPath())</p> <p>&nbsp;</p> <p><font size="2">Regards,</font></p> <p><font size="2">Charles</p> </font> 2006-11-22T16:10:01-05:00