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

W

WALDO

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?
 
A

Antonio Bakula

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
 
W

WALDO

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

WALDO

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)
 
W

WALDO

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
 
A

Antonio Bakula

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 !
 
W

WALDO

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
 
A

Antonio Bakula

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

WALDO

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top