using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web;
using Whir.Framework.Extension;
namespace Whir.Framework.Helper
{
/// <summary>
/// 辅助类
/// </summary>
public class FileHelper
{
/// <summary>
/// 生成树形文件Html
/// </summary>
/// <param name="builder">用于存放拼接的Html,由于是递归拼接,调用方法时,传入空的StringBuilder即可</param>
/// <param name="path">要显示的服务器端文件夹路径(物理路径)</param>
/// <param name="replacePath">要替换掉的路径部分</param>
/// <returns></returns>
public static string GetGuideTree(StringBuilder builder, string path, string replacePath)
{
var currentDir = new DirectoryInfo(path);
DirectoryInfo[] subDirs = currentDir.GetDirectories();
if (subDirs.Length > 0)
{
builder.AppendFormat("<li><span class='folder' path='{0}'>{1}</span>" + Environment.NewLine,
currentDir.FullName.Replace(replacePath, ""), currentDir.Name);
builder.Append(" <ul>" + Environment.NewLine);
foreach (DirectoryInfo dir in subDirs)
{
GetGuideTree(builder, dir.FullName, replacePath);
}
#region 文件夹下文件
FileInfo[] files = currentDir.GetFiles();
if (files.Length > 0)
{
foreach (FileInfo file in files)
{
string previewUrl = file.FullName.IsImage()
? GetFileWebUrl(
file.FullName.Replace(HttpContext.Current.Server.MapPath("~/"), ""))
: string.Empty;
builder.AppendFormat(
"<li><span class='file' name='{0}' img='{1}' path='{2}'>{0}</span>" + Environment.NewLine,
&
文章分类
C#文件处理辅助类
分类:C#
发布:2015-07-26
来源:root
浏览:7421 次
如果觉得文章对您有帮助,您可以对我进行打赏 ¥1.95 元(金额随机^_^,每次刷新金额不同)。
请使用支付宝扫码支付
留言评论
*称 呼: | |
*联系方式: | 方便与您取得联系,推荐使用邮箱。 |
*内 容: | |
已有评论
暂无数据 |