https://www.wendangku.net/doc/d3360578.html,检查文件是否存在
https://www.wendangku.net/doc/d3360578.html, 2008-12-26 来源: 中国建站 我要投递新闻
.本教程表明我们如何能够验证文件是否存在,或没有收到执行代码表示,有关文件。 C #中的版本。
检查是否存在一个文件之前执行某些行代码可以是非常有益的。它可以防止错误信息所造成的试图操纵的文件不存在,例如。使用System.IO ,我们可以查看是否存在一个文件在某一目录提供方便。
using System.IO;
服务器智力助攻,各种规模的企业与他们主办的需求,提供完全配置的服务器解决方案加上主动服务器管理服务。服务器智力专门提供完整的互联网服务器解决方案,随时准备支持他们的专家三百六十五分之二十四积极支持团队。
ASPX页面看起来就像这样:
页符进行https://www.wendangku.net/doc/d3360578.html,上传大文件出现网页无法显示https://www.wendangku.net/doc/d3360578.html,中Get和Post的用法配置https://www.wendangku.net/doc/d3360578.html,应用程序https://www.wendangku.net/doc/d3360578.html,页面框架概念浅析https://www.wendangku.net/doc/d3360578.html,的https://www.wendangku.net/doc/d3360578.html,表单身份验证的实现方法https://www.wendangku.net/doc/d3360578.html,安装部署问题总结https://www.wendangku.net/doc/d3360578.html,(VB)应用之图片增加水印文字https://www.wendangku.net/doc/d3360578.html,的生成eurl.axd Http异常错https://www.wendangku.net/doc/d3360578.html,2.0的新特性概述在https://www.wendangku.net/doc/d3360578.html,中备份恢复Sql Server数据. 用户名: 密码: 匿名? 注册
评论总数:2 条 [ 查看全部 ] 网友评论
==============================================================================
.net 文件夹是否存在的判断 protected void Button1_Click(object sender, EventArgs e)
{
string path = "";
string physicsPath = Server.MapPath(Request.ApplicationPath); //将当前虚拟根路径转为实际物理路径
string toFindDirectoryName = "ss"; //要查找的文件夹名
FindDirectory(physicsPath + "\\", toFindDirectoryName, out path);//用递归的方式去查找文件夹
if (!string.IsNullOrEmpty(path)) //如果存在,返回该文件夹所在的物理路径
{
//将该物理路径转为虚拟路径
Response.Write(GetVirtualPath(path, Request.ApplicationPath));
}
else
{
//没有找到路径,创建新文件夹
Directory.CreateDirectory(physicsPath + "\\" + toFindDirectoryName);
}
}
///
/// 将物理路径转为虚拟路径
///
/// 物理路径
/// 虚拟根路径
///
private string GetVirtualPath(string physicsPath, string virtualRootPath)
{
int index = physicsPath.IndexOf(virtualRootPath.Substring(1));
return "/" + physicsPath.Substring(index).Replace("\\", "/");
}
///
/// 在指定目录下递归查找子文件夹
///
/// 根文件夹路径
/// 要查找的文件夹名
private void FindDirectory(string bootPath, string directoryName, out string filePath)
{
//在指定目录下递归查找子文件夹
DirectoryInfo dir = new DirectoryInfo(bootPath);
filePath = "";
try
{
foreach (DirectoryInfo d in dir.GetDirectories()) //查找子文件夹
{
if (https://www.wendangku.net/doc/d3360578.html, == directoryName) //找到,返回文件夹路径
{
filePath = d.FullName;
break;
}
FindDirectory(bootPath + https://www.wendangku.net/doc/d3360578.html, + "\\", directoryName, out filePath); //否则继续查找
}
}
catch (Exception e)
{
Response.Write(e.Message);
}
}
=====================================================================
在保
存的时候,如果想要弹出脚本让用户操作,是不可能继续进行保存操作的.
所以,在上传之后,你可检查文件名,如果同名,则先以随机名称保存该上传文件,并弹出对话框问用户.
this.response.write( " ");
this.response.end();