Example #1
0
        [WebMethod]//更改文件名
        public bool UpdateFileName(string isbn, string ztm, string cdxh, string cdmc)
        {
            try
            {
                string          path     = XMLHelper.getAppSettingValue("FTP_Home") + "\\Download\\" + CDString.getFileName(isbn + ztm) + "\\" + cdxh.Replace(" ", "_");
                DirectoryInfo   dir      = new DirectoryInfo(path);
                List <FileInfo> listFile = dir.GetFiles().ToList();

                if (listFile.Count == 1)
                {
                    FileInfo file     = listFile.First();
                    string   new_path = XMLHelper.getAppSettingValue("FTP_Home") + "\\Download\\" + CDString.getFileName(isbn + ztm) + "\\" + cdxh;
                    if (!Directory.Exists(new_path))
                    {
                        Directory.CreateDirectory(new_path);
                    }
                    File.Move(file.FullName, new_path + "\\" + CDString.getFileName(cdmc) + file.Extension);
                    listFile = dir.GetFiles().ToList();
                    if (listFile.Count == 0)
                    {
                        Directory.Delete(path);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch { return(false); }
        }
Example #2
0
        public string MoveFile(string username, string ISBN, string ZTM, string CDXH)
        {
            try
            {
                string homedir = GetFtpUserHomeDir(username);//获取管理员目录
                homedir = homedir.Replace("\r", "");
                DirectoryInfo dir  = new DirectoryInfo(homedir);
                FileInfo      file = dir.GetFiles().FirstOrDefault(f => f.Name.Contains(ISBN) && f.Name.Contains(CDXH));//获取FTP服务器文件列表
                if (file != null)
                {
                    string path = XMLHelper.getAppSettingValue("FTP_Home") + "\\Download\\" + ISBN.Replace(" ", "_") +
                                  CDString.getFileName(ZTM) + "\\" + CDXH.Replace(" ", "_");

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    if (dir.Root.Name.Equals(file.Directory.Root.Name))
                    {
                        file.MoveTo(path + "\\" + CDString.getFileName(file.Name.Replace(ISBN.Replace(" ", "_") + "_" + CDXH.Replace(" ", "_"), "")).Replace("_", ""));
                        return("file_ok");
                    }
                    else
                    {
                        file.CopyTo(path + "\\" + CDString.getFileName(file.Name.Replace(ISBN.Replace(" ", "_") + "_" + CDXH.Replace(" ", "_"), "")).Replace("_", ""));
                        file.Delete();
                        return("file_ok");
                    }
                }
                else
                {
                    return("file_null");
                }
            }
            catch { return("file_error"); }
        }
Example #3
0
 [WebMethod]//移除文件
 public bool RemoveFile(string glytm, string isbn, string ztm, string cdxh)
 {
     try
     {
         Serv_UControl sc      = Serv_UControl.getServUContorl();
         string        homedir = sc.GetFtpUserHomeDir(glytm).Replace("\r", "");//获取管理员目录
         string        path    = XMLHelper.getAppSettingValue("FTP_Home") + "\\Download\\" + isbn.Replace(" ", "_") + CDString.getFileName(ztm) + "\\" + cdxh.Replace(" ", "_");
         DirectoryInfo dir     = new DirectoryInfo(path);
         FileInfo      file    = dir.GetFiles().FirstOrDefault();//获取FTP服务器文件列表
         if (file != null)
         {
             file.Delete();//删除文件
         }
         if (dir.GetFiles().Count() < 1)
         {
             dir.Delete();//删除目录
         }
         return(true);
     }
     catch { return(false); }
 }
Example #4
0
        [WebMethod]//文件长度
        public string GetFile(string glytm, string isbn, string ztm, string cdxh)
        {
            List <FileInfo> listFile = new List <FileInfo>();

            try
            {
                Serv_UControl sc      = Serv_UControl.getServUContorl();
                string        homedir = sc.GetFtpUserHomeDir(glytm).Replace("\r", "");//获取管理员目录
                string        path    = XMLHelper.getAppSettingValue("FTP_Home") + "\\Download\\" + CDString.getFileName(isbn + ztm) + "\\" + cdxh.Replace(" ", "_") + "\\";
                DirectoryInfo dir     = new DirectoryInfo(path);
                listFile = dir.GetFiles().ToList();//获取FTP服务器文件列表
                FileInfo file = listFile.FirstOrDefault();
                return(file.Length + "," + file.Extension);
            }
            catch { return(null); }
        }
Example #5
0
        [WebMethod]//获取文件名
        public string GetFileName(string isbn, string ztm, string cdxh)
        {
            try
            {
                string        path = XMLHelper.getAppSettingValue("FTP_Home") + "\\Download\\" + CDString.getFileName(isbn + ztm) + "\\" + CDString.getFileName(cdxh);
                DirectoryInfo dir  = new DirectoryInfo(path);

                if (dir.Exists)
                {
                    return(dir.GetFiles().First().Name);
                }
                else
                {
                    return(null);
                }
            }
            catch { return(null); }
        }