images in profile

G

Guest

I’ve been playing around with the profile over the weekend and thought I’d
share my results:
“Save a picture in the profile using file upload control then display it on
a pageâ€

webConfig:
<anonymousIdentification enabled="true"/>
<profile>
<properties>
<add name="picture" serializeAs="Binary" type="System.Object"/>
</properties>
</profile>

Created two pages:

profileUpload.aspx:

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="profileUpload.aspx.vb" Inherits="profileUpload" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" />

</form>
</body>
</html>

Code behind:
Button1 click event:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Reference the FileUpload control
Dim UploadedFile As FileUpload =
CType(FileUpload1.FindControl("FileUpload1"), FileUpload)
'Load FileUpload's InputStream into Byte array
Dim imageBytes(UploadedFile.PostedFile.InputStream.Length) As Byte
UploadedFile.PostedFile.InputStream.Read(imageBytes, 0,
imageBytes.Length)
Profile.picture = imageBytes
Response.Redirect("profileTest.aspx")
End Sub

profileTest.aspx (blank aspx page)

code behind:(page load event)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Response.ContentType = "jpg"
Response.BinaryWrite(Profile.picture)

End Sub

Seems to work!

Any comments? – Simplfy or alternative method?
Would welcome your feedback.
 
G

Guest

Works in Firefox but for this to work in IE7 and Firefox amend
profileTest.aspx load event to:

Dim imageData As Object = Profile.picture
Dim imageType As String = "image/jpeg"

Response.ContentType = imageType
Response.BinaryWrite(imageData)
 

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

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top