文档库 最新最全的文档下载
当前位置:文档库 › net 文件夹是否存在的判断

net 文件夹是否存在的判断


https://www.wendangku.net/doc/d3360578.html,检查文件是否存在
https://www.wendangku.net/doc/d3360578.html, 2008-12-26 来源: 中国建站 我要投递新闻

.本教程表明我们如何能够验证文件是否存在,或没有收到执行代码表示,有关文件。 C #中的版本。


检查是否存在一个文件之前执行某些行代码可以是非常有益的。它可以防止错误信息所造成的试图操纵的文件不存在,例如。使用System.IO ,我们可以查看是否存在一个文件在某一目录提供方便。

using System.IO;

服务器智力助攻,各种规模的企业与他们主办的需求,提供完全配置的服务器解决方案加上主动服务器管理服务。服务器智力专门提供完整的互联网服务器解决方案,随时准备支持他们的专家三百六十五分之二十四积极支持团队。

ASPX页面看起来就像这样:



Search for a file (inc. extension to see if it exists in the media directory.

Hint: try delete.gif











我们迁移的网站服务器智力的一个周末和安装是如此顺利,我们正在启动和运行了。他们帮助我们的一切,我们需要做的所有的应用程序。随着服务器智力的帮助下,我们能够避免任何麻烦

逻辑检查,看看是否有任何文字的文本时,按下按钮,首先。如果有文本目前,它会检查,看看是否这个文本文件是一个在媒体上的文件夹中。用户将得到通知,如果存在一个文件或没有。
代码隐藏看起来就像这样:


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
doesFileExist(TextBox1.Text);
}

public void doesFileExist(string searchString)
{
if (TextBox1.Text != "")
{
string imageFolder;
imageFolder = Server.MapPath("/media/") + searchString.ToString();
if (File.Exists(imageFolder))
{
Label1.Text = "File " + searchString + " does exist in '/media/' folder.";
}
else
{
Label1.Text = "File " + searchString + " does not exist in '/media/' folder.";
}
}
else
Label1.Text = "Please enter some text.";
}
}








1顶一下

推荐给好友 收藏到本地 收藏到百度 收藏到QQ书签 Google书签添加到其它收藏:
.上一篇:https://www.wendangku.net/doc/d3360578.html,上传与删除文件代码 下一篇:https://www.wendangku.net/doc/d3360578.html, Web控制:image 控件与imageButton控件教程

相关文章列表https://www.wendangku.net/doc/d3360578.html,使用FCKEditor的分

页符进行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();

相关文档
相关文档 最新文档