gpt4 book ai didi

c# - Path.GetExtension 返回 ""

转载 作者:太空宇宙 更新时间:2023-11-03 13:49:39 25 4
gpt4 key购买 nike

我正在尝试将图像路径上传到数据库并将文件保存在图像文件夹中。除了 getExtension 部分(.jpg、.gif 等...)之外,此方法正常工作,Path.GetExtension 方法始终返回 null (""),我不知道为什么。

您可以在下面找到使用的代码:

string imagesFolderPath = Server.MapPath("//Images");
imagesFolderPath += "//";

string newImageName = addProduct.id.ToString();
string extension = Path.GetExtension(fileUpload.FileName.ToString());

addProduct.imagePath = "Images//" + newImageName + extension;

fileUpload.SaveAs(imagesFolderPath + newImageName);

最佳答案

根据 MSDN Documentation :

The extension of the specified path (including the period "."), or null, or String.Empty. If path is null, GetExtension returns null. If path does not have extension information, GetExtension returns String.Empty.

获得空字符串 "" 的唯一方法是not 的路径为 null的路径有扩展名。

你得到一个空字符串,因为路径没有扩展名。

关于c# - Path.GetExtension 返回 "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14054483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com