Problem z utworzeniem katalogu

0

Witam
Chciałem posegregować tworzone zdjęcia ze w katalogi, mianowicie chodzi mi by przy tworzeniu sprawdzało czy katalog o nazwie dzisiejsza data (np 2018.08.13) istnieje jeśli tak to zapisuje do niego utworzone zdjęcie, a jeśli nie to tworzy ten katalog a następnie zapisuje do niego zdjęcie. Mam następujący kod

public ActionResult Capture()
{

        DateTime dt = DateTime.Now;
        string catalogName = @"/Images/WebImages/" + dt.ToString("MM.dd.yyyy")+"/";
      
       if (Directory.Exists(catalogName) )
        {
           

            var stream = Request.InputStream;
            string dump;

            var userId = User.Identity.GetUserId();

            var user = DbContext.Users
                .Include(x => x.Photos)
                .FirstOrDefault(x => x.Id.ToString() == userId);

            using (var reader = new StreamReader(stream))
            {
                dump = reader.ReadToEnd();
                
                DateTime nm = DateTime.Now;

                string date = nm.ToString("yyyy.MM.dd hh.mm");

                var path = Server.MapPath("~"+catalogName + date + ".jpg");

                System.IO.File.WriteAllBytes(path, String_To_Bytes2(dump));

                ViewData["path"] = date + ".jpg";

                Session["val"] = date + ".jpg";

                if (user != null)
                {
                    var photo = new Photo
                    {
                        Id = Guid.NewGuid(),
                        Bytes = dump,
                        ImageType = "image/jpeg"
                    };

                    user.Photos.Add(photo);
                    DbContext.SaveChanges();

                    ViewData["path"] = photo.Id.ToString();
                }
            }
            Off();
        }
        else
        {
            string folderName = @"/Images/WebImages/" ;
            string subFolder = dt.ToString("MM.dd.yyyy") ;
            string pathString = System.IO.Path.Combine(folderName, subFolder);
            Directory.CreateDirectory(pathString);
            var stream = Request.InputStream;
            string dump;

            var userId = User.Identity.GetUserId();

            var user = DbContext.Users
                .Include(x => x.Photos)
                .FirstOrDefault(x => x.Id.ToString() == userId);

            using (var reader = new StreamReader(stream))
            {
                dump = reader.ReadToEnd();

                DateTime nm = DateTime.Now;

                string date = nm.ToString("yyyy.MM.dd hh.mm");

                var path = Server.MapPath("~/"+ pathString+"/" +  date + ".jpg");
                System.IO.File.WriteAllBytes(path, String_To_Bytes2(dump));


                ViewData["path"] = date + ".jpg";
               
                Session["val"] = date + ".jpg";

                if (user != null)
                {
                    var photo = new Photo
                    {
                        Id = Guid.NewGuid(),
                        Bytes = dump,
                        ImageType = "image/jpeg"
                    };

                    user.Photos.Add(photo);
                    DbContext.SaveChanges();

                    ViewData["path"] = photo.Id.ToString();
                }
            }
            Off();
        }
        return View("Index");

    }       

jednakże nie tworzy mi katalogu i nie zapisuje zdjęcia. Aplikacja jest napisana MVC ASP.NET

0

use debugger luke

1 użytkowników online, w tym zalogowanych: 0, gości: 1