12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace LogoForceTestApp.Modules.MainModule
- {
- public class DataHelp
- {
- //写csv
- public static bool Save(string fullPath, string fileName, string RowName, string Data)
- {
- bool result = true;
- try
- {
- if (!Directory.Exists(fullPath))
- {
- Directory.CreateDirectory(fullPath);
- }
- if (fileName == null)
- {
- fileName = DateTime.Now.ToString("yyyyMMdd");
- }
- string text = "";
- string path = fullPath + "\\" + text;
- string text2 = ".csv";
- string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
- if (!File.Exists(fullPath + "\\" + fileNameWithoutExtension + fileName + text2))
- {
- using (File.Create(fullPath + "\\" + fileNameWithoutExtension + fileName + text2))
- {
- }
- FileStream fileStream2 = new FileStream(fullPath + "\\" + fileNameWithoutExtension + fileName + text2, FileMode.Append);
- StreamWriter streamWriter = new StreamWriter(fileStream2, Encoding.UTF8);
- streamWriter.WriteLine(RowName);
- streamWriter.WriteLine(Data);
- streamWriter.Flush();
- streamWriter.Close();
- fileStream2.Close();
- }
- else
- {
- FileStream fileStream2 = new FileStream(fullPath + "\\" + fileNameWithoutExtension + fileName + text2, FileMode.Append);
- StreamWriter streamWriter = new StreamWriter(fileStream2, Encoding.UTF8);
- streamWriter.WriteLine(Data);
- streamWriter.Flush();
- streamWriter.Close();
- fileStream2.Close();
- }
- }
- catch
- {
- result = false;
- }
- return result;
- }
- }
- }
|