Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public partial class WebForm2 : System.Web.UI.Page
    {
        [WebMethod]
        [ScriptMethod]
        
        public static Slide[] GetImages()
        {
            List<slide> slides = new List<slide>();
            string path = HttpContext.Current.Server.MapPath("~/Images/Images/");
            if (path.EndsWith("\\"))
            {
                path = path.Remove(path.Length - 1);
            }
            Uri pathUri = new Uri(path, UriKind.Absolute);
            string[] files = Directory.GetFiles(path);
            foreach (string file in files)
            {
                Uri filePathUri = new Uri(file, UriKind.Absolute);
                slides.Add(new Slide
                {
                    Name = Path.GetFileNameWithoutExtension(file),
                    Description = Path.GetFileNameWithoutExtension(file) + " Description.",
                    ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString()
                });
            }
            return slides.ToArray();
        }
    }
Posted
Updated 7-Oct-15 20:38pm
v2
Comments
Krunal Rohit 8-Oct-15 2:40am    
Try putting breakpoint & debug it.

-KR

1 solution

You are trying to access null object, because of that only you are getting null reference exception. I request you to debug the code and check which line you got that error and then check the value of that, for sure it's showing null value. Check the null condition before of that line, issue has been resolved.
 
Share this answer
 

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