strImagePath = "~/指定的目录/" + strOldName; fupImage.SaveAs(strImagePath); } else { //Label1.Text = "图片上传失败,不是正确的图片文件!"; } } }//验证文件后缀名 public static bool CheckFileType(string strExt) { switch (strExt.ToLower()) { case ".gif": return true; case ".png": return true; case ".jpg": return true; case ".jpeg": return true; default: return false; } }
请问这里面的Path.GetExtension(strOldName);是什么意思呢?
Path.GetExtension(strOldName) 获得文件的扩展名
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0103: 当前上下文中不存在名称“Path”
<asp:FileUpload ID="fupImage" runat="server" CssClass="FileUp" />
<asp:RegularExpressionValidator ID="revUploadImages" ControlToValidate="fupImage" Text="请选择正确的图片文件" runat="server" ValidationExpression='[A-Za-z]\:\\[^\:\?\"\>\<\*]*\.([Gg][Ii][Ff]|[Jj][Pp][Gg]|[Bb][Mm][Pp])' ></asp:RegularExpressionValidator><asp:Button ID="btnAddImage" runat="server" Text="提 交" OnClick="btnAddImage_Click" />protected void btnAddImage_Click(object sender, EventArgs e)
{ if (fupImage.HasFile)
{
string strOldName = fupImage.FileName;
string strExt = Path.GetExtension(strOldName);
if (CheckFileType(strExt))
{
strImagePath = "~/指定的目录/" + strOldName;
fupImage.SaveAs(strImagePath); }
else
{
//Label1.Text = "图片上传失败,不是正确的图片文件!";
}
}
}//验证文件后缀名
public static bool CheckFileType(string strExt)
{
switch (strExt.ToLower())
{
case ".gif":
return true;
case ".png":
return true;
case ".jpg":
return true;
case ".jpeg":
return true;
default:
return false;
}
}
请问这里面的Path.GetExtension(strOldName);是什么意思呢?
获得文件的扩展名
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0103: 当前上下文中不存在名称“Path”