Photo saved in Directory does not appear in Solution Explorer

2

After much pain, you can save the photo in the directory and not the bank. But she does not appear in my folder in my Solution Explorer, but when I open the photo through the windows explore it appears.

Because of this, the photo is not displayed when editing the record. How should I proceed?

Code that saves Photo:

int n = 0;
        Boolean valido = true;
        foreach (var item in ModelState.Values)
        {
            n++;
            if ((item.Value == null) && (n < 12))
            {
                valido = false;
            }
        }
        if (valido == true)
        {
            var file = Request.Files[0];
            var fileName = Path.GetFileName(file.FileName);
            var pat = Path.Combine(Server.MapPath("~/Fotos/"), fileName);
            file.SaveAs(pat);

            frota.URLFoto = fileName;
            db.Frotas.Add(frota);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

Razor HTML:

@{ var foto = Model.URLFoto;
   var pat = Path.Combine("~/Fotos/", foto); }

<img src="@pat" width="172" height="92" style="border: 1px solid black; width: 172px; height: 92px;" />
    
asked by anonymous 08.06.2015 / 18:26

2 answers

2

Both normal and optimal is that the photo does not appear in Solution Explorer, because the files that appear in Solution Explorer are project files. Incorrect would be if photos that do not belong to the project appeared in the project.

Now, if the photo does not appear when editing the record, it means that the procedure for loading this photo is incorrect. Edit your question by placing the image upload code so I can provide a more targeted and correct answer to your problem.

EDIT

Server.MapPath was also missing when uploading the photo:

@{ var foto = Model.URLFoto;
   var pat = Path.Combine(Server.MapPath("~/Fotos/"), foto); }

<img src="@pat" width="172" height="92" style="border: 1px solid black; width: 172px; height: 92px;" />
    
08.06.2015 / 18:35
1

To write an image to the database, first define the table that will receive the data, I suggest a table with only the image (which will be more convenient when not loading the image), and one or more fields to indicate to whom belongs.

The field that will receive the image must be byte type for MSSQL, I do not know what your BD will then have to search a bit, at the place of loading the photo, transform it into bytes and send it to the database, saving with the data

Transforming a file into a byte

byte[] arquivoByte = new byte[FileUpload.PostedFile.InputStream.Length+1];
FileUpload.PostedFile.InputStream.Read(arquivoByte,0,arquivoByte.Length);
    
09.06.2015 / 16:27