Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用C中的程序(其本身就是exe文件)输出.exe文件?_C#_Wpf_Visual Studio_Exe - Fatal编程技术网

C# 如何使用C中的程序(其本身就是exe文件)输出.exe文件?

C# 如何使用C中的程序(其本身就是exe文件)输出.exe文件?,c#,wpf,visual-studio,exe,C#,Wpf,Visual Studio,Exe,所以这一定很容易,但很难在网上搜索。所有的结果都给了我如何用C程序生成exe文件的答案 动机:-制作一个exe文件,运行任何电视剧的随机插曲 我通过VisualStudio在C中创建了一个新的WPF应用程序,它要求用户选择一个文件夹,然后从该文件夹及其子文件夹中的所有文件运行随机视频。但我不希望用户总是去选择文件夹。我应该在代码中包含什么,以便将exe文件保存在用户选择的目录中的某个位置。然后用户可以方便地运行该文件本身。 这是我的密码: FolderBrowserDialog

所以这一定很容易,但很难在网上搜索。所有的结果都给了我如何用C程序生成exe文件的答案

动机:-制作一个exe文件,运行任何电视剧的随机插曲

我通过VisualStudio在C中创建了一个新的WPF应用程序,它要求用户选择一个文件夹,然后从该文件夹及其子文件夹中的所有文件运行随机视频。但我不希望用户总是去选择文件夹。我应该在代码中包含什么,以便将exe文件保存在用户选择的目录中的某个位置。然后用户可以方便地运行该文件本身。 这是我的密码:

        FolderBrowserDialog fbd = new FolderBrowserDialog();

        DialogResult result = fbd.ShowDialog();
        string files="a"; //Initialize


        if (result == System.Windows.Forms.DialogResult.OK)
        {
            //If user presses OK then, 'files' variable is the directory selected
            files = fbd.SelectedPath; 
        }
        else if(result == System.Windows.Forms.DialogResult.Cancel)
        {
            Close();
        }

        //All Important Video Formats Included to search for
        string[] formats = { "mp4", "avi", "mkv", "flv", "wmv", "3gp" };
        string[] Allfiles = new string[0];
        for (int i=0; i<formats.Length;i++)
        {
            string[] temp = Directory.GetFiles(files, "*" + formats[i], SearchOption.AllDirectories);
            Allfiles = AddArray(Allfiles, temp);
        }

        //Starts a random Episode
        Random episode = new Random();
        int Episode = episode.Next(0, Allfiles.Length);
        Process.Start(Allfiles[Episode]);
您可以将其写入文本文件,然后在其他应用程序中读取 使用System.IO添加

写入文本文件:

// Write the string to a file.
StreamWriter file = new System.IO.StreamWriter(txt path);
file.WriteLine(lines);

file.Close();
String line;
try 
{
//Pass the file path and file name to the StreamReader constructor
StreamReader sr = new StreamReader("C:\\Sample.txt");

//Read the first line of text
line = sr.ReadLine();

//close the file
sr.Close();
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
   finally 
{
Console.WriteLine("Executing finally block.");
}
从文本文件读取:

// Write the string to a file.
StreamWriter file = new System.IO.StreamWriter(txt path);
file.WriteLine(lines);

file.Close();
String line;
try 
{
//Pass the file path and file name to the StreamReader constructor
StreamReader sr = new StreamReader("C:\\Sample.txt");

//Read the first line of text
line = sr.ReadLine();

//close the file
sr.Close();
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
   finally 
{
Console.WriteLine("Executing finally block.");
}

如果要关闭应用程序,请键入此。关闭

是否希望应用程序为.exe或应用程序make.exe app为什么用户不能将您的exe文件复制到他们想要的文件夹中,然后此exe文件从其位置随机播放视频?这是一个奇怪的程序。用文件夹作为参数启动exe的.bat如何?同意w/@Rabban。为什么要使用已编译的二进制exe来实现此目的?批处理文件可以简单地写为文本,扩展名为.bat,并按照您的描述执行。@RazLuvaton真棒!!它起作用了。谢谢。我是新来的,所以你能告诉我,如果我能给你一些声誉或你的回答什么吗?