如何将文件保存到项目文件夹而不使用保存对话框 [英] How to save a file into project Folder without using save dialog

查看:106
本文介绍了如何将文件保存到项目文件夹而不使用保存对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将文件保存到项目文件夹中:



例如我的项目文件夹是 WpfApplication 图像是一个子文件夹。



如果我通过打开Dailog 如何将其保存到图像文件夹?

How to save the file into project folder:

E.g. my project folder is WpfApplication and Images is a sub folder.

If I select the file through Open Dailog how can i save it into image folder?

推荐答案

由于您使用打开文件对话框打开文件,因此可以使用获取所选文件的对象的File属性(如果只选择了一个文件,如果选择了多个文件,那么将返回集合中的第一个文件),然后你可以使用它的名称文件(以字符串形式)。最后,将该文件复制到您的目录。



https://msdn.microsoft.com/en-us/library/system.windows.controls.openfiledialog.file(v = VS.95)的.aspx [ ^ ]用于OpenFileDialog.File属性。

https://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.fullname(v = VS.95)的.aspx [ ^ ] FileInfo对象的FullName属性。

https://msdn.microsoft.com /en-us/library/c6cfw35a(v=vs.95).aspx [ ^ ]用于File.Copy(字符串,字符串)方法。您可以使用此方法将该文件从位置复制并粘贴到您指定的位置。



如果您要执行此操作,将文件数据写入项目(Visual Studio解决方案),那么它将不起作用,文件必须是使用添加功能添加到解决方案。
Since you're opening the file using a Open File Dialog, then you can use the File property of the object to get the File that was selected (this is if there is only one file selected, if multiple files were selected then the first file in the collection would be returned), and then you can use the Name of that file (in string). Finally, Copy that file to your directory.

https://msdn.microsoft.com/en-us/library/system.windows.controls.openfiledialog.file(v=vs.95).aspx[^] for OpenFileDialog.File property.
https://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.fullname(v=vs.95).aspx[^] FullName property of the FileInfo object.
https://msdn.microsoft.com/en-us/library/c6cfw35a(v=vs.95).aspx[^] for the File.Copy(string, string) method. You can use this method to copy and paste that file from location to your own specified location.

If you're going to perform this action, to write the file data into the project (Visual Studio solution) then it is not going to work, files must be added to the solution using the Add feature.


谢谢老兄的帮助

i刚刚使用保存对话框解决了我的问题。
thank you dude for your help
i just salved my problem bt using save dialog box.


这篇关于如何将文件保存到项目文件夹而不使用保存对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆