C#文件重命名的处理方法 (转载)
2015-06-20 12:38
411 查看
string newName = txtFileName.Text.Trim();
string oldName = Request.QueryString["fileName"];
RSPSession sessionRsp = (RSPSession)Session["RSPSetting"];
string basePath = sessionRsp.BaseFolder;
string currPath = basePath + sessionRsp.CurrentRelFolder;
string sourceFileName = "";
if (!string.IsNullOrEmpty(newName))
{
string currFilePath = Path.Combine(currPath, oldName);
sourceFileName = currFilePath;
string extension = sourceFileName.Substring(sourceFileName.LastIndexOf('.'),
sourceFileName.Length - sourceFileName.LastIndexOf('.'));
if (File.Exists(Path.Combine(currPath, newName+extension)))
{
Response.Write("文件夹中存在此名称文件,请更改文件名。");
}
else
{
currFilePath = Path.Combine(currPath, newName);
FileInfo fileInfo = new FileInfo(sourceFileName);
fileInfo.MoveTo(currFilePath + extension);
Response.Write("<script>self.parent.tb_remove();</script>");
}
}
string oldName = Request.QueryString["fileName"];
RSPSession sessionRsp = (RSPSession)Session["RSPSetting"];
string basePath = sessionRsp.BaseFolder;
string currPath = basePath + sessionRsp.CurrentRelFolder;
string sourceFileName = "";
if (!string.IsNullOrEmpty(newName))
{
string currFilePath = Path.Combine(currPath, oldName);
sourceFileName = currFilePath;
string extension = sourceFileName.Substring(sourceFileName.LastIndexOf('.'),
sourceFileName.Length - sourceFileName.LastIndexOf('.'));
if (File.Exists(Path.Combine(currPath, newName+extension)))
{
Response.Write("文件夹中存在此名称文件,请更改文件名。");
}
else
{
currFilePath = Path.Combine(currPath, newName);
FileInfo fileInfo = new FileInfo(sourceFileName);
fileInfo.MoveTo(currFilePath + extension);
Response.Write("<script>self.parent.tb_remove();</script>");
}
}
相关文章推荐
- C#的装箱拆箱操作详解
- C#中TextBox实现输入提示功能的方法
- c#中datagridview处理非绑定列的方法
- 关于VS2005中C#代码用F12转到定义时,总是显示从元数据的问题
- C#语言实现对网页图片的随机抓取。基础办法,但还有一点小问题,欢迎大家指正
- C# Monitor
- C# 编写Windows Service(windows服务程序)
- C# Interop CorelDRAW
- [变]C#谜题(1-10)表达式篇
- C#数据触发器
- 关于数列1,1,2,3,5,8,13,21,34..用C#语言编程求第n项为?
- C#自定义控件开发
- C#数据绑定(续)
- 记录一个c#计算器程序
- C# 读取xml文件
- C#自定义控件
- C#面向对象第六天总结
- DataGridView 单元格中内容为链接,字体为蓝色
- C#EXCEL操作大全
- C# 读取与修改配置文件