Ejemplo n.º 1
0
 public static bool SaveFile(string path, string content, Encoding encoding = null)
 {
     try
     {
         if (!DirFileHelper.CreateDirIfNotExist(FilePathHelper.GetDirectoryName(path.PathNormalize())))
         {
             return(false);
         }
         if (encoding == null)
         {
             encoding = Encoding.UTF8;
         }
         using (FileStream stream = new FileStream(path, FileMode.Create))
         {
             using (StreamWriter writer = new StreamWriter(stream, encoding))
             {
                 writer.Write(content);
                 writer.Flush();
                 writer.Close();
             }
             stream.Close();
         }
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
 public static bool MoveFile(string sourceFilePath, string descFilePath)
 {
     if (string.IsNullOrEmpty(sourceFilePath) || string.IsNullOrEmpty(descFilePath))
     {
         return(false);
     }
     try
     {
         if (!File.Exists(sourceFilePath))
         {
             return(false);
         }
         if (!DirFileHelper.CreateDirIfNotExist(FilePathHelper.GetDirectoryName(descFilePath.PathNormalize())))
         {
             return(false);
         }
         if (File.Exists(descFilePath) && !DeleteFile(descFilePath))
         {
             return(false);
         }
         File.Move(sourceFilePath, descFilePath);
     }
     catch
     {
         return(false);
     }
     return(true);
 }