IHttpHandler and VS design-time

Z

Zarko Gajic

Hi,

I've developed a custom handler for my custom control that stores and serves
all the JS and GIF files to the control user at run time.

Question: how do I force the images to appear on the control (as those are
child controls to this composite control) at design time in VS's designer?

~Zarko
 
L

lisa

Zarko said:
Hi,

I've developed a custom handler for my custom control that stores and serves
all the JS and GIF files to the control user at run time.

Question: how do I force the images to appear on the control (as those are
child controls to this composite control) at design time in VS's
designer?

Aren't they showing already? Do you have a custom designer? If so,
you should be able to point to the handler and have it work. I think.

I did something completely different. I have a date control that has a
little date gif on the button. So I embedded that in the assembly, and
added this code to the Render override in the custom control:

======================
Dim AppFolder As String = "DatePicker.gif"

If Not System.IO.File.Exists(AppFolder) Then
Dim myAssembly As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly
Dim myStream As Stream = _

myAssembly.GetManifestResourceStream("<namespace>.DatePicker.gif")
Dim DatePicker_gif() As System.Byte = New
System.Byte(myStream.Length) {}
myStream.Read(DatePicker_gif, 0, CInt(myStream.Length))
Try
Dim myTempFile As New FileStream(AppFolder, FileMode.Create)
myTempFile.Write(DatePicker_gif, 0, CInt(myStream.Length))
myTempFile.Close()
Catch ex As Exception
Throw New Exception("Unable to create DatePicker.gif.")
Exit Sub
End Try
End If

_dateimage.ImageUrl = "DatePicker.gif"
======================

What this does is pull the file out of the assembly and write it to the
root of whatever application the control is being used in. If someone
deletes the file, it'll just get written there again the next time the
control renders.

Now... I don't know what the issue is regarding privileges. Where I
work, we have to put in a strong named key and grant it full trust in
order to even use custom controls. And I suspect that the full trust
might be the only reason this works. But it does work.

The gif appears in design time *and* run time. If I had put it in
images/, I'm not sure it would have worked, because the file path would
have to be images\ and the URL needs to be images/. I have no idea if
VS.NET is smart enough to figure that out. So... root.

The only issue I might have would be if someone were to put a
DatePicker.gif in that folder that was different. My code will *not*
overwrite a file that's already there (both for safety and efficiency).
So if you use a technique like this for a script file, make sure the
name is sufficiently unique that there won't be one there with the same
name.

HTH,
Lisa
 
Z

Zarko Gajic

Lisa, thanks for the idea.


~Zarko

designer?

Aren't they showing already? Do you have a custom designer? If so,
you should be able to point to the handler and have it work. I think.

I did something completely different. I have a date control that has a
little date gif on the button. So I embedded that in the assembly, and
added this code to the Render override in the custom control:

======================
Dim AppFolder As String = "DatePicker.gif"

If Not System.IO.File.Exists(AppFolder) Then
Dim myAssembly As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly
Dim myStream As Stream = _

myAssembly.GetManifestResourceStream("<namespace>.DatePicker.gif")
Dim DatePicker_gif() As System.Byte = New
System.Byte(myStream.Length) {}
myStream.Read(DatePicker_gif, 0, CInt(myStream.Length))
Try
Dim myTempFile As New FileStream(AppFolder, FileMode.Create)
myTempFile.Write(DatePicker_gif, 0, CInt(myStream.Length))
myTempFile.Close()
Catch ex As Exception
Throw New Exception("Unable to create DatePicker.gif.")
Exit Sub
End Try
End If

_dateimage.ImageUrl = "DatePicker.gif"
======================

What this does is pull the file out of the assembly and write it to the
root of whatever application the control is being used in. If someone
deletes the file, it'll just get written there again the next time the
control renders.

Now... I don't know what the issue is regarding privileges. Where I
work, we have to put in a strong named key and grant it full trust in
order to even use custom controls. And I suspect that the full trust
might be the only reason this works. But it does work.

The gif appears in design time *and* run time. If I had put it in
images/, I'm not sure it would have worked, because the file path would
have to be images\ and the URL needs to be images/. I have no idea if
VS.NET is smart enough to figure that out. So... root.

The only issue I might have would be if someone were to put a
DatePicker.gif in that folder that was different. My code will *not*
overwrite a file that's already there (both for safety and efficiency).
So if you use a technique like this for a script file, make sure the
name is sufficiently unique that there won't be one there with the same
name.

HTH,
Lisa
 

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,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top