Reputation: 6227
At the moment I'm pointing to a file on my machine, but I'm wondering how I would point the string to a folder I created within the project. For example the path to the folder in visual studio is,
C:\Users\Drian Darley\documents\visual studio 2013\Projects\KinectBVversion1\KinectKickboxingBVversion1\Gesture\jabtwo.xml
I have heard of pack URI's, would that suit in this situation or how would I set one up?
This is how it is pointing to the file at present, which is not ideal as it has to point to a file stored locally on the machine.
private string gesturefile =
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\GesturePak\\wave.xml";
Upvotes: 4
Views: 20076
Reputation: 128042
If you do not want to store files separately you need to set their Build Action
to Resource
(in the Properties window in Visual Studio) and access them by a Pack URI:
var uri = new Uri("pack://application:,,,/GesturePAK/wave.xml");
var resourceStream = Application.GetResourceStream(uri).Stream;
Now you can access the content of the XML file by resourceStream
. For example reading the file content into a string could be done like this:
string content;
using (StreamReader reader = new StreamReader(resourceStream, Encoding.UTF8))
{
content = reader.ReadToEnd();
}
Upvotes: 5
Reputation: 1639
Try like this
string gesturefile= Path.Combine(Environment.CurrentDirectory, @"GesturePak\wave.xml");
Examples:
http://msdn.microsoft.com/en-us/library/fyy7a5kt(v=vs.110).aspx http://www.dotnetperls.com/path
or
Use Path.GetFullPath
Example : http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx
Upvotes: 7
Reputation: 38094
for example, if you create a folder called "Images" within your project, then you can point like:
string address="Images/dukenukem.jpg";
Upvotes: 1