简体   繁体   中英

How do I save image URL in database?

I have tried to save an image URL in a SQL database but path.compain() does not work and just the file name is saved in the database instead of all the path. Can anyone help me?

if (Request.Files.Count > 0)
{
    HttpPostedFileBase file3 = Request.Files[2];
    if (Request.Files.Count > 2 &&
        file3.ContentLength > 0 &&
        (file3.ContentType.ToUpper().Contains("JPEG") ||
        file3.ContentType.ToUpper().Contains("PNG") ||
        file3.ContentType.ToUpper().Contains("GIF")))
    {
        string fileName = Path.Combine(Server.MapPath("~/advertimages/cars/mercedes"), Path.GetFileName(file3.FileName));
        file1.SaveAs(fileName);
        modelcar.Image3Url = fileName;
    }
}

You can create a new FileInfo object from fileName

FileInfo fi = new FileInfo(fileName);

And then use fi.FullName();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM