简体   繁体   English

在C#WPF应用程序中将批处理文件用作资源

[英]Using a batch file as a resource in C# WPF Application

I have a batch file i want to create from my Resources. 我有一个要从我的资源创建的批处理文件。

I know this method for creating a file for .exe files: 我知道这种为.exe文件创建文件的方法:

byte [] resource_bytes = Project.Properties.Resources.exefile;
File.WriteAllBytes(path, resource_bytes);

It doesn't work the same for batch files. 对于批处理文件,它的工作方式不同。

Does someone has a solution? 有人有解决方案吗?

A windows Batch file (bat) is a text file, Try this one: Windows Batch file (bat)是文本文件,请尝试以下操作:

if (!string.IsNullOrEmpty(text))
{
    File.WriteAllText(resourcePath, text);
}
else
{
    MessageBox.Show("The Batch file is empty");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM