How do I get the url of control's page at design time?

Discussion in 'ASP .Net Building Controls' started by WALDO, Oct 20, 2004.

  1. WALDO

    WALDO Guest

    I have a control designer that I am building for a webcontrol I've
    built. The control includes some images as part of it's design. I'd
    like for the designer to resolve those images so they can be shown in
    the designer. The control at runtime would ordinarily call ResolveUrl
    and get the correct path. I'd like to know the url of the page my
    control is sitting on so that I may write a ResolveUrl for

    Any ideas?
    WALDO, Oct 20, 2004
    1. Advertisements

  2. yes and no :)

    at design time you don't have url, you have disk path, there is no web
    server at design time (AFAIK). I run into the same problem, I wonted to
    write in web.config in design time.

    I had LOT OF troubles, mainly because of poor (or non-existing) design time
    support. For VS.NET you have to call some non documented COM objects, you
    can download component that tries to solve this mess, but I am not very
    happy about it :

    This assembly have function that returns path of your project in design
    time, it's freeware and have source included (beware, Delphi.NET)

    Antonio Bakula, Oct 21, 2004
    1. Advertisements

  3. WALDO

    WALDO Guest

    I'm not afraid of using COM objects. I use Lutz Roeder's Reflector to
    look at Visual Studio code and I see the .Net-based designers are
    looking at COM objects for the most part. If they can do it, I can do

    I feel that there's got to be something I can look at to give me a
    reference to the web project's path. The web project knows it's on
    I want to know that, too.
    WALDO, Oct 21, 2004
  4. WALDO

    WALDO Guest

    See, I got it.

    Dim srvce As IWebFormsDocumentService =
    Dim objWebFormsDocumentService As Object = CObj(srvce)
    Dim t As Type = objWebFormsDocumentService.GetType
    Dim mi As System.Reflection.MethodInfo
    mi = t.GetMethod("GetDocumentUrl", Reflection.BindingFlags.Instance Or
    Dim strUrl As String = mi.Invoke(objWebFormsDocumentService, Nothing)
    WALDO, Oct 21, 2004
  5. WALDO

    WALDO Guest

    Or better yet (duh):

    Dim srvce As IWebFormsDocumentService =
    Dim objWebFormsDocumentService As Object = CObj(srvce)
    Dim strUrl As String = srvce.DocumentUrl
    WALDO, Oct 21, 2004
  6. Great :)

    But I am not sure that this will help you to display images in design time.
    Please post back if you succeed, I am VERY interested.

    thanks !
    Antonio Bakula, Oct 21, 2004
  7. WALDO

    WALDO Guest

    WALDO, Oct 21, 2004
  8. WALDO

    WALDO Guest

    I am awesome!

    I found the same code written in C# that you used to get the DTE object.
    I had already translated it into VB, so forgive me. I just went the step
    further and was able to get the URL of the project.

    Public Overrides Function GetDesignTimeHtml() As String
    Dim html As String = ""

    'VS 2002
    Dim strMoniker As String = "!VisualStudio.DTE.7:" &
    Dim dte As EnvDTE.DTE = GetMSDEVFromGIT(strMoniker)

    If dte Is Nothing Then 'Try VS 2003
    strMoniker = "!VisualStudio.DTE.7.1:" &
    dte = GetMSDEVFromGIT(strMoniker)
    End If

    If dte Is Nothing Then
    html = "DTE Is Nothing"
    Dim projs() As Object = dte.ActiveSolutionProjects
    Dim proj As EnvDTE.Project
    For Each proj In projs
    Dim props As EnvDTE.Properties = proj.Properties
    Dim prop As EnvDTE.Property

    'Look for URL property
    For Each prop In props
    html &= "<br>" & prop.Name & " = " & prop.Value.ToString
    End If

    Catch exc As Exception
    html = Me.GetErrorDesignTimeHtml(exc)
    End Try

    Return html
    End Function
    WALDO, Oct 21, 2004
  9. yes, that's the only way. Unfortunatly this doesn't work for any other .NET
    IDE, like WebMatrix for example. I still haven't found solution for
    WebMatrix designtime project path.
    Antonio Bakula, Oct 22, 2004
  10. WALDO

    WALDO Guest

    Hadn't thought of that. I've never used WebMatrix before. If it's built
    off of EnvDte, then it should work, you just need a different moniker.
    WALDO, Oct 22, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.