Creating multiple galleries programtically

Last post 03-24-2011, 10:48 PM by cntakuchi. 4 replies.
Sort Posts: Previous Next
  •  02-25-2011, 9:29 PM 66459

    Creating multiple galleries programtically

    Hello.  I have an aspx page that needs to be populated with a variable number of galleries based on user settings.  By default, there is one gallery that is implemented statically and all of the rest are implemented
    programmatically.  Also, each gallery needs to have a different Gallery Folder.  The problem is that when I try to add files to one of the programmatically implemeted galleries, the admin console shows the images from the static gallery.  In order words if I try to upload an image into one of the galleries created programmatically is just goes to into the static gallery.  Below is a sample of my source code. 
     
    For the static gallery.
     
     C#
     GalleryBrowser1.AllowEdit=true;
     
    Aspx
     <%if(GalleryBrowser1.AllowEdit){%>
                            <a href="#" onclick="thegallerybrowser.ShowEditor();return false;">Upload Photos</a> |
                        <%}%>
                            <a href="#" onclick="thegallerybrowser.ShowSlider();return false;">View as slide show</a>
                        </div>
                        <dotnetgallery:gallerybrowser runat="server" id="GalleryBrowser1" Width="780" Height="400" />
     
    For the Dynamically Created Galleries
     
    DotNetGallery.GalleryBrowser gallery = new DotNetGallery.GalleryBrowser();
                    gallery.GalleryFolder = @"~/GalleryFiles/" + _profileUser.UserName + sport.sportName.Trim() + @"/";
                    gallery.ID = sport.sportName.Trim();
                    gallery.LogonUserName = HttpContext.Current.Profile.UserName;
                    gallery.Viewer = "LightBox";
                    gallery.ConsoleLayout = "Explorer";
                    gallery.Theme = "Classic";
                    gallery.Layout = "Classic";
                    
                    
                    gallery.AllowEdit = true;
                    Literal galleryControlLiteral = new Literal();
                    StringBuilder gallerySb = new StringBuilder("<a href=");
                    gallerySb.Append('"');
                    gallerySb.Append("#");
                    gallerySb.Append('"');
                    gallerySb.Append("onclick=");
                    gallerySb.Append('"');
                    gallerySb.Append("thegallerybrowser.ShowEditor();return false;");
                    gallerySb.Append('"');
                    gallerySb.Append(">Upload New Pictures</a>");

                    galleryControlLiteral.Text = gallerySb.ToString();

                    if (_isUsersOwnProfile)
                    {
                        page.Controls.Add(literal);
                    }
                    page.Controls.Add(gallery);
                    page.Controls.Add(galleryControlLiteral);
                    ASPxPageControlSports.TabPages.Add(page);
     
    Any help figuring this out would be greatly appreciated.  
     
    Thanks in Advance. 
    Filed under:
  •  02-26-2011, 1:10 AM 66460 in reply to 66459

    Re: Creating multiple galleries programtically

    Hi pat8719,
    Please try the code below,
     
    Aspx
     <%if(GalleryBrowser1.AllowEdit){%>
                            <a href="#" onclick="thegallerybrowser.ShowEditor();return false;">Upload Photos</a> |
                        <%}%>
                            <a href="#" onclick="thegallerybrowser.ShowSlider();return false;">View as slide show</a>
                        </div>
                        <dotnetgallery:gallerybrowser runat="server" id="GalleryBrowser1" Width="780" Height="400" />
    C#
    1. protected override void OnInit(EventArgs e)   
    2. {   
    3.     base.OnInit(e);   
    4.        
    5.     GalleryBrowser1.Layout="SlideShow";   
    6.     string folder = "~/GalleryFiles/" + _profileUser.UserName + sport.sportName.Trim() + "/";   
    7.     if (!System.IO.Directory.Exists(Server.MapPath(folder)))   
    8.         System.IO.Directory.CreateDirectory(Server.MapPath(folder));   
    9.     GalleryBrowser1.GalleryFolder = folder;   
    10.     GalleryBrowser1.LogonUserName = HttpContext.Current.Profile.UserName;   
    11.     GalleryBrowser1.Viewer = "LightBox";   
    12.     GalleryBrowser1.ConsoleLayout = "Explorer";   
    13.     GalleryBrowser1.Theme = "Classic";   
    14.     GalleryBrowser1.Layout = "Classic";   
    15.        
    16.        
    17.   
    18.        
    19. //  if(Context.User.Identity.Name=="Admin")   
    20. //  {   
    21.           
    22.         GalleryBrowser1.AllowEdit=true;   
    23.         GalleryBrowser1.AllowPostComment=true;   
    24.         GalleryBrowser1.AllowShowComment=true;   
    25. //  }   
    26.        
    27. }  
     

    Regards,
    Jeff
  •  02-26-2011, 10:27 AM 66464 in reply to 66460

    Re: Creating multiple galleries programtically

    Jeff,
     
    Now a new gallery folder gets created but any uploads still go into the gallery that was created statically
    elsewhere on the page rather than the gallery we are creating in code 
  •  02-26-2011, 8:21 PM 66466 in reply to 66464

    Re: Creating multiple galleries programtically

    Hi pat8719,
    If you upload in the page, it will save to the new Gallery,
    In my local demo it works well,
    Please send me your test page
     
    Regards,
    Jeff
View as RSS news feed in XML