100 lines
2.9 KiB
C#
100 lines
2.9 KiB
C#
using System.Diagnostics;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
//using Outlook = Microsoft.Office.Interop.Outlook;
|
|
|
|
namespace Gremlin_BlazorServer.Services
|
|
{
|
|
internal static class FileIO
|
|
{
|
|
public static string ReadResource(string name)
|
|
{
|
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
|
|
// Format: "{Namespace}.{Folder}.{filename}.{Extension}"
|
|
string resourcePath = name.StartsWith(nameof(Gremlin_BlazorServer))
|
|
? name
|
|
: assembly.GetManifestResourceNames().Single(str => str.EndsWith(name));
|
|
|
|
using (Stream? stream = assembly.GetManifestResourceStream(resourcePath))
|
|
{
|
|
if (stream == null) { return ""; }
|
|
using (StreamReader reader = new(stream))
|
|
{
|
|
return reader.ReadToEnd();
|
|
}
|
|
}
|
|
}
|
|
|
|
private static readonly Encoding defaultEncodingIfNoBom = Encoding.UTF8;
|
|
|
|
// public static string GetFilepathFromUser(string filter = "Delimited Data File|*.csv; *.txt; *.tsv")
|
|
// {
|
|
// string _filepath = "";
|
|
// OpenFileDialog dlg = new()
|
|
// {
|
|
// Multiselect = false,
|
|
// Filter = filter
|
|
// };
|
|
|
|
// if (dlg.ShowDialog() == true)
|
|
// {
|
|
// //Auswahl dlg.filenames an passende Objekte übergeben
|
|
// _filepath = dlg.FileName;
|
|
// }
|
|
// return _filepath;
|
|
// }
|
|
|
|
internal static void OpenFile(string path, string file, string type)
|
|
{
|
|
try
|
|
{
|
|
_ = Process.Start(path == "" ? $"{file}.{type}" : $"{path}\\{file}.{type}");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.WriteLine(ex);
|
|
}
|
|
}
|
|
|
|
public static Encoding GetEncoding(string fileName)
|
|
{
|
|
Stream fileStream = File.OpenRead(fileName);
|
|
using (StreamReader reader = new(fileStream, defaultEncodingIfNoBom, true))
|
|
{
|
|
_ = reader.Peek();
|
|
Encoding encoding = reader.CurrentEncoding;
|
|
return encoding;
|
|
}
|
|
}
|
|
|
|
// public static void WriteClipboardToTSV(string clipboard, QuoteViewModel quoteVM)
|
|
// {
|
|
// string datei = quoteVM.QuotePath + quoteVM.QuoteNumber + ".tsv";
|
|
// using StreamWriter writer = new(datei, false, Encoding.UTF8);
|
|
// {
|
|
// writer.WriteLine(clipboard);
|
|
// }
|
|
// }
|
|
|
|
//public static void SendQuoteViaMail(QuoteVM quoteVM)
|
|
//{
|
|
// Outlook.Application application = new();
|
|
|
|
// Outlook.MailItem mail = application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
|
|
|
|
// mail.Subject = quoteVM.QuoteNumber;
|
|
// Outlook.AddressEntry currentUser = application.Session.CurrentUser.AddressEntry;
|
|
|
|
// if (currentUser.Type == "EX")
|
|
// {
|
|
// Outlook.ExchangeUser manager = currentUser.GetExchangeUser().GetExchangeUserManager();
|
|
// // Add recipient using display name, alias, or smtp address
|
|
// mail.Recipients.Add(manager.PrimarySmtpAddress);
|
|
// mail.Recipients.ResolveAll();
|
|
// mail.Attachments.Add($"{quoteVM.QuoteNumber}.pdf", Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
|
|
// mail.Send();
|
|
// }
|
|
//}
|
|
}
|
|
} |