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 behindpage 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.
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 behindpage 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.