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
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
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...) .
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
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.
--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
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.
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 "ControlDesigner" 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.
The components i'm designing reside in their own assembly that will be likely be under the following folder location after they are installed:
:\Program Files\\\Common 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.
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.
rbuckton
Member
547 Points
124 Posts
Complex Question on Designers
Oct 28, 2002 12:00 PM|LINK
Senior Consultant
Microsoft
NikhilKo
Contributor
3279 Points
93 Posts
Microsoft
Re: Complex Question on Designers
Oct 28, 2002 04:57 PM|LINK
Weblog: http://www.nikhilk.net
Twitter: @nikhilk
rbuckton
Member
547 Points
124 Posts
Re: Complex Question on Designers
Oct 28, 2002 10:52 PM|LINK
Senior Consultant
Microsoft
NikhilKo
Contributor
3279 Points
93 Posts
Microsoft
Re: Complex Question on Designers
Oct 29, 2002 03:01 AM|LINK
Weblog: http://www.nikhilk.net
Twitter: @nikhilk
rbuckton
Member
547 Points
124 Posts
Re: Complex Question on Designers
Oct 29, 2002 12:22 PM|LINK
Senior Consultant
Microsoft
PLBlum
All-Star
30399 Points
5347 Posts
MVP
Re: Complex Question on Designers
Oct 31, 2002 04:44 PM|LINK
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
rbuckton
Member
547 Points
124 Posts
Re: Complex Question on Designers
Nov 01, 2002 12:55 PM|LINK
Senior Consultant
Microsoft
Thomas Z.
Member
210 Points
42 Posts
Re: Complex Question on Designers
Nov 01, 2002 04:13 PM|LINK
Thomas
rbuckton
Member
547 Points
124 Posts
Re: Complex Question on Designers
Nov 01, 2002 06:56 PM|LINK
Senior Consultant
Microsoft
rbuckton
Member
547 Points
124 Posts
Re: Complex Question on Designers
Nov 01, 2002 07:17 PM|LINK
Senior Consultant
Microsoft