gpt4 book ai didi

vb.net - 应用程序资源中文件的文件路径(作为字符串)是什么?

转载 作者:行者123 更新时间:2023-12-01 15:22:10 24 4
gpt4 key购买 nike

我问的原因是我想在运行时在应用程序资源中打印一个文件,如下所示:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim printProcess As New Process
printProcess.StartInfo.CreateNoWindow = True
printProcess.StartInfo.FileName = "C:\Users\Geoffrey van Wyk\Documents\Countdown_Timer_Help.rtf"
printProcess.StartInfo.FileName = My.Resources.Countdown_Timer_Help
printProcess.StartInfo.Verb = "Print"
printProcess.Start()
End Sub

当我使用“C:\ Users \ Geoffrey van Wyk \ Documents \ Countdown_Timer_Help.rtf”作为FileName的参数时,它可以工作。但是当我使用My.Resources.Countdown_Timer_Help时,它说找不到文件。

最佳答案

不,您没有得到它,该文件将仅存在于您的开发机上。部署程序后,文件将嵌入到程序中,无法打印。您必须编写代码,将文件从资源保存到磁盘,然后打印。例如:

  Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim path As String = Application.UserAppDataPath
path = System.IO.Path.Combine(path, "Help.rtf")
System.IO.File.WriteAllText(path, My.Resources.Countdown_Timer_Help)
Dim printProcess As New Process
printProcess.StartInfo.CreateNoWindow = True
printProcess.StartInfo.FileName = path
printProcess.StartInfo.Verb = "Print"
printProcess.Start()
End Sub

鉴于您必须将资源保存到文件中,因此更简单的选择是随应用程序一起部署文件,而不是将其作为资源嵌入并一遍又一遍地写入磁盘。使用Application.ExecutablePath查找文件。为了使它在调试时起作用,您必须将文件复制到bin \ Debug。为此,请使用“项目+添加现有项”将文件添加到项目中,并将“复制到输出目录”属性设置为“如果较新则复制”。

关于vb.net - 应用程序资源中文件的文件路径(作为字符串)是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2123257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com