By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,586 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

saving picture to a user profile!

P: n/a
Hey

(and thank you for reading my post)

In visual web developer 2005 express edition I've created a simple website
project..

At this website I want users who register to be able to upload a picture of
themselves to their profile... I admit that I'm a newbie... but this is how
I understand this:

I create a new section in web.config contain this info
<profile defaultProvider="AspNetSqlProfileProvider">
<properties>
<add name="Name" />
<add name="Picture" type="System.Web.UI.WebControls.Image" />
</properties>
</profile>

Then in the code I can write something like this:

Profile.Picture = <a picture>;

And then during execution of this code the picture is automatically saved in
the express database visual web developer 2005 express edition created in
this project folder. (the .NET framework creates the new column in the user
profile and do all functionality for saving & loading the image from the db)

Is it how it works???

Hmm it can't be correct, because even now I can create new users to my
website, name & password being used by the login control in my website...
but all the data my web.config file has is this:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/></system.web>
</configuration>
There are no settings here that hold the username and password..... so
clearly what I suggest above must be wrong!

Please guide me on the right track here, give me some clue I could look
after... a link explaining this would be great (I've been google already,
but I think I'm searching with the wrong keywords)

Please, I'm stucked in this, so some suggestions would be greatly
appreaciated!

Jeff
Jun 28 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
hey jeff

you'll likely want to store the picture as a byte array in the profile

images in html are not embedded in the html itself, but are references
to external files, so you'll have to create another url that serves up
the images.

in your web.config:

<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" defaultValue="null"
/>
<add name="PictureType" type="string" />
</properties>
</profile>

your upload page could be like this:

<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />

with this in the code behind (C#):

protected void Button1_Click(object sender, EventArgs e)
{
HttpPostedFile file = FileUpload1.PostedFile;

byte[] data = new byte[file.ContentLength];

file.InputStream.Read(data, 0, file.ContentLength);

Profile.Picture = data;
Profile.PictureType = file.ContentType;
}

your "getImage.aspx" page like this (C#):

protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}

and your page that you want to host the image on, like this:

<img src="getImage.aspx" />

HTH

Neil
Jeff wrote:
Hey

(and thank you for reading my post)

In visual web developer 2005 express edition I've created a simple website
project..

At this website I want users who register to be able to upload a picture of
themselves to their profile... I admit that I'm a newbie... but this is how
I understand this:

I create a new section in web.config contain this info
<profile defaultProvider="AspNetSqlProfileProvider">
<properties>
<add name="Name" />
<add name="Picture" type="System.Web.UI.WebControls.Image" />
</properties>
</profile>

Then in the code I can write something like this:

Profile.Picture = <a picture>;

And then during execution of this code the picture is automatically saved in
the express database visual web developer 2005 express edition created in
this project folder. (the .NET framework creates the new column in the user
profile and do all functionality for saving & loading the image from the db)

Is it how it works???

Hmm it can't be correct, because even now I can create new users to my
website, name & password being used by the login control in my website...
but all the data my web.config file has is this:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/></system.web>
</configuration>
There are no settings here that hold the username and password..... so
clearly what I suggest above must be wrong!

Please guide me on the right track here, give me some clue I could look
after... a link explaining this would be great (I've been google already,
but I think I'm searching with the wrong keywords)

Please, I'm stucked in this, so some suggestions would be greatly
appreaciated!

Jeff


Jun 29 '06 #2

P: n/a
Hey

Thank you very much for your help, I've almost solved this now.

However I've run into a little problem:
When I run this app I get this exception:
"The property 'Picture' could not be created from it's default value. Error
message"

I get this error when the picture property is null

Here is my code (I'm using the same webpage to view the image and select the
image):

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/>
<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" defaultValue="null" />
<add name="PictureType" type="string" />
</properties>
</profile>
</system.web>
</configuration>

public partial class webForms_Profile_photo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}

protected void Button1_Click(object sender, EventArgs e)
{
HttpPostedFile file = FileUpload1.PostedFile;
byte[] data = new byte[file.ContentLength];
file.InputStream.Read(data, 0, file.ContentLength);
Profile.Picture = data;
Profile.PictureType = file.ContentType;
}
}

Any ideas on how to solve this?

Jeff

<ne**********@gmail.com> wrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
hey jeff

you'll likely want to store the picture as a byte array in the profile

images in html are not embedded in the html itself, but are references
to external files, so you'll have to create another url that serves up
the images.

in your web.config:

<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" defaultValue="null"
/>
<add name="PictureType" type="string" />
</properties>
</profile>

your upload page could be like this:

<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />

with this in the code behind (C#):

protected void Button1_Click(object sender, EventArgs e)
{
HttpPostedFile file = FileUpload1.PostedFile;

byte[] data = new byte[file.ContentLength];

file.InputStream.Read(data, 0, file.ContentLength);

Profile.Picture = data;
Profile.PictureType = file.ContentType;
}

your "getImage.aspx" page like this (C#):

protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}

and your page that you want to host the image on, like this:

<img src="getImage.aspx" />

HTH

Neil
Jeff wrote:
Hey

(and thank you for reading my post)

In visual web developer 2005 express edition I've created a simple
website
project..

At this website I want users who register to be able to upload a picture
of
themselves to their profile... I admit that I'm a newbie... but this is
how
I understand this:

I create a new section in web.config contain this info
<profile defaultProvider="AspNetSqlProfileProvider">
<properties>
<add name="Name" />
<add name="Picture" type="System.Web.UI.WebControls.Image" />
</properties>
</profile>

Then in the code I can write something like this:

Profile.Picture = <a picture>;

And then during execution of this code the picture is automatically saved
in
the express database visual web developer 2005 express edition created in
this project folder. (the .NET framework creates the new column in the
user
profile and do all functionality for saving & loading the image from the
db)

Is it how it works???

Hmm it can't be correct, because even now I can create new users to my
website, name & password being used by the login control in my website...
but all the data my web.config file has is this:
<?xml version="1.0"?>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/></system.web>
</configuration>
There are no settings here that hold the username and password..... so
clearly what I suggest above must be wrong!

Please guide me on the right track here, give me some clue I could look
after... a link explaining this would be great (I've been google already,
but I think I'm searching with the wrong keywords)

Please, I'm stucked in this, so some suggestions would be greatly
appreaciated!

Jeff

Jun 29 '06 #3

P: n/a
hey jeff

the part with Response.BinaryWrite has to be in a different page, in
this case GetFile.aspx

you should also check for null:

if(Profile.Picture != null)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}

cheers

neil

Jeff wrote:
Hey

Thank you very much for your help, I've almost solved this now.

However I've run into a little problem:
When I run this app I get this exception:
"The property 'Picture' could not be created from it's default value. Error
message"

I get this error when the picture property is null

Here is my code (I'm using the same webpage to view the image and select the
image):

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/>
<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" defaultValue="null" />
<add name="PictureType" type="string" />
</properties>
</profile>
</system.web>
</configuration>

public partial class webForms_Profile_photo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}

protected void Button1_Click(object sender, EventArgs e)
{
HttpPostedFile file = FileUpload1.PostedFile;
byte[] data = new byte[file.ContentLength];
file.InputStream.Read(data, 0, file.ContentLength);
Profile.Picture = data;
Profile.PictureType = file.ContentType;
}
}

Any ideas on how to solve this?

Jeff

<ne**********@gmail.com> wrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
hey jeff

you'll likely want to store the picture as a byte array in the profile

images in html are not embedded in the html itself, but are references
to external files, so you'll have to create another url that serves up
the images.

in your web.config:

<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" defaultValue="null"
/>
<add name="PictureType" type="string" />
</properties>
</profile>

your upload page could be like this:

<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />

with this in the code behind (C#):

protected void Button1_Click(object sender, EventArgs e)
{
HttpPostedFile file = FileUpload1.PostedFile;

byte[] data = new byte[file.ContentLength];

file.InputStream.Read(data, 0, file.ContentLength);

Profile.Picture = data;
Profile.PictureType = file.ContentType;
}

your "getImage.aspx" page like this (C#):

protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}

and your page that you want to host the image on, like this:

<img src="getImage.aspx" />

HTH

Neil
Jeff wrote:
Hey

(and thank you for reading my post)

In visual web developer 2005 express edition I've created a simple
website
project..

At this website I want users who register to be able to upload a picture
of
themselves to their profile... I admit that I'm a newbie... but this is
how
I understand this:

I create a new section in web.config contain this info
<profile defaultProvider="AspNetSqlProfileProvider">
<properties>
<add name="Name" />
<add name="Picture" type="System.Web.UI.WebControls.Image" />
</properties>
</profile>

Then in the code I can write something like this:

Profile.Picture = <a picture>;

And then during execution of this code the picture is automatically saved
in
the express database visual web developer 2005 express edition created in
this project folder. (the .NET framework creates the new column in the
user
profile and do all functionality for saving & loading the image from the
db)

Is it how it works???

Hmm it can't be correct, because even now I can create new users to my
website, name & password being used by the login control in my website...
but all the data my web.config file has is this:
<?xml version="1.0"?>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/></system.web>
</configuration>
There are no settings here that hold the username and password..... so
clearly what I suggest above must be wrong!

Please guide me on the right track here, give me some clue I could look
after... a link explaining this would be great (I've been google already,
but I think I'm searching with the wrong keywords)

Please, I'm stucked in this, so some suggestions would be greatly
appreaciated!

Jeff


Jun 29 '06 #4

P: n/a
Hey
My code crashes:

This is the error message I get:
"The property 'Picture' could not be created from it's default value. Error
message: There is an error in XML document (1, 1)."

(The crash occur in public class ProfileCommon :
System.Web.Profile.ProfileBase, see code below):

public virtual byte[] Picture {
get {
return ((byte[])(this.GetPropertyValue("Picture")));
}
set {
this.SetPropertyValue("Picture", value);
}
}

This is my web.config file:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/>
<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" defaultValue="null"
/>
<add name="PictureType" type="string" />
</properties>
</profile>
</system.web>
</configuration>
Any ideas what I should do to fix this problem?... I thought about setting
another image as default value, but then the image had to be converted to
xml and placed in web.config. And maybe if I use a default image it wouldn't
solve the problem either -> maybe the error occur because of a error in
web.config?

any ideas?
<ne**********@gmail.com> wrote in message
news:11**********************@x69g2000cwx.googlegr oups.com...
hey jeff

the part with Response.BinaryWrite has to be in a different page, in
this case GetFile.aspx

you should also check for null:

if(Profile.Picture != null)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}

cheers

neil

Jeff wrote:
Hey

Thank you very much for your help, I've almost solved this now.

However I've run into a little problem:
When I run this app I get this exception:
"The property 'Picture' could not be created from it's default value.
Error
message"

I get this error when the picture property is null

Here is my code (I'm using the same webpage to view the image and select
the
image):

<?xml version="1.0"?>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/>
<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" defaultValue="null" />
<add name="PictureType" type="string" />
</properties>
</profile>
</system.web>
</configuration>

public partial class webForms_Profile_photo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}

protected void Button1_Click(object sender, EventArgs e)
{
HttpPostedFile file = FileUpload1.PostedFile;
byte[] data = new byte[file.ContentLength];
file.InputStream.Read(data, 0, file.ContentLength);
Profile.Picture = data;
Profile.PictureType = file.ContentType;
}
}

Any ideas on how to solve this?

Jeff

<ne**********@gmail.com> wrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
> hey jeff
>
> you'll likely want to store the picture as a byte array in the profile
>
> images in html are not embedded in the html itself, but are references
> to external files, so you'll have to create another url that serves up
> the images.
>
> in your web.config:
>
> <profile enabled="true">
> <properties>
> <add name="Picture" type="System.Byte[]" defaultValue="null"
> />
> <add name="PictureType" type="string" />
> </properties>
> </profile>
>
> your upload page could be like this:
>
> <asp:FileUpload ID="FileUpload1" runat="server" />
> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
> Text="Button" />
>
> with this in the code behind (C#):
>
> protected void Button1_Click(object sender, EventArgs e)
> {
> HttpPostedFile file = FileUpload1.PostedFile;
>
> byte[] data = new byte[file.ContentLength];
>
> file.InputStream.Read(data, 0, file.ContentLength);
>
> Profile.Picture = data;
> Profile.PictureType = file.ContentType;
> }
>
> your "getImage.aspx" page like this (C#):
>
> protected void Page_Load(object sender, EventArgs e)
> {
> Response.ContentType = Profile.PictureType;
> Response.BinaryWrite(Profile.Picture);
> Response.End();
> }
>
> and your page that you want to host the image on, like this:
>
> <img src="getImage.aspx" />
>
> HTH
>
> Neil
>
>
> Jeff wrote:
>> Hey
>>
>> (and thank you for reading my post)
>>
>> In visual web developer 2005 express edition I've created a simple
>> website
>> project..
>>
>> At this website I want users who register to be able to upload a
>> picture
>> of
>> themselves to their profile... I admit that I'm a newbie... but this
>> is
>> how
>> I understand this:
>>
>> I create a new section in web.config contain this info
>> <profile defaultProvider="AspNetSqlProfileProvider">
>> <properties>
>> <add name="Name" />
>> <add name="Picture" type="System.Web.UI.WebControls.Image" />
>> </properties>
>> </profile>
>>
>> Then in the code I can write something like this:
>>
>> Profile.Picture = <a picture>;
>>
>> And then during execution of this code the picture is automatically
>> saved
>> in
>> the express database visual web developer 2005 express edition created
>> in
>> this project folder. (the .NET framework creates the new column in the
>> user
>> profile and do all functionality for saving & loading the image from
>> the
>> db)
>>
>> Is it how it works???
>>
>> Hmm it can't be correct, because even now I can create new users to my
>> website, name & password being used by the login control in my
>> website...
>> but all the data my web.config file has is this:
>> <?xml version="1.0"?>
>> <configuration
>> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
>> <system.web>
>> <roleManager enabled="true"/>
>> <authentication mode="Forms"/>
>> <compilation debug="true"/></system.web>
>> </configuration>
>> There are no settings here that hold the username and password..... so
>> clearly what I suggest above must be wrong!
>>
>> Please guide me on the right track here, give me some clue I could
>> look
>> after... a link explaining this would be great (I've been google
>> already,
>> but I think I'm searching with the wrong keywords)
>>
>> Please, I'm stucked in this, so some suggestions would be greatly
>> appreaciated!
>>
>> Jeff
>

Jun 29 '06 #5

P: n/a
why are you doing it that way? thx
Jeff wrote:
Hey
My code crashes:

This is the error message I get:
"The property 'Picture' could not be created from it's default value. Error
message: There is an error in XML document (1, 1)."

(The crash occur in public class ProfileCommon :
System.Web.Profile.ProfileBase, see code below):

public virtual byte[] Picture {
get {
return ((byte[])(this.GetPropertyValue("Picture")));
}
set {
this.SetPropertyValue("Picture", value);
}
}

This is my web.config file:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/>
<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" defaultValue="null"
/>
<add name="PictureType" type="string" />
</properties>
</profile>
</system.web>
</configuration>
Any ideas what I should do to fix this problem?... I thought about setting
another image as default value, but then the image had to be converted to
xml and placed in web.config. And maybe if I use a default image it wouldn't
solve the problem either -> maybe the error occur because of a error in
web.config?

any ideas?
<ne**********@gmail.com> wrote in message
news:11**********************@x69g2000cwx.googlegr oups.com...
hey jeff

the part with Response.BinaryWrite has to be in a different page, in
this case GetFile.aspx

you should also check for null:

if(Profile.Picture != null)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}

cheers

neil

Jeff wrote:
Hey

Thank you very much for your help, I've almost solved this now.

However I've run into a little problem:
When I run this app I get this exception:
"The property 'Picture' could not be created from it's default value.
Error
message"

I get this error when the picture property is null

Here is my code (I'm using the same webpage to view the image and select
the
image):

<?xml version="1.0"?>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/>
<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" defaultValue="null" />
<add name="PictureType" type="string" />
</properties>
</profile>
</system.web>
</configuration>

public partial class webForms_Profile_photo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}

protected void Button1_Click(object sender, EventArgs e)
{
HttpPostedFile file = FileUpload1.PostedFile;
byte[] data = new byte[file.ContentLength];
file.InputStream.Read(data, 0, file.ContentLength);
Profile.Picture = data;
Profile.PictureType = file.ContentType;
}
}

Any ideas on how to solve this?

Jeff

<ne**********@gmail.com> wrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
> hey jeff
>
> you'll likely want to store the picture as a byte array in the profile
>
> images in html are not embedded in the html itself, but are references
> to external files, so you'll have to create another url that serves up
> the images.
>
> in your web.config:
>
> <profile enabled="true">
> <properties>
> <add name="Picture" type="System.Byte[]" defaultValue="null"
> />
> <add name="PictureType" type="string" />
> </properties>
> </profile>
>
> your upload page could be like this:
>
> <asp:FileUpload ID="FileUpload1" runat="server" />
> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
> Text="Button" />
>
> with this in the code behind (C#):
>
> protected void Button1_Click(object sender, EventArgs e)
> {
> HttpPostedFile file = FileUpload1.PostedFile;
>
> byte[] data = new byte[file.ContentLength];
>
> file.InputStream.Read(data, 0, file.ContentLength);
>
> Profile.Picture = data;
> Profile.PictureType = file.ContentType;
> }
>
> your "getImage.aspx" page like this (C#):
>
> protected void Page_Load(object sender, EventArgs e)
> {
> Response.ContentType = Profile.PictureType;
> Response.BinaryWrite(Profile.Picture);
> Response.End();
> }
>
> and your page that you want to host the image on, like this:
>
> <img src="getImage.aspx" />
>
> HTH
>
> Neil
>
>
> Jeff wrote:
>> Hey
>>
>> (and thank you for reading my post)
>>
>> In visual web developer 2005 express edition I've created a simple
>> website
>> project..
>>
>> At this website I want users who register to be able to upload a
>> picture
>> of
>> themselves to their profile... I admit that I'm a newbie... but this
>> is
>> how
>> I understand this:
>>
>> I create a new section in web.config contain this info
>> <profile defaultProvider="AspNetSqlProfileProvider">
>> <properties>
>> <add name="Name" />
>> <add name="Picture" type="System.Web.UI.WebControls.Image" />
>> </properties>
>> </profile>
>>
>> Then in the code I can write something like this:
>>
>> Profile.Picture = <a picture>;
>>
>> And then during execution of this code the picture is automatically
>> saved
>> in
>> the express database visual web developer 2005 express edition created
>> in
>> this project folder. (the .NET framework creates the new column in the
>> user
>> profile and do all functionality for saving & loading the image from
>> the
>> db)
>>
>> Is it how it works???
>>
>> Hmm it can't be correct, because even now I can create new users to my
>> website, name & password being used by the login control in my
>> website...
>> but all the data my web.config file has is this:
>> <?xml version="1.0"?>
>> <configuration
>> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
>> <system.web>
>> <roleManager enabled="true"/>
>> <authentication mode="Forms"/>
>> <compilation debug="true"/></system.web>
>> </configuration>
>> There are no settings here that hold the username and password..... so
>> clearly what I suggest above must be wrong!
>>
>> Please guide me on the right track here, give me some clue I could
>> look
>> after... a link explaining this would be great (I've been google
>> already,
>> but I think I'm searching with the wrong keywords)
>>
>> Please, I'm stucked in this, so some suggestions would be greatly
>> appreaciated!
>>
>> Jeff
>


Jun 30 '06 #6

P: n/a
Hey

Thank you for taking the time to respond to my post here on this forum.

I removed the defaultValue from the "picture" property in web.config. Then I
realized that I have to use 2 webpages. 1 webpage (page A) to read in the
image.... and another webpage (page B) that displays the result of page A...

Thanks!


<ne**********@gmail.com> wrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
why are you doing it that way? thx
Jeff wrote:
Hey
My code crashes:

This is the error message I get:
"The property 'Picture' could not be created from it's default value.
Error
message: There is an error in XML document (1, 1)."

(The crash occur in public class ProfileCommon :
System.Web.Profile.ProfileBase, see code below):

public virtual byte[] Picture {
get {
return ((byte[])(this.GetPropertyValue("Picture")));
}
set {
this.SetPropertyValue("Picture", value);
}
}

This is my web.config file:
<?xml version="1.0"?>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/>
<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]"
defaultValue="null"
/>
<add name="PictureType" type="string" />
</properties>
</profile>
</system.web>
</configuration>
Any ideas what I should do to fix this problem?... I thought about
setting
another image as default value, but then the image had to be converted to
xml and placed in web.config. And maybe if I use a default image it
wouldn't
solve the problem either -> maybe the error occur because of a error in
web.config?

any ideas?
<ne**********@gmail.com> wrote in message
news:11**********************@x69g2000cwx.googlegr oups.com...
> hey jeff
>
> the part with Response.BinaryWrite has to be in a different page, in
> this case GetFile.aspx
>
> you should also check for null:
>
> if(Profile.Picture != null)
> {
> Response.ContentType = Profile.PictureType;
> Response.BinaryWrite(Profile.Picture);
> Response.End();
> }
>
> cheers
>
> neil
>
> Jeff wrote:
>> Hey
>>
>> Thank you very much for your help, I've almost solved this now.
>>
>> However I've run into a little problem:
>> When I run this app I get this exception:
>> "The property 'Picture' could not be created from it's default value.
>> Error
>> message"
>>
>> I get this error when the picture property is null
>>
>> Here is my code (I'm using the same webpage to view the image and
>> select
>> the
>> image):
>>
>> <?xml version="1.0"?>
>> <configuration
>> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
>> <system.web>
>> <roleManager enabled="true"/>
>> <authentication mode="Forms"/>
>> <compilation debug="true"/>
>> <profile enabled="true">
>> <properties>
>> <add name="Picture" type="System.Byte[]" defaultValue="null" />
>> <add name="PictureType" type="string" />
>> </properties>
>> </profile>
>> </system.web>
>> </configuration>
>>
>> public partial class webForms_Profile_photo : System.Web.UI.Page
>> {
>> protected void Page_Load(object sender, EventArgs e)
>> {
>> Response.ContentType = Profile.PictureType;
>> Response.BinaryWrite(Profile.Picture);
>> Response.End();
>> }
>>
>> protected void Button1_Click(object sender, EventArgs e)
>> {
>> HttpPostedFile file = FileUpload1.PostedFile;
>> byte[] data = new byte[file.ContentLength];
>> file.InputStream.Read(data, 0, file.ContentLength);
>> Profile.Picture = data;
>> Profile.PictureType = file.ContentType;
>> }
>> }
>>
>> Any ideas on how to solve this?
>>
>> Jeff
>>
>>
>>
>>
>>
>> <ne**********@gmail.com> wrote in message
>> news:11**********************@p79g2000cwp.googlegr oups.com...
>> > hey jeff
>> >
>> > you'll likely want to store the picture as a byte array in the
>> > profile
>> >
>> > images in html are not embedded in the html itself, but are
>> > references
>> > to external files, so you'll have to create another url that serves
>> > up
>> > the images.
>> >
>> > in your web.config:
>> >
>> > <profile enabled="true">
>> > <properties>
>> > <add name="Picture" type="System.Byte[]"
>> > defaultValue="null"
>> > />
>> > <add name="PictureType" type="string" />
>> > </properties>
>> > </profile>
>> >
>> > your upload page could be like this:
>> >
>> > <asp:FileUpload ID="FileUpload1" runat="server" />
>> > <asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
>> > Text="Button" />
>> >
>> > with this in the code behind (C#):
>> >
>> > protected void Button1_Click(object sender, EventArgs e)
>> > {
>> > HttpPostedFile file = FileUpload1.PostedFile;
>> >
>> > byte[] data = new byte[file.ContentLength];
>> >
>> > file.InputStream.Read(data, 0, file.ContentLength);
>> >
>> > Profile.Picture = data;
>> > Profile.PictureType = file.ContentType;
>> > }
>> >
>> > your "getImage.aspx" page like this (C#):
>> >
>> > protected void Page_Load(object sender, EventArgs e)
>> > {
>> > Response.ContentType = Profile.PictureType;
>> > Response.BinaryWrite(Profile.Picture);
>> > Response.End();
>> > }
>> >
>> > and your page that you want to host the image on, like this:
>> >
>> > <img src="getImage.aspx" />
>> >
>> > HTH
>> >
>> > Neil
>> >
>> >
>> > Jeff wrote:
>> >> Hey
>> >>
>> >> (and thank you for reading my post)
>> >>
>> >> In visual web developer 2005 express edition I've created a simple
>> >> website
>> >> project..
>> >>
>> >> At this website I want users who register to be able to upload a
>> >> picture
>> >> of
>> >> themselves to their profile... I admit that I'm a newbie... but
>> >> this
>> >> is
>> >> how
>> >> I understand this:
>> >>
>> >> I create a new section in web.config contain this info
>> >> <profile defaultProvider="AspNetSqlProfileProvider">
>> >> <properties>
>> >> <add name="Name" />
>> >> <add name="Picture" type="System.Web.UI.WebControls.Image" />
>> >> </properties>
>> >> </profile>
>> >>
>> >> Then in the code I can write something like this:
>> >>
>> >> Profile.Picture = <a picture>;
>> >>
>> >> And then during execution of this code the picture is automatically
>> >> saved
>> >> in
>> >> the express database visual web developer 2005 express edition
>> >> created
>> >> in
>> >> this project folder. (the .NET framework creates the new column in
>> >> the
>> >> user
>> >> profile and do all functionality for saving & loading the image
>> >> from
>> >> the
>> >> db)
>> >>
>> >> Is it how it works???
>> >>
>> >> Hmm it can't be correct, because even now I can create new users to
>> >> my
>> >> website, name & password being used by the login control in my
>> >> website...
>> >> but all the data my web.config file has is this:
>> >> <?xml version="1.0"?>
>> >> <configuration
>> >> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
>> >> <system.web>
>> >> <roleManager enabled="true"/>
>> >> <authentication mode="Forms"/>
>> >> <compilation debug="true"/></system.web>
>> >> </configuration>
>> >> There are no settings here that hold the username and password.....
>> >> so
>> >> clearly what I suggest above must be wrong!
>> >>
>> >> Please guide me on the right track here, give me some clue I could
>> >> look
>> >> after... a link explaining this would be great (I've been google
>> >> already,
>> >> but I think I'm searching with the wrong keywords)
>> >>
>> >> Please, I'm stucked in this, so some suggestions would be greatly
>> >> appreaciated!
>> >>
>> >> Jeff
>> >
>

Jun 30 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.