View Single Post
  #57 (permalink)  
Old August 24th, 2007, 06:40 PM
krainov krainov is offline
Authorized User
 
Join Date: Aug 2007
Location: Moscow, , Russia.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by 99mary
 Choice avatar with loading on server if to whom will be necessary

UserProfile.ascx

<asp:FileUpload ID="filUpload" runat="server" />&nbsp;
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Add" CausesValidation="false" />

UserProfile.ascx.cs

     protected void btnUpload_Click(object sender, EventArgs e)
     {
         lblFeedbackKO.Visible = false;
         lblFeedbackOK.Visible = false;
         if (filUpload.PostedFile != null && filUpload.PostedFile.ContentLength > 0 && filUpload.PostedFile.FileName != string.Empty)
         {
             try
             {
                 // if not already present, create a directory named /Uploads/<CurrentUserName>
                 string dirUrl = (this.Page as MB.TheBeerHouse.UI.BasePage).BaseUrl +
                     "Uploads/" + this.Page.User.Identity.Name;
                 string dirPath = Server.MapPath(dirUrl);
                 if (!Directory.Exists(dirPath))
                     Directory.CreateDirectory(dirPath);
                 // save the file under the user's personal folder
                 string fileUrl = dirUrl + "/" + Path.GetFileName(filUpload.PostedFile.FileName);
                 string _inputFile = fileUrl;
                 string contentType = filUpload.PostedFile.ContentType;
                 int contentLength = filUpload.PostedFile.ContentLength;
                
                 if (contentType != "image/pjpeg" && contentType != "image/gif" && contentType != "image/jpeg" && contentType != "image/x-png")
                     {
                         lblFeedbackKO.Visible = true;
                         lblFeedbackKO.Text = "Only GIF, JPEG and PNG image types are supported.";
                        
                     }
                 else

                         if (contentLength > 25000)
                         {
                             lblFeedbackKO.Visible = true;
                             lblFeedbackKO.Text = "Avatar images must be less than 25K in size.";

                         }
                         else
                         {
                             System.Drawing.Image image = System.Drawing.Image.FromStream(filUpload.PostedFi le.InputStream);
                             if (!((image.Width > 0 && image.Width <= 100) && (image.Height > 0 && image.Height <= 100)))
                             {
                                 lblFeedbackKO.Visible = true;
                                 lblFeedbackKO.Text = "Avatar images must be no larger than 150 by 150 pixels.";

                             }
                             else
                             {
                                 filUpload.PostedFile.SaveAs(Server.MapPath(fil eUrl));
                                 txtAvatarUrl.Text = fileUrl;
                                 lblFeedbackOK.Visible = true;
                                 lblFeedbackOK.Text = "File is successfully added.<br /> For change necessary to save profile.";
                             }
                         }
                        
                 }
            
             catch (Exception ex)
             {
                 lblFeedbackKO.Visible = true;
                 lblFeedbackKO.Text = ex.Message;
             }
         }
     }




I have following in my window: The name 'Directory' does not exist in the current context.
Also You did not said that it is necessary to locate the two <asp:Label> named OK & KO. Please, post the whole code-behind file for this feature.