IHttpHandler and VS design-time

Discussion in 'ASP .Net Building Controls' started by Zarko Gajic, Apr 18, 2005.

  1. Zarko Gajic

    Zarko Gajic Guest

    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
    Zarko Gajic, Apr 18, 2005
    #1
    1. Advertising

  2. Zarko Gajic

    Guest

    Zarko Gajic wrote:
    > 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
    , Apr 20, 2005
    #2
    1. Advertising

  3. Zarko Gajic

    Zarko Gajic Guest

    Lisa, thanks for the idea.


    ~Zarko

    <> wrote in message
    news:...
    >
    > Zarko Gajic wrote:
    > > 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
    >
    Zarko Gajic, Apr 21, 2005
    #3
  4. On Mon, 18 Apr 2005 14:25:14 +0200, Zarko Gajic wrote:

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


    http://cc.borland.com/ccweb.exe/listing?id=21308

    this control works in design time too.


    --
    http://www.antoniob.com/
    remove antispam XremoveX from e-mail !
    Antonio Bakula, Apr 26, 2005
    #4
    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. Sky Sigal
    Replies:
    13
    Views:
    851
    Sky Sigal
    Aug 3, 2004
  2. Replies:
    5
    Views:
    2,421
    Matt Berther
    Mar 4, 2005
  3. Chance Hopkins

    IHttpHandler, ProcessRequest and Session

    Chance Hopkins, Apr 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    4,965
    Chance Hopkins
    Apr 14, 2005
  4. Mutley
    Replies:
    1
    Views:
    2,052
    Bruce Barker
    Jan 24, 2006
  5. flamesrock
    Replies:
    8
    Views:
    449
    Hendrik van Rooyen
    Nov 24, 2006
Loading...

Share This Page