如何获取解决方案文件的位置 [英] How to get solution file's Location
问题描述
我想将文件从我的项目位置复制到本地磁盘[即。在D驱动器上]
我的解决方案名称 - > CoffeeShop我将现有项目添加到我的解决方案 - FileName - Logo.JPG
我只想将此Logo.JPG文件从我的项目/解决方案位置复制到本地D盘。
我对File.Copy()方法有一个想法。
但我怎么样可以从位置设置Logo.JPG文件的位置。
例如
string solutionFileLocation = [how我可以得到这个位置吗?]
string to_Location = @D:\;
File.Copy(solutionFileLocation,to_Location) ;
Thnx提前
I want to Copy file from my project Location to local Disk[i.e. on "D" drive]
My Solution Name --> CoffeeShop I add existing item to my solution--FileName--Logo.JPG
I Just want to copy this Logo.JPG file from my project/solution location to Local D Disk.
I have an Idea about File.Copy() method.
But how i can set location of Logo.JPG file as from Location.
e.g.
string solutionFileLocation = [how I can get this location?]
string to_Location= @"D:\";
File.Copy(solutionFileLocation,to_Location);
Thnx in advance
推荐答案
你的问题没有任何意义。如果需要从某个目录调用File.Copy
到其他目录,则在运行时执行此操作。在运行时,没有解决方案,项目以及任何其他源文件。这就是构建和构建生成的模块和程序集。
如果您只需要知道可执行文件目录,那么应用程序程序集的目录(程序集)更准确地说,是程序集的可执行模块,请查看我以前的答案:如何查找我的程序目录(可执行目录)。
另请参阅我的其他答案:如何找到我的程序目录(当前目录,特殊文件夹)。
-SA
Your question does not really make any sense. If you need to callFile.Copy
from certain directory to some other directory, you do it during runtime. And during runtime, there is no such thing as solution, project, as well as any other source file. This is what goes to the build, and the build produced modules and assemblies.
If you simply need to know the executable directory, the directory where your application assembly (assemblies, more exactly, assemblies' executable modules) are located, please see my past answer: How to find my programs directory (executable directory).
See also my other answer: How to find my programs directory (current directory, "special folders").
—SA
Hi
如果您添加图片,请点击项目属性,点击 - >添加 - >现有项目,然后使用下面的代码获取图像文件路径
Hi If u add images likes project propertis rigth click --> Add ->Existing item,then use below code to get image file path
private void button1_Click(object sender, EventArgs e)
{
string strpath = Application.StartupPath; //in this strpath u get application directory path,i mean ur solution path
strpath = strpath + "\\Logo.JPG"; // here u can add then file name
MessageBox .Show (strpath ); //and finally u get full image file path
}
如果您将文件保存在任何文件夹中,请使用此
If u save file inside any folder then use this
{
string strpath = Application.StartupPath; //in this strpath u get application directory path,i mean ur solution path
strpath = strpath + "\\NF\\Logo.JPG"; // here u can add then file name,NF is folder name inside solution
MessageBox .Show (strpath ); //and finally u get full image file path
}
string solutionFileLocation
= Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName+"\\CoffeeShop\\Logo.JPG";
这篇关于如何获取解决方案文件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!