# StreamLoading event - how do i know which stream is loading

**URL:** <https://community.thinkgeo.com/t/streamloading-event-how-do-i-know-which-stream-is-loading/1491>\
**Category:** WinForms\
**Created:** [November 10, 2010, 5:47pm UTC](https://community.thinkgeo.com/t/streamloading-event-how-do-i-know-which-stream-is-loading/1491 "2010-11-10T17:47:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul2](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/paul2/32/24982_2.png) [@Paul2](https://community.thinkgeo.com/u/Paul2)\
**Post date:** [November 10, 2010, 5:47pm UTC](https://community.thinkgeo.com/t/streamloading-event-how-do-i-know-which-stream-is-loading/1491/1 "2010-11-10T17:47:23Z")

</div>

Today&nbsp;I've&nbsp;been&nbsp;working&nbsp;on&nbsp;adding&nbsp;images&nbsp;to&nbsp;maps&nbsp;using&nbsp;the&nbsp;GdiPlusRasterLayer.&nbsp;As&nbsp;the&nbsp;images&nbsp;do&nbsp;not&nbsp;have&nbsp;world&nbsp;files&nbsp;associated&nbsp;with&nbsp;them,&nbsp;I&nbsp;am&nbsp;creating&nbsp;them&nbsp;on&nbsp;the&nbsp;fly&nbsp;by&nbsp;handling&nbsp;the&nbsp;StreamLoading&nbsp;event&nbsp;of&nbsp;the&nbsp;ImageSource.&nbsp;However,&nbsp;the&nbsp;StreamLoadingEventArgs&nbsp;does&nbsp;not&nbsp;indicate&nbsp;which&nbsp;stream&nbsp;is&nbsp;attempting&nbsp;to&nbsp;be&nbsp;loaded,&nbsp;so&nbsp;I&nbsp;am&nbsp;struggling&nbsp;trying&nbsp;to&nbsp;provide&nbsp;a&nbsp;generic&nbsp;event&nbsp;handler&nbsp;that&nbsp;allows&nbsp;me&nbsp;to&nbsp;dynamically&nbsp;load&nbsp;and&nbsp;display&nbsp;several&nbsp;images&nbsp;on&nbsp;a&nbsp;map.

&nbsp;

`Private _imageWorldFiles As New Dictionary(Of String, WorldFile)...Dim imageWorldFile = New WorldFile(worldExtent, imageWidth, imageHeight)_imageWorldFiles.Add(Path, imageWorldFile)AddHandler imageSource.StreamLoading, AddressOf MapImage_StreamLoading...Private Sub MapImage_StreamLoading(ByVal sender As Object, ByVal e As StreamLoadingEventArgs)    If e.AlternateStreamName.Contains(".JGW") Then        ' Need the key here or some indication of which stream we're dealing with        Dim imageWorldFile = _imageWorldFiles("d:\_scratch\image.jpg")        Dim sb = New StringBuilder        sb.AppendLine(imageWorldFile.HorizontalResolution)        sb.AppendLine("0")        sb.AppendLine("0")        sb.AppendLine(imageWorldFile.VerticalResolution)        sb.AppendLine(imageWorldFile.UpperLeftX)        sb.AppendLine(imageWorldFile.UpperLeftY)        Dim byteArray = Encoding.ASCII.GetBytes(sb.ToString())        Dim stream = New MemoryStream(byteArray)        e.AlternateStream = stream        e.AlternateStreamName = "test.jgw"    End If    End Sub`

Here&nbsp;I&nbsp;am&nbsp;trying&nbsp;to&nbsp;create&nbsp;a&nbsp;WorldFile&nbsp;object&nbsp;and&nbsp;store&nbsp;them&nbsp;in&nbsp;a&nbsp;dictionary.&nbsp;Then,&nbsp;in&nbsp;the&nbsp;StreamLoading&nbsp;event,&nbsp;I&nbsp;was&nbsp;going&nbsp;to&nbsp;retrieve&nbsp;the&nbsp;corresponding&nbsp;WorldFile&nbsp;from&nbsp;the&nbsp;dictionary&nbsp;and&nbsp;writing&nbsp;it&nbsp;to&nbsp;the&nbsp;stream.&nbsp;The&nbsp;problem&nbsp;is&nbsp;I&nbsp;have&nbsp;no&nbsp;way&nbsp;of&nbsp;retrieving&nbsp;the&nbsp;key&nbsp;for&nbsp;the&nbsp;current&nbsp;stream&nbsp;in&nbsp;the&nbsp;event&nbsp;handler.

Thanks&nbsp;for&nbsp;any&nbsp;help&nbsp;you&nbsp;can&nbsp;provide.&nbsp;Paul

---

<div class="post-metadata">

**Author:** ![Paul2](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/paul2/32/24982_2.png) [@Paul2](https://community.thinkgeo.com/u/Paul2)\
**Post date:** [November 10, 2010, 5:50pm UTC](https://community.thinkgeo.com/t/streamloading-event-how-do-i-know-which-stream-is-loading/1491/2 "2010-11-10T17:50:39Z")

</div>

Nevermind&nbsp;-&nbsp;I&nbsp;think&nbsp;the&nbsp;source&nbsp;object&nbsp;is&nbsp;giving&nbsp;me&nbsp;the&nbsp;reference&nbsp;to&nbsp;the&nbsp;GdiPlusRasterSource&nbsp;that&nbsp;I&nbsp;need.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Paul

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [November 10, 2010, 8:17pm UTC](https://community.thinkgeo.com/t/streamloading-event-how-do-i-know-which-stream-is-loading/1491/3 "2010-11-10T20:17:20Z")

</div>

Paul,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;am&nbsp;glad&nbsp;you&nbsp;find&nbsp;the&nbsp;solution&nbsp;by&nbsp;yourself.&nbsp;  
&nbsp;&nbsp;  
&nbsp;When&nbsp;create&nbsp;a&nbsp;GdiPlusRasterLayer&nbsp;you&nbsp;will&nbsp;pass&nbsp;in&nbsp;the&nbsp;image&nbsp;file&nbsp;path,&nbsp;at&nbsp;event&nbsp;handler&nbsp;you&nbsp;can&nbsp;access&nbsp;e.AlternateStreamName&nbsp;to&nbsp;indicate&nbsp;which&nbsp;stream&nbsp;is&nbsp;what&nbsp;you&nbsp;want.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Please&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;more&nbsp;questions.&nbsp;  
&nbsp;Thanks&nbsp;  
&nbsp;James

---

<div class="post-metadata">

**Author:** ![Paul2](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/paul2/32/24982_2.png) [@Paul2](https://community.thinkgeo.com/u/Paul2)\
**Post date:** [November 10, 2010, 11:23pm UTC](https://community.thinkgeo.com/t/streamloading-event-how-do-i-know-which-stream-is-loading/1491/4 "2010-11-10T23:23:19Z")

</div>

Thanks&nbsp;James.&nbsp;To&nbsp;be&nbsp;clear,&nbsp;the&nbsp;problem&nbsp;I&nbsp;was&nbsp;having&nbsp;is&nbsp;that&nbsp;e.AlternateStreamName&nbsp;doesn’t&nbsp;have&nbsp;any&nbsp;indication&nbsp;of&nbsp;which&nbsp;GdiPlusRasterSource&nbsp;is&nbsp;firing&nbsp;the&nbsp;event&nbsp;-&nbsp;but&nbsp;the&nbsp;sender&nbsp;object&nbsp;is&nbsp;the&nbsp;firing&nbsp;GdiPlusRasterSource,&nbsp;and&nbsp;you&nbsp;can&nbsp;pull&nbsp;the&nbsp;file&nbsp;name&nbsp;from&nbsp;it.&nbsp;The&nbsp;AlternateStreamName&nbsp;is&nbsp;just&nbsp;a&nbsp;delimited&nbsp;list&nbsp;of&nbsp;file&nbsp;extensions.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [November 11, 2010, 1:30am UTC](https://community.thinkgeo.com/t/streamloading-event-how-do-i-know-which-stream-is-loading/1491/5 "2010-11-11T01:30:20Z")

</div>

Paul,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yes,&nbsp;you’re&nbsp;right.&nbsp;I&nbsp;just&nbsp;think&nbsp;about&nbsp;the&nbsp;same&nbsp;event&nbsp;of&nbsp;ShapeFileFeatureSource,&nbsp;it&nbsp;will&nbsp;pass&nbsp;out&nbsp;the&nbsp;full&nbsp;path,&nbsp;but&nbsp;GdiPlusRasterSource&nbsp;doesn’t.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;point&nbsp;that.&nbsp;  
&nbsp;James
