English 中文(简体)
如何找到我们在解决办法中包含的档案?
原标题:How to get path of a file which we include in our solution folder?
  • 时间:2011-10-06 04:06:50
  •  标签:
  • c#
  • c#-4.0

我有一个问题,即我必须走一只Xml文档的道路,这在我的解决办法中。 能够让任何机构了解这一档案。

曾经尝试过什么

string path = Directory.GetCurrentDirectory() + "/test.xml";

但是,这并没有给我正确的档案道路。 谁能向我提供细节,以找到一条道路?

问题回答

Try this..

String path = Application.StartupPath + “ estxml”;

如果您的xml在BIN的夹中,你可以使用该代码获得你的xml。

你们需要把档案放在一个项目的根子里。 此外,还试图纠正闪点:+“/test.xml”

如果是解决办法的夹,那么它就在申请的目前目录中获胜(根据建筑配置获得适当的双倍夹),除非你确保它是一种内容类型,并且被复制到建筑夹中。

If your parameter accept a URI you can use something like this

new Uri("/<proejct or assembly name>;component/<folder path>/<filename>")

例如,我的假.。 酒吧拥有一个有多个名称的资源,我有档案说,可以使用。

new Uri("/foo.bar;component/resources/dummy.xml")

I would be sort of leery of this requirement if I were you. Conceptually, your solution directory and solution in general is the "building materials" and your compiled, deployable code your finished "building" that you d give to a customer. What you re asking for here is like the builder of a house saying "What s the best way to cement my hammer into the floor of the basement?" Someone could probably give you a good answer, but is correctly applying the solution a good idea?

更具体地说,为什么您的操作时间、可执行守则取决于您的预定/建造时间解决结构? 我建议,你实际上可能想要做的是build活动:XML从您的解决方案中复制件,到你的目标可执行目录。 如果你这样做,那么你就可以在守则中使用你的“常备目录”方法,而不担心解决办法的结构如何。 这些建筑活动使用指挥线的星号,并为你的解决方案目录提供宏观数据,因此,你有像“SolutionDir”测试的Xml美元(BuildDir)”这样的东西。

(如果你已经意识到这一点,并且你有某种特别具体要求,要求制定符合自己解决结构的法典,则道歉。)





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签