Reputation: 275
I am trying to access the folder from winform application using the below code but its give me this path
D:\myproject\abc\bin\Debug\..\xml\list.xml
But my folder is is in this location
D:\myproject\abc\xml\list.xml
I am using this code for access xml file
protected void GetProcess()
{
var ps = Process.GetProcesses();
pictureBox1.Visible = true;
label2.Text = "Tracking Downloader";
foreach (var p in ps)
{
try
{
Process[] proc = Process.GetProcessesByName(p.ProcessName);
XDocument xdoc = XDocument.Load("..\\xml\\lst");
var block = xdoc.Descendants("lst");
foreach (var list in block)
{
if (proc[0].MainModule.FileVersionInfo.FileDescription.Contains(list.Value) )
{
p.Kill();
}
}
// listBox1.Items.Add(proc[0].MainModule.FileVersionInfo.FileDescription);
}
catch
{
Console.WriteLine("Access Denied");
}
}
//pictureBox1.Visible = false;
label2.Visible = true;
Console.ReadLine();
}
Experts Please Help. Thanks
Upvotes: 0
Views: 1116
Reputation: 19091
Your problem is that when running from Visual Studio, your app is running from the bin
directory. A compiled application will probably run from a different place.
You probably want to add the file list.xml
to the output directory, so that it will be available from wherever the app runs. You can do this in two steps:
"xml"
under your project, and adding the file list.xml
to it (use Add --> existing item from the right click context menu).Now, when you compile your project, your new folder and file, xml/list.xml
, will be included under /bin
, and you should be able to access it from wherever you run your app.
Upvotes: 3