lu
2024-11-09 260881e61c8e994449c32f3c8793827b1b0b754d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using CefSharp;
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 _h5 = GetFileType(urlPath);
            string _url = WebApiUrl + "upload/" + _h5 + "?filePath=" + urlPath + "&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 "h5Image.html";
                case ".pdf":
                    return "h5Pdf.html";
                // 添加其他文件类型
                // ...
                default:
                    return "h5Other.html";
            }
        }
    }
}