Excel file drag and drop
Jetzt kann man auch Excel files direkt aus dem Browser ins ENI ziehen. Diese werden im Hintergrund heruntergeladen und in einer temporären Datei gespeichert. Damit wird der Schritt erst die Datei herunterzuladen und vom lokalen Verzeichnis aus zu öffnen übersprungen.
This commit is contained in:
parent
fd8a809a0f
commit
6a5e719384
@ -6,6 +6,7 @@ using bsmd.database;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Windows;
|
||||
|
||||
namespace ENI2.EditControls
|
||||
@ -28,9 +29,11 @@ namespace ENI2.EditControls
|
||||
|
||||
#region Drag&Drop event handler
|
||||
|
||||
private void imageSource_Drop(object sender, DragEventArgs e)
|
||||
private async void imageSource_Drop(object sender, DragEventArgs e)
|
||||
{
|
||||
string[] files = (string[]) e.Data.GetData(DataFormats.FileDrop);
|
||||
if (files != null)
|
||||
{
|
||||
foreach (string file in files)
|
||||
Console.WriteLine(file);
|
||||
if (files.Length > 0)
|
||||
@ -56,10 +59,34 @@ namespace ENI2.EditControls
|
||||
EnableCompareButton();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string link = (string)e.Data.GetData(DataFormats.Text);
|
||||
if(link != null)
|
||||
{
|
||||
// check if it is really an url, try to download the file and open it
|
||||
if(Uri.TryCreate(link, UriKind.Absolute, out Uri uri))
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
var response = await client.GetAsync(uri);
|
||||
string fileName = Path.GetTempPath() + Guid.NewGuid().ToString() + ".xlsx";
|
||||
using (var fs = new FileStream(fileName, FileMode.CreateNew))
|
||||
{
|
||||
await response.Content.CopyToAsync(fs);
|
||||
textBoxSource.Text = link;
|
||||
_sourcePath = fileName;
|
||||
EnableCompareButton();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void imageTarget_Drop(object sender, DragEventArgs e)
|
||||
private async void imageTarget_Drop(object sender, DragEventArgs e)
|
||||
{
|
||||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
if (files != null)
|
||||
{
|
||||
foreach (string file in files)
|
||||
Console.WriteLine(file);
|
||||
if (files.Length > 0)
|
||||
@ -85,6 +112,28 @@ namespace ENI2.EditControls
|
||||
EnableCompareButton();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string link = (string)e.Data.GetData(DataFormats.Text);
|
||||
if (link != null)
|
||||
{
|
||||
// check if it is really an url, try to download the file and open it
|
||||
if (Uri.TryCreate(link, UriKind.Absolute, out Uri uri))
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
var response = await client.GetAsync(uri);
|
||||
string fileName = Path.GetTempPath() + Guid.NewGuid().ToString() + ".xlsx";
|
||||
using (var fs = new FileStream(fileName, FileMode.CreateNew))
|
||||
{
|
||||
await response.Content.CopyToAsync(fs);
|
||||
textBoxTarget.Text = link;
|
||||
_targetPath = fileName;
|
||||
EnableCompareButton();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void imageSource_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user