For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > December 2006 > Image data in profile: 28 bytes unaccounted for?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Image data in profile: 28 bytes unaccounted for?
Roel

2006-12-20, 7:08 pm

Hi,

I'm using the ASP.NET 2.0 profile system to keep an image of members of my
website "MyWebsite".

Initially, I've created the property in the web.config like:
<add name="Photo" serializeAs="Binary" type="System.Byte[]" >

Doing so, the binary data was saved in the "PropertyValuesBinary" column in
"aspnet_profile".

Now I need to query the "aspnet_profile" table from another website,
"MyOtherWebsite", and I want to read the image-data.

Therefore, I've altered the profile property like:
<add name="Photo" serializeAs="Binary" type="System.Byte[]"
customProviderData="image"/>

Now the binary data gets saved in a new column "Photo" in "aspnet_profile".

In "MyWebsite", the image data is correctly read by Profile.Photo.
In "MyOtherWebsite", the image data is queried by SQL (DataTable) but when I
read the column "Photo" from "aspnet_profile" the binary data is 28 bytes
longer than the binary data returned by Profile.Photo.

How do I get rid of those extra 28 bytes?

Kind Regards,
Roel


bruce barker

2006-12-20, 7:08 pm

profile stores a serialized byte array, not just the data. use the
binary deserializer to read the column.

-- bruce (sqlwork.com)

Roel wrote:
> Hi,
>
> I'm using the ASP.NET 2.0 profile system to keep an image of members of my
> website "MyWebsite".
>
> Initially, I've created the property in the web.config like:
> <add name="Photo" serializeAs="Binary" type="System.Byte[]" >
>
> Doing so, the binary data was saved in the "PropertyValuesBinary" column in
> "aspnet_profile".
>
> Now I need to query the "aspnet_profile" table from another website,
> "MyOtherWebsite", and I want to read the image-data.
>
> Therefore, I've altered the profile property like:
> <add name="Photo" serializeAs="Binary" type="System.Byte[]"
> customProviderData="image"/>
>
> Now the binary data gets saved in a new column "Photo" in "aspnet_profile".
>
> In "MyWebsite", the image data is correctly read by Profile.Photo.
> In "MyOtherWebsite", the image data is queried by SQL (DataTable) but when I
> read the column "Photo" from "aspnet_profile" the binary data is 28 bytes
> longer than the binary data returned by Profile.Photo.
>
> How do I get rid of those extra 28 bytes?
>
> Kind Regards,
> Roel
>
>

Roel

2006-12-21, 4:11 am

Thanx Bruce!

I've used this code to deserialize the byte array:

private byte[] DeserializeImage(byte[] image)

{

byte[] buf = image;

MemoryStream ms = new MemoryStream();

ms.Write(buf, 0, buf.Length);

ms.S(0, 0);

BinaryFormatter b = new BinaryFormatter();

return (byte[])b.Deserialize(ms);

}

This does the trick!

Kind Regards,
Roel

"bruce barker" <nospam@nospam.com> wrote in message
news:%23NwXeBFJHHA.3676@TK2MSFTNGP03.phx.gbl...[color=darkred]
> profile stores a serialized byte array, not just the data. use the binary
> deserializer to read the column.
>
> -- bruce (sqlwork.com)
>
> Roel wrote:

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com