如何将嵌入的文本文件复制到c#.net windows应用程序中的另一个位置? [英] How to copy embedded text file to another location in c#.net windows application?
问题描述
我之前在这里问过一个问题,我也有一个解决方案。这是我的问题的链接 - http://www.codeproject.com/Questions/613427/How-to-a-copy-text-file-without-overwrite-existing?arn=0
问题是我想做同样的事情,但使用嵌入式文本文件作为源文件,我试图解决它,但没有成功。 Plz帮助。
使用以下代码:
< pre lang =cs> private void button1_Click( object 发件人,EventArgs e)
{
尝试
{
var resourceName = WindowsFormsApplication1.TextFile1.txt;
WriteResourceToFile(resourceName, C:\\\ txt);
}
catch
{
MessageBox.Show( 访问资源时出错!);
}
}
public void WriteResourceToFile( string resourceName, string fileName)
{
使用( var resource = Assembly.GetExecutingAssembly()。GetManifestResourceStream(resourceName))
{
使用( var file = new FileStream(fileName,FileMode。 Create,FileAccess.Write))
{
resource.CopyTo(file);
}
}
}
您还可以在以下链接中找到一个很好的解释:
http://stackoverflow.com/questions/13031778/how-can-i-extract-a-file-from-an-embedded-resource-and-save -it-to-disk [ ^ ]
嵌入式资源名称为YourNamespace。 ResourceName.Extension这是完美解释
http://support.microsoft.com/kb/319292 [ ^ ]
此 m
文章[ ^ ]向您展示如何使用StreamReader访问嵌入的文本文件。
这个m
I have asked a question here before and i have got a solution too. This is the link of my question- http://www.codeproject.com/Questions/613427/How-to-a-copy-text-file-without-overwrite-existing?arn=0
problem is i want to do same thing but using embedded text file as source file and i have try to solve it but no success. Plz help.
use the following code:
private void button1_Click(object sender, EventArgs e) { try { var resourceName = "WindowsFormsApplication1.TextFile1.txt"; WriteResourceToFile(resourceName, "C:\\1.txt"); } catch { MessageBox.Show("Error accessing resources!"); } } public void WriteResourceToFile(string resourceName, string fileName) { using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { resource.CopyTo(file); } } }
and also you can find a good explanation in the following links :
http://stackoverflow.com/questions/13031778/how-can-i-extract-a-file-from-an-embedded-resource-and-save-it-to-disk[^]
the Embedded resource name is "YourNamespace.ResourceName.Extension" which is explaind perfectly here
http://support.microsoft.com/kb/319292[^]
This m
article[^] shows you how to access the embedded text file using StreamReader.
this m
这篇关于如何将嵌入的文本文件复制到c#.net windows应用程序中的另一个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!