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
    design-time.

    Any ideas?
    WALDO, Oct 20, 2004
    #1
    1. Advertising

  2. On 20 Oct 2004 07:13:02 -0700, WALDO wrote:

    > 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
    > design-time.
    >
    > Any ideas?


    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 :

    http://www.antoniob.com/projects/PDesignTimeTools.aspx

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


    HTH


    --
    http://www.antoniob.com/
    remove antispam XremoveX from e-mail !
    Antonio Bakula, Oct 21, 2004
    #2
    1. Advertising

  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
    it.

    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
    http://localhost/MyProject
    I want to know that, too.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    WALDO, Oct 21, 2004
    #3
  4. WALDO

    WALDO Guest

    See, I got it.

    [VB.Net]
    Dim srvce As IWebFormsDocumentService =
    Me.GetService(GetType(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
    Reflection.BindingFlags.NonPublic)
    Dim strUrl As String = mi.Invoke(objWebFormsDocumentService, Nothing)


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    WALDO, Oct 21, 2004
    #4
  5. WALDO

    WALDO Guest

    Or better yet (duh):

    [VB.Net]
    Dim srvce As IWebFormsDocumentService =
    Me.GetService(GetType(IWebFormsDocumentService))
    Dim objWebFormsDocumentService As Object = CObj(srvce)
    Dim strUrl As String = srvce.DocumentUrl

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    WALDO, Oct 21, 2004
    #5
  6. On Thu, 21 Oct 2004 07:00:50 -0700, WALDO wrote:

    > Or better yet (duh):
    >
    > [VB.Net]
    > Dim srvce As IWebFormsDocumentService =
    > Me.GetService(GetType(IWebFormsDocumentService))
    > Dim objWebFormsDocumentService As Object = CObj(srvce)
    > Dim strUrl As String = srvce.DocumentUrl
    >


    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 !

    --
    http://www.antoniob.com/
    remove antispam XremoveX from e-mail !
    Antonio Bakula, Oct 21, 2004
    #6
  7. WALDO

    WALDO Guest

    WALDO, Oct 21, 2004
    #7
  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 = ""

    Try
    'VS 2002
    Dim strMoniker As String = "!VisualStudio.DTE.7:" &
    System.Diagnostics.Process.GetCurrentProcess().Id.ToString()
    Dim dte As EnvDTE.DTE = GetMSDEVFromGIT(strMoniker)

    If dte Is Nothing Then 'Try VS 2003
    strMoniker = "!VisualStudio.DTE.7.1:" &
    System.Diagnostics.Process.GetCurrentProcess().Id.ToString()
    dte = GetMSDEVFromGIT(strMoniker)
    End If

    If dte Is Nothing Then
    html = "DTE Is Nothing"
    Else
    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
    Next
    Next
    End If

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


    Return html
    End Function

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    WALDO, Oct 21, 2004
    #8
  9. On Thu, 21 Oct 2004 08:30:34 -0700, WALDO wrote:

    > 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.
    >


    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.


    --
    http://www.antoniob.com/
    remove antispam XremoveX from e-mail !
    Antonio Bakula, Oct 22, 2004
    #9
  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.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    WALDO, Oct 22, 2004
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    709
  2. Paul Cook
    Replies:
    0
    Views:
    443
    Paul Cook
    Nov 6, 2003
  3. flamesrock
    Replies:
    8
    Views:
    440
    Hendrik van Rooyen
    Nov 24, 2006
  4. Replies:
    1
    Views:
    360
    Teemu Keiski
    Jul 2, 2003
  5. WALDO
    Replies:
    1
    Views:
    122
    Antonio Bakula
    Oct 21, 2004
Loading...

Share This Page