Ejemplo n.º 1
0
        public bool DelFile(string path)
        {
            try
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                    return(true);
                }
                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogHelp.WriteLog(ex.ToString());
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /*
         * 获得指定路径下所有文件名
         * StreamWriter sw  文件写入流
         * string path      文件路径
         * int indent       输出时的缩进量
         */
        public static List <FileOp> getFileName(string path, string type)
        {
            //string[] patharr= path.Split(new string[] { "FileOS" }, StringSplitOptions.None);
            string[] patharr = path.Split(new string[] { ConfigHelper.GetConfigString("path") }, StringSplitOptions.None);
            if (!Directory.Exists(path))
            {
                return(null);
            }
            DirectoryInfo root = new DirectoryInfo(path);
            List <FileOp> list = new List <FileOp>();
            string        ext  = "";

            switch (type)
            {
            case "1":
                ext = ".jpg,.png,.bmp";
                break;

            case "2":
                ext = ".doc,.docx.,.xls,.xlsx,.ppt,.pptx,.pdf.,.txt";
                break;

            default:
                ext = "";
                break;
            }
            foreach (FileInfo f in root.GetFiles())
            {
                if (ext.IndexOf(f.Extension.ToLower()) != -1)
                {
                    if (type == "1")
                    {
                        FileOp fo = new FileOp();
                        fo.Name    = "/" + ConfigHelper.GetConfigString("path") + "/" + path.Replace(AppDomain.CurrentDomain.BaseDirectory, "") + "/" + f.Name;
                        fo.FileUrl = patharr[1].Replace('\\', '/') + "/" + f.Name;
                        string thumbnailUrl = "d://thum//";
                        fo.FileThumbnailUrl = "data:image/jpeg;base64," + MakeThumbnail(f.FullName, thumbnailUrl + f.Name, 140, 140, "HW");
                        //fo.FileThumbnailUrl = thumbnailUrl;
                        //fo.FileUrl=  patharr[1].Replace('\\', '/') + "/" + f.Name;
                        fo.Size  = GetFileSize(f.Length);
                        fo.Ysize = f.Length;
                        fo.Date  = f.CreationTime.ToString("yyyy-MM-dd HH:mm");;
                        fo.Type  = f.Extension.Substring(1);
                        list.Add(fo);
                    }
                    else
                    {
                        LogHelp.WriteLog(path);
                        FileOp fo = new FileOp();
                        //fo.Name = "<a href='/"+ ConfigHelper.GetConfigString("path") + patharr[1].Replace('\\', '/') + "/" + f.Name + "'>" + f.Name + "</a>";
                        fo.Name    = "<a javascript:void(0)>" + f.Name + "</a>";
                        fo.FileUrl = patharr[1].Replace('\\', '/') + "/" + f.Name;
                        fo.Size    = GetFileSize(f.Length);
                        fo.Ysize   = f.Length;
                        fo.Date    = f.CreationTime.ToString("yyyy-MM-dd HH:mm");;
                        fo.Type    = f.Extension.Substring(1);
                        list.Add(fo);
                    }
                }
                if (ext == "")
                {
                    if (".jpg,.png,.bmp,.doc,.docx.,.xls,.xlsx,.ppt,.pptx,.pdf.,.txt".IndexOf(f.Extension.ToLower()) == -1)
                    {
                        FileOp fo = new FileOp();
                        //fo.Name = "<a href='/"+ ConfigHelper.GetConfigString("path") + patharr[1].Replace('\\', '/') + "/" + f.Name + "'>" + f.Name + "</a>";
                        fo.Name    = "<a javascript:void(0)>" + f.Name + "</a>";
                        fo.FileUrl = patharr[1].Replace('\\', '/') + "/" + f.Name;
                        fo.Size    = GetFileSize(f.Length);
                        fo.Ysize   = f.Length;
                        fo.Date    = f.CreationTime.ToString("yyyy-MM-dd HH:mm");;
                        fo.Type    = f.Extension.Substring(1);
                        list.Add(fo);
                    }
                }
            }
            return(list);
        }