通过文件名获取文件扩展名 [英] Get File Extension by Filename

查看:90
本文介绍了通过文件名获取文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...我想问个问题,

如何通过文件名获取文件扩展名?

我的代码如下:

hi... i want to ask something,,

how to get file extension by filename?

i have code below:

string id = "34";
string ext = System.IO.Path.GetExtension(Server.MapPath(Request.ApplicationPath + @"\Images\") + id);
Response.Write(ext);



请修改我的代码...



revise my code please...

推荐答案



我尝试了一些代码来让您使用文件名获取文件扩展名

Hi,

I tried some code for you to get file extension by using filename

DirectoryInfo dinfo = new DirectoryInfo(Server.MapPath("~/Images"));
           FileInfo[] finfo = dinfo.GetFiles("winter.*");
           int l=finfo.Length;
           string ext=Path.GetExtension(finfo[0].FullName);



在这里,您必须传递文件名而不是"winter"

然后将文件信息存储在finfo数组中.

这样我们就可以得到该文件扩展名

我希望你能理解我说的话

最好的



Here you''ve to pass your file name instead of "winter"

Then The file information stored in finfo array.

So we can get that file extension

I hope you understood What I said

All the Best


您的文件名"... \ Images \ 34"没有扩展名.
Your file name "...\Images\34" has no extension.


要获取文件扩展名,
To get File Extension,
Response.Write(Path.GetExtension(@"F:\Articles\ValidationControls\ValidationControls.zip"));



请参阅下面的链接



Refer below link

http://codes.codedigest.com/CodeDigest/68-Get-File-Extension--File-Name--File-Name-without-Extension-from-Path-in-C--and-ASP-Net.aspx[^]


这篇关于通过文件名获取文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆