Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to upload a picture using session.when i upload the picture its uploaded with same name of session but when i again login from that id it does not show the same picture instead its show default picture.....

C#
protected void Button2_Click1(object sender, EventArgs e)
       {
           StartUpLoad();
       }
       private void StartUpLoad()
       {
           //get the file name of the posted image
              string username = (string)(Session["UserAuthentication"]);

              string imgName = username;
           //sets the image path
           string imgPath = "Images/gallery/adil/" + imgName;

           //get the size in bytes that

           int imgSize = FileUpload1.PostedFile.ContentLength;

           //validates the posted file before saving
           if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
           {
               // 10240 KB means 10MB, You can change the value based on your requirement
               if (FileUpload1.PostedFile.ContentLength > 1024000)
               {
                   Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big.')", true);

               }
               else
               {
                   //then save it to the Folder
                   FileUpload1.SaveAs(Server.MapPath(imgPath));
                   Image1.ImageUrl = username + imgPath;
                   Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true);

               }

           }


       }



// And this is mark up code of image upload
VB
<asp:Image
              ID="Image1" runat="server"
           ImageUrl="~/images/gallery/adil/dafult.jpg" Height="379px" Width="614px" />
Posted
Comments
Can you post the code where you are checking the session and if the picture exists with that name ?
fak_farrukh 3-Jun-13 2:08am    
protected void Page_Load(object sender, EventArgs e)
{


string username = (string)(Session["UserAuthentication"]);
if(Session["UserAuthentication"]!=null)
{
Label2.Text=username;


}
else
{
Response.Redirect("Login.aspx");
}
Ok. Then how are you reading the image and assigning that to the ImageUrl?
Please post that code.
KarthickInfosys 3-Jun-13 2:43am    
I think using session we cant able to retain the picture when your next login because the session id may changes when m multiple login times when your checking with that id its not possible

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900