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;
using System.Text;/// <summary>
/// Cls_Fso 的文件/文件夹操作说明
/// </summary>
public class Cls_Fso
{
    /// <summary>
    /// 检测文件夹/文件是否存在
    /// </summary>
    /// <param name="Path">相对路经</param>
    /// <param name="typeid">(0文件夹,1文件)</param>
    /// <returns></returns>
    public static bool FsoIsTrue(string Path, int typeid)
    {
        switch (typeid)
        {
            case 0:     //文件夹
                if (!Directory.Exists(HttpContext.Current.Server.MapPath(Path)))
                {
                    return false;
                }
                else
                {
                    return true;
                }
            case 1:     //文件
                if (!File.Exists(HttpContext.Current.Server.MapPath(Path)))
                {
                    return false;
                }
                else
                {
                    return true;
                }
        }
        return false;
    }
    /// <summary>
    /// 创建文件夹/文件
    /// </summary>
    /// <param name="Path">相对路经</param>
    /// <param name="typeid">(0文件夹,1文件)</param>
    public static void FsoCreate(string Path, int typeid)
    {
        switch (typeid)
        {
            case 0:     //创建文件夹
                if (!Directory.Exists(HttpContext.Current.Server.MapPath(Path)))
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath(Path));
                }
                else
                {
                    Cls_Common.ErrView("·您要创建的【文件夹】已经存在,请更换名称!");
                }
                break;
            case 1:     //创建文件
                if (!File.Exists(HttpContext.Current.Server.MapPath(Path)))
                {
                    File.Create(HttpContext.Current.Server.MapPath(Path));
                }
                else
                {
                    Cls_Common.ErrView("·您要创建的〖文件〗已经存在,请更换名称!");
                }
                break;
        }
    }
    /// <summary>
    /// 删除文件夹/文件
    /// </summary>
    /// <param name="Path">相对路经</param>
    /// <param name="typeid">(0文件夹,1文件)</param>
    public static void FsoDel(string Path, int typeid)
    {
        switch (typeid)
        {
            case 0:     //删除文件夹
                if (Directory.Exists(HttpContext.Current.Server.MapPath(Path)))
                {
                    if (Directory.GetFiles(HttpContext.Current.Server.MapPath(Path)).Length > 0)
                    {
                        Cls_Common.ErrView("·此文件夹不为空,请先删除里面的文件/文件夹");
                    }
                    else
                    {
                        Directory.Delete(HttpContext.Current.Server.MapPath(Path));
                    }
                }
                else
                {
                    Cls_Common.ErrView("·您要删除的【文件夹】不存在");
                }
                break;
            case 1:     //删除文件
                if (File.Exists(HttpContext.Current.Server.MapPath(Path)))
                {
                    File.Delete(HttpContext.Current.Server.MapPath(Path));
                }
                else
                {
                    Cls_Common.ErrView("·您要删除的〖文件〗不存在");
                }
                break;
        }
    }
    /// <summary>
    /// 复制文件夹/文件
    /// </summary>
    /// <param name="oldPath">原路经</param>
    /// <param name="newPath">新路经</param>
    /// <param name="typeid">(0文件夹,1文件)</param>
    public static void FsoCopy(string oldPath, string newPath, int typeid)
    {
        switch (typeid)
        {
            case 0:     //复制文件夹
                Cls_Common.ErrView("·暂不提供【文件夹】复制功能!");
                break;
            case 1:     //复制文件
                if (File.Exists(HttpContext.Current.Server.MapPath(oldPath)))
                {
                    if (File.Exists(HttpContext.Current.Server.MapPath(newPath)))
                    {
                        Cls_Common.ErrView("·您要复制的〖文件〗已经存在,请更换名称!");
                    }
                    else
                    {
                        File.Copy(HttpContext.Current.Server.MapPath(oldPath), HttpContext.Current.Server.MapPath(newPath));
                    }
                }
                else
                {
                    Cls_Common.ErrView("·您要复制的〖文件〗不存在");
                }
                break;
        }
    }
    /// <summary>
    /// 生成内容文件
    /// </summary>
    /// <param name="Path">相对路经</param>
    /// <param name="Info">内容</param>
    public static void FsoCreateInfo(string Path,string Info)
    {
        File.WriteAllText(HttpContext.Current.Server.MapPath(Path), Info, Encoding.Default);
    }
}
欢迎大家访问我的网站:http://www.bjxtwl.com

解决方案 »

  1.   

    造轮子?System.IO里有这些方法吧
      

  2.   


      /// <summary>
        /// 样式标题
        /// </summary>
        /// <param name="Title">标题文字</param>
        /// <param name="TColor">颜色</param>
        /// <param name="CType">样式</param>
        /// <returns></returns>
        public static string TitleStyle(string Title, string TColor,int CType)
        {
            string Tcss = "";
            switch (CType)
            {
                case 1: //粗体
                    Tcss = "font-weight: bold;";
                    break;
                case 2: //斜体
                    Tcss = "font-style: italic;";
                    break;
                case 3: //粗+斜
                    Tcss = "font-style: italic;font-weight: bold;";
                    break;
            }        if (Tcss != "")
            {
                if (String.IsNullOrEmpty(TColor) == false)
                {
                    return "<span style=\"Color:" + TColor + ";" + Tcss + "\">" + Title + "</span>";
                }
                else
                {
                    return "<span style=\"" + Tcss + "\">" + Title + "</span>"; 
                }
            }
            else
            {
                if (String.IsNullOrEmpty(TColor) == false)
                {
                    return "<span style=\"Color:" + TColor + "\">" + Title + "</span>";
                }
                else
                {
                    return Title;
                }
            }
        }
      

  3.   


        /// <summary>
        /// 获取URL源码
        /// </summary>
        /// <param name="url">远程URL</param>
        /// <returns></returns>
        public static string GetUrlCode(string url)
        {
            if (string.IsNullOrEmpty(url)==false)
            {
                WebClient WClient = new WebClient();
                Stream SReam = WClient.OpenRead(url);
                StreamReader Sread = new StreamReader(SReam, Encoding.Default);
                string Info = Sread.ReadToEnd();
                if (Info != "")
                {
                    return Info;
                }
            }
            return null;
        }
      

  4.   


        /// <summary>
        /// 错误提示
        /// </summary>
        /// <param name="Str"></param>
        public static void ErrView(string Str)
        {
            string Tstr;
            Tstr = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\r\n";
            Tstr = Tstr + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n";
            Tstr = Tstr + "<head>\r\n";
            Tstr = Tstr + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />\r\n";
            Tstr = Tstr + "<title>友情提示!</title>\r\n";
            Tstr = Tstr + "<style type=text/css>td{font-size:12px;line-height: 20px;}</style>\r\n";
            Tstr = Tstr + "<table align=center border=1 cellpadding=5 cellspacing=0 width='350' bordercolordark=#FFFFFF>\r\n";
            Tstr = Tstr + "<tr><td><b>友情提示:</b></td></tr>\r\n";
            Tstr = Tstr + "<tr>\r\n";
            Tstr = Tstr + "<td valign=top>\r\n";
            Tstr = Tstr + "<table width='90%' border=0 cellspacing=5 cellpadding=0 align=center>\r\n";
            Tstr = Tstr + "<tr><td><span style=color:red>" + Str + "<br></span><br />\r\n";
            Tstr = Tstr + "·<a href=# onclick=javascript:history.back()>返回上一页</a><br />\r\n";
            Tstr = Tstr + "·<a href=# onclick=javascript:window.parent.close()>关闭当前页</a></td>\r\n";
            Tstr = Tstr + "</tr></table></td></tr><tr>\r\n";
            Tstr = Tstr + "<td align=center>\r\n";
            Tstr = Tstr + "<a href='http://www.bjxtwl.com/' target=_blank style='color:#CCCCCC'>Powered By bjxtwl.Com </a></td>\r\n";
            Tstr = Tstr + "</tr></table>\r\n";
            HttpContext.Current.Response.Write(Tstr);
            HttpContext.Current.Response.End();
        }