lu
2025-04-14 ecb7a60de1639f520712ce95f99414b0dd2c9713
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.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";
            }
        }
    }
}