mardi 5 mai 2015

server.mappath indicate the name of controller

I want to add an image and I concat the server directory with the directory where I want to save the file. But the name of the controller is added in the complete path that I do not want.

                string newFile = "\\Photoclient\\photo\\" + System.IO.Path.GetFileName(Tretouche.fichierphoto.FileName);
                // getting a valid server path to save
                string cheminfichier = Server.MapPath("..") + newFile;
                if (Tretouche.fichierphoto.FileName != String.Empty)
                {
                    Tretouche.fichierphoto.SaveAs(cheminfichier);
                    Tretouche.SRCphoto = "\\Photoclient\\photo\\" + System.IO.Path.GetFileName(Tretouche.fichierphoto.FileName);
                }

there is an error when save file because cheminfichier contains the name of the controller in the path. Tks for help

Aucun commentaire:

Enregistrer un commentaire