简体   繁体   English

如何将图片网址保存在数据库中?

[英]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. 我试图将图像URL保存在SQL数据库中,但是path.compain()无法正常工作,仅文件名保存在数据库中,而不是所有路径中。 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 您可以从fileName创建一个新的FileInfo对象

FileInfo fi = new FileInfo(fileName);

And then use fi.FullName(); 然后使用fi.FullName();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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