First of all, when I search for profile in .net, I find rare answers for Profile in .Net 4.0
My question now: I designed a register page using ASP.net web project (not web site). and I saved basic information norrmally using aspnetdb, I saved Roles, and some properties to Profile also. But now I want to save a picture (itself not a path or url)
In the user profile I tried many way
Diaa.Asfour
Member
11 Points
17 Posts
Profile in .Net framework 4.0
Feb 14, 2012 12:54 PM|LINK
First of all, when I search for profile in .net, I find rare answers for Profile in .Net 4.0
My question now: I designed a register page using ASP.net web project (not web site). and I saved basic information norrmally using aspnetdb, I saved Roles, and some properties to Profile also. But now I want to save a picture (itself not a path or url) In the user profile I tried many way
like
<properties>
<add name="EmpId" allowAnonymous="true" />
<add name="Mobile" allowAnonymous="true" />
<add name="Address" allowAnonymous="true" />
<add name="Personalphoto" allowAnonymous="true"/>
</properties>
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: Profile in .Net framework 4.0
Feb 16, 2012 07:33 AM|LINK
Hi
You can convert the picture to byte array, then store the byte array to your db.
Next time convert the array to picture back.
Here is a example, hope it helpful:
using Im = System.Drawing.Image; public partial class Picture : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { byte[] barrImg = File.ReadAllBytes(@"C:\Users\y\Desktop\dino.jpg"); MemoryStream memStream = new MemoryStream(barrImg); Im img = Im.FromStream(memStream); img.Save(Response.OutputStream, ImageFormat.Jpeg); } }If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
Diaa.Asfour
Member
11 Points
17 Posts
Re: Profile in .Net framework 4.0
Feb 18, 2012 06:19 AM|LINK
Thank you Dino, but I want to save theses bytes using ASP.net profile:
Profile.SetPropertyValue("photo", byteImageData);
Profile.Save();
but it does not work
MetalAsp.Net
All-Star
112219 Points
18266 Posts
Moderator
Re: Profile in .Net framework 4.0
Feb 18, 2012 07:09 AM|LINK
Diaa.Asfour
Member
11 Points
17 Posts
Re: Profile in .Net framework 4.0
Feb 18, 2012 07:58 AM|LINK
I did the following
<properties>
<add name="Mobile" allowAnonymous="true" />
<add name="Address" allowAnonymous="true" />
<add name="photo" allowAnonymous="true" type="System.Array" serializeAs="Binary" />
</properties>
And after save I check the db i find the mobile and address are saved, but the image is not saved.
MetalAsp.Net
All-Star
112219 Points
18266 Posts
Moderator
Re: Profile in .Net framework 4.0
Feb 18, 2012 12:25 PM|LINK
I found this page: http://bytes.com/topic/asp-net/answers/338721-saving-image-profile. They used Object for type and Binary for serializeAs. Maybe it'ss work for you.
Diaa.Asfour
Member
11 Points
17 Posts
Re: Profile in .Net framework 4.0
Feb 20, 2012 02:31 PM|LINK
Thank you .. It works fine now.
and here are the complete code:
//Web.Config
<properties>
<add name="Mobile" allowAnonymous="true" />
<add name="Address" allowAnonymous="true" />
<add name="photo" allowAnonymous="true" type="System.Object" serializeAs="Binary" />
</properties>
//Uploading an Image
byteImageData = ReadImage("E:\\Picture\\" + postedImage.FileName, new string[] { ".gif", ".jpg", ".bmp" });
//Assign data and Saving profile
Profile.SetPropertyValue("photo", byteImageData);
Profile.SetPropertyValue("Address",RTBAddress.Text);
Profile.SetPropertyValue("Mobile",RTBMobile.Text);
Profile.Save();\
//Check that the Image is saved correctly
byte[] barrImg = (byte[])((HttpContext.Current.Profile.GetPropertyValue("photo")));
var strfn = Convert.ToString(DateTime.Now.ToFileTime());
var fs = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write);
fs.Write(barrImg, 0, barrImg.Length);
fs.Flush();
fs.Close();
The Image will be in the following location:
..\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0