locked
how to access folder in side a folder? RRS feed

  • Question

  • User-1136231507 posted

    Hi,

     I created slideshow with ajax slide show extender and I can display images in folder images in root with this code

    string path = HttpContext.Current.Server.MapPath("~/images/");

    with this code I can access images in folder but my slide show images are in other folder inside Folder images.

    string path = HttpContext.Current.Server.MapPath("~/images/SlideshowImages/");

    when slide show run display empty images I don't know why??????????

    plz help me, THANKS,

    Thursday, September 4, 2014 12:27 PM

Answers

  • User1918509225 posted

    Hi gigidel,

    I have tested your code ,the problem is  here:

    gigidel

    ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString()

    When you set your path as "~/Images/SlideshowImages",You will just get the ImagePath of one image like below ,you can set a breakpoint and debug it

    SlideshowImages/xx.jpg

    While the image path should be :

    Images/SlideshowImages/xx.jpg

    So I suggest that you can try the code below:

    new Slide
               {
                   Name = Path.GetFileNameWithoutExtension(file),
                   Description = Path.GetFileNameWithoutExtension(file) + " Description.",
                   ImagePath = "Images/"+pathUri.MakeRelativeUri(filePathUri).ToString()
               };

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 9, 2014 4:35 AM

All replies

  • User-1360095595 posted

    I think, though I'm not sure, the problem is that the slideshow extender needs a relative path whereas the MapPath() returns an absolute path. I'm referring to bulding the list of slides using AjaxControlToolkit.Slide(().

    I'm curious by your statement:

    I can display images in folder images in root with this code

    string path = HttpContext.Current.Server.MapPath("~/images/");

    Because when I try to use MapPath(), it doesn't work! So, when I use this:

    slides[0] = new AjaxControlToolkit.Slide("../../Images/Image1.gif", "One", "Image 1");
    slides[1] = new AjaxControlToolkit.Slide("../../Images/Image2.gif", "Two", "Image 2");
    

    It works. But if I use:

    slides[0] = new AjaxControlToolkit.Slide("~/Images/Image1.gif", "One", "Image 1");
    slides[1] = new AjaxControlToolkit.Slide("~/Images/Image2.gif", "Two", "Image 2");
    
    OR 
    
    slides[0] = new AjaxControlToolkit.Slide(HttpContext.Current.Server.MapPath("~/Images/Image1.gif"), "One", "Image 1");
    slides[1] = new AjaxControlToolkit.Slide(HttpContext.Current.Server.MapPath("~/Images/Image2.gif"), "Two", "Image 2");
    

    I only see Image2.gif. And the slideshow isn't "animated"...

    Thursday, September 4, 2014 12:58 PM
  • User-1136231507 posted

    Hi,

     I use this code to generate slideshow 

                List<Slide> slides = new List<Slide>();
                string path = HttpContext.Current.Server.MapPath("~/Images/SlideshowImages");
                if (path.EndsWith("\\"))
                {
                    path = path.Remove(path.Length - 1);
                }
                Uri pathUri = new Uri(path, UriKind.RelativeOrAbsolute);
                string[] files = Directory.GetFiles(path);
                foreach (string file in files)
                {
                    Uri filePathUri = new Uri(file, UriKind.RelativeOrAbsolute);
                    slides.Add(new Slide
                    {
                        Name = Path.GetFileNameWithoutExtension(file),
                        Description = Path.GetFileNameWithoutExtension(file) + " Description.",
                        ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString()
                    });
                }
                return slides.ToArray();

    with this code easily generate slide show with any images.

    my problem is here this code run when use

    string path = HttpContext.Current.Server.MapPath("~/Images/");

    but my slideshow images folder is in inside this folder images

    ("~/Images/SlideshowImages/");

    I want to load this address

    thanks

    Friday, September 5, 2014 3:23 AM
  • User1918509225 posted

    Hi gigidel,

    I have tested your code ,the problem is  here:

    gigidel

    ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString()

    When you set your path as "~/Images/SlideshowImages",You will just get the ImagePath of one image like below ,you can set a breakpoint and debug it

    SlideshowImages/xx.jpg

    While the image path should be :

    Images/SlideshowImages/xx.jpg

    So I suggest that you can try the code below:

    new Slide
               {
                   Name = Path.GetFileNameWithoutExtension(file),
                   Description = Path.GetFileNameWithoutExtension(file) + " Description.",
                   ImagePath = "Images/"+pathUri.MakeRelativeUri(filePathUri).ToString()
               };

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 9, 2014 4:35 AM