Dee*_*ons 8 .net c# asp.net ajax file-io
我使用的是.NET 2.0,Linq是不可能的.我想在不知道文件扩展名的情况下检查文件是否存在于目录中.
我只需要完成这个逻辑.
1.使用搜索模式提供的字符串文件名在目录中存在检查文件,省略文件的扩展名
2.获取文件(如果存在)和Databind提供Download links.如果文件不存在,则开始上传文件.
更新:
Directory.GetFiles()和DirectoryInfo.GetFiles()确实解决了其中我检查文件的存在的部分.至于有关FileInfo对象的性能,这些只是我对数据绑定的要求的解决方案,以提供下载链接
Ken*_*ent 20
DirectoryInfo root = new DirectoryInfo("your_directory_path");
FileInfo[] listfiles = root.GetFiles("dummy.*");
if (listfiles.Length > 0)
{
//File exists
foreach (FileInfo file in listfiles)
{
//Get Filename and link download here
}
}
else
{
//File does not exist
//Upload
}
Run Code Online (Sandbox Code Playgroud)
希望这有效
要查看是否存在具有该名称的文件,您不能只使用..
但是,Directory.GetFiles已经包含完整路径
string [] files = Directory.GetFiles(Path,"name*");
bool exists = files.Length > 0;
if ( exists)
{
//Get file info - assuming only one file here..
FileInfo fi = new FileInfo(files[0]);
//Or loop through all files
foreach (string s in files)
{
FileInfo fi = new FileInfo(s);
//Do something with fileinfo
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17708 次 |
| 最近记录: |