学习笔记(创建文件夹)
来源:互联网 发布:amd超频软件 编辑:程序博客网 时间:2024/04/28 22:13
在做一个自动生成静态页面的时候遇到生成文件和文件夹的问题。
现在总结下来,以备后插。以下是测试页面。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class Manager_Major_TestWjj : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
}
protected void dddd_Click(object sender, EventArgs e)
...{
string path;
//得到虚拟目录的物理路径。
path = HttpContext.Current.Server.MapPath("../../Template/ddd/");
try
...{
if (System.IO.Directory.Exists(path))
...{
Response.Write("目录已经存在!");
}
else
...{
System.IO.Directory.CreateDirectory(path);
Response.Write("创建成功!!");
}
}
catch (System.Exception err)
...{
throw err;
}
Response.Write(path);
}
}
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class Manager_Major_TestWjj : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
}
protected void dddd_Click(object sender, EventArgs e)
...{
string path;
//得到虚拟目录的物理路径。
path = HttpContext.Current.Server.MapPath("../../Template/ddd/");
try
...{
if (System.IO.Directory.Exists(path))
...{
Response.Write("目录已经存在!");
}
else
...{
System.IO.Directory.CreateDirectory(path);
Response.Write("创建成功!!");
}
}
catch (System.Exception err)
...{
throw err;
}
Response.Write(path);
}
}
页面文件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestWjj.aspx.cs" Inherits="Manager_Major_TestWjj" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="dddd" Text="dddd" runat="server" OnClick="dddd_Click" />
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="dddd" Text="dddd" runat="server" OnClick="dddd_Click" />
</div>
</form>
</body>
</html>
这个例子中,HttpContext.Current.Server.MapPath("../../Template/ddd/");要根据实际情况来改写。
通过测试,可以生成文件加,如果有的话,就不再create。
ok,就这吧。
- 学习笔记(创建文件夹)
- 学习笔记 - java创建文件夹
- Android学习笔记五:文件夹创建
- (Ios 学习笔记) 文件夹操作
- Java学习笔记七(文件夹操作)
- (学习笔记) 数组创建
- 学习Linux(创建、删除文件和文件夹命令)
- 学习Linux二(创建、删除文件和文件夹命令)
- 学习Linux二(创建、删除文件和文件夹命令)
- 学习Linux二(创建、删除文件和文件夹命令)
- 学习Linux二(创建、删除文件和文件夹命令)
- 学习Linux二(创建、删除文件和文件夹命令)
- 学习Linux二(创建、删除文件和文件夹命令)
- 学习Linux二(创建、删除文件和文件夹命令)
- Linux文件夹权限 学习笔记
- Linux学习笔记--共享文件夹
- Linux文件夹权限 学习笔记
- C#复制文件和文件夹(学习笔记)
- 淡化背景
- 尝试用语句备份sql数据库
- 2007年9月8日
- 精通CSS--高级WEB标准解决方案(第一章)-------读书笔记
- 配置Microsoft Visual SourceSafe 2005的Internet访问
- 学习笔记(创建文件夹)
- .net中前台javascript与后台c#函数相互调用
- windows 2003服务器备份和恢复的经验总结
- 关于多个textbox的leave,changed事件
- 用证书实现windows 2003下IIS的SSL安全通信
- Indent,Outdent和hanging indent
- Executive MBA Programs
- Windows终端服务SSL认证配置指南
- 停止错误