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 ;) ..
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.
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.
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.
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:
DTEinDesigner.zip 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,
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.
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.
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 insert the correct virtual path to display design time images properly. My library has about
20 controls so I created a new class "BaseControlDesigner"
that extends "ControlDesigner". And extend BaseControlDesigner from my controls. Heres the BaseControlDesigner class:
using System;
using System.ComponentModel.Design;
using System.Web.UI.Design;
namespace SurveyControls.Classes
{
public class BaseControlDesigner : ControlDesigner
{
public BaseControlDesigner()
{
}
public string ParentConfigPath()
{
Type currentType = this.GetType();
System.ComponentModel.Design.ITypeResolutionService service = (ITypeResolutionService) GetService(typeof(System.ComponentModel.Design.ITypeResolutionService ));
string AssemblyPath = System.IO.Path.GetDirectoryName(service.GetPathOfAssembly(currentType.Assembly.GetName()));
return AssemblyPath.Substring(0, AssemblyPath.LastIndexOf('\\'))+ "\\web.config";
}
}
}
Another class is needed to read the web.config:
using System;
using System.Xml;
using System.Xml.XPath;
Thomas Z.
Member
210 Points
42 Posts
Re: Complex Question on Designers
Nov 01, 2002 07:22 PM|LINK
Thomas
rbuckton
Member
547 Points
124 Posts
Re: Complex Question on Designers
Nov 01, 2002 07:34 PM|LINK
Senior Consultant
Microsoft
rbuckton
Member
547 Points
124 Posts
Re: Complex Question on Designers
Nov 01, 2002 07:52 PM|LINK
Senior Consultant
Microsoft
Thomas Z.
Member
210 Points
42 Posts
Re: Complex Question on Designers
Nov 01, 2002 07:59 PM|LINK
Thomas
rbuckton
Member
547 Points
124 Posts
Re: Complex Question on Designers
Nov 02, 2002 03:15 AM|LINK
Senior Consultant
Microsoft
jonshin
Member
95 Points
24 Posts
Re: Complex Question on Designers
May 22, 2004 04:02 PM|LINK
AndrewSeven
Contributor
2184 Points
437 Posts
Re: Complex Question on Designers
May 25, 2004 01:44 PM|LINK
trickster
Member
15 Points
3 Posts
Re: Complex Question on Designers
Sep 30, 2004 10:17 AM|LINK
quickchuck
Member
5 Points
1 Post
Re: Complex Question on Designers
Nov 22, 2006 04:10 PM|LINK
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 insert the correct virtual path to display design time images properly. My library has about 20 controls so I created a new class "BaseControlDesigner" that extends "ControlDesigner". And extend BaseControlDesigner from my controls. Heres the BaseControlDesigner class:
using System;
using System.ComponentModel.Design;
using System.Web.UI.Design;
namespace SurveyControls.Classes
{
public class BaseControlDesigner : ControlDesigner
{
public BaseControlDesigner()
{
}
public string ParentConfigPath()
{
Type currentType = this.GetType();
System.ComponentModel.Design.ITypeResolutionService service = (ITypeResolutionService) GetService(typeof(System.ComponentModel.Design.ITypeResolutionService ));
string AssemblyPath = System.IO.Path.GetDirectoryName(service.GetPathOfAssembly(currentType.Assembly.GetName()));
return AssemblyPath.Substring(0, AssemblyPath.LastIndexOf('\\'))+ "\\web.config";
}
}
}
Another class is needed to read the web.config:
using System;
using System.Xml;
using System.Xml.XPath;
namespace SurveyControls.Classes
{
public class Utils
{
public Utils()
{
}
public static string GetVirtualPath(string ParentWebConfigPath)
{
String appSetting = "na";
XmlDocument documentXml = new XmlDocument();
documentXml.Load(ParentWebConfigPath);
XPathNavigator navigator = documentXml.CreateNavigator();
XPathNodeIterator iterator = null;
iterator = navigator.Select("/configuration/appSettings/add");
while (iterator.MoveNext())
{
navigator = iterator.Current;
if(navigator.GetAttribute("key", "") == "VirtualPath")
{
appSetting = navigator.GetAttribute("value", "");
}
}
return appSetting;
}
}
}
Now you can get webconfig info to your control at design time with a call to the util method:
Utils.GetVirtualPath(ParentConfigPath())
Regards,
Charles