using CefSharp.WinForms;
|
using System;
|
using System.Configuration;
|
using System.IO;
|
using System.Windows.Forms;
|
|
namespace Gs.DevApp.UserControl
|
{
|
public partial class ShowFile : DevExpress.XtraEditors.XtraForm
|
{
|
private static readonly string WebApiUrl =
|
ConfigurationManager.AppSettings["WebApiUrl"];
|
private ChromiumWebBrowser chromeBrowser;
|
string urlPath;
|
public ShowFile(string _urlPath)
|
{
|
InitializeComponent();
|
this.urlPath = _urlPath;
|
this.Load += ShowFile_Load;
|
this.FormClosed += ShowFile_FormClosed;
|
}
|
|
private void ShowFile_FormClosed(object sender, FormClosedEventArgs e)
|
{
|
chromeBrowser.Dispose();
|
}
|
|
private void ShowFile_Load(object sender, EventArgs e)
|
{
|
string filePath = System.Uri.EscapeUriString(urlPath);
|
string fileType = GetFileType(urlPath);
|
string _url = WebApiUrl + "upload/h5/site.html?fileType=" + fileType + "&filePath=" + filePath + "&mid=" + Guid.NewGuid().ToString();
|
chromeBrowser = new ChromiumWebBrowser(_url);
|
this.pane1.Controls.Add(chromeBrowser);
|
chromeBrowser.Dock = DockStyle.Fill;
|
txtUrl.Text = _url;
|
txtUrl.ReadOnly = true;
|
}
|
|
public static string GetFileType(string fileName)
|
{
|
// 获取文件扩展名
|
string extension = Path.GetExtension(fileName);
|
// 根据扩展名判断文件类型
|
switch (extension.ToLowerInvariant())
|
{
|
case ".jpg":
|
case ".jpeg":
|
case ".png":
|
return "img";
|
case ".pdf":
|
return "pdf";
|
case ".mp4":
|
return "mp4";
|
default:
|
return "other";
|
}
|
}
|
}
|
}
|