c# - WinForms如何打开资源文件夹中的文件
问题描述
我是 WinForms 技术的新手。我正在使用 .NET Framework 4.8 ,Microsoft Visual Studio 2019。我将文件放在文件Resources
夹中。
我尝试过这样的事情
using DevExpress.XtraBars;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace accwf
{
public partial class NhapSoDu : DevExpress.XtraBars.Ribbon.RibbonForm
{
public NhapSoDu()
{
InitializeComponent();
}
private void simpleButton1_Click(object sender, EventArgs e)
{
Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);
Process.Start(".../B01-DN_01_Summary.xlsx");
}
}
}
请指导我完成它。
解决方案
我在我的一个应用程序中执行此操作以打开一个 XLSX 文件,该文件是我的应用程序中的嵌入式资源
private void buttonOpenTemplate_Click(object sender, EventArgs e)
{
byte[] templateFile = Properties.Resources._01__So_du_tai_khoan; // This is your Excel document in the application Resources
string tempPath = $"{Path.GetTempFileName()}.xlsx";
using (MemoryStream ms = new MemoryStream(templateFile))
{
using(FileStream fs = new FileStream(tempPath, FileMode.OpenOrCreate))
{
ms.WriteTo(fs);
fs.Close();
}
ms.Close();
}
Process.Start(tempPath);
}
这需要引用来System.IO
访问MemoryStream
和FileStream
类。
推荐阅读
- r - 如何编写调用数据和列的函数?
- android - 设置 BottomSheetBehavior 时出现空指针异常
- javascript - 导航到延迟加载模块 Angular 8 的子节点
- mysql - 如何匹配同一张表的多个列并选择最大匹配列
- c# - 无法在下拉 selectedindexchange 中附加列表以供以后在 buttonclick 事件中使用
- spring - 使用 spring boot 应用程序在 ROMETOOL 上设置我的 RSS 提要
- python-3.x - 在 Python Selenium 中处理 reCAPTCHA
- python - django docker db migrations 不适用于新模型
- python - 反向查找 django 模型
- react-native - 来自 Firebase 推送通知的反应导航导航