First of all - i googled the problem, and nothing good related seemed to come up. Also it will probably seem to you that this question is a newbie one (and i must say i never had this problem when printing files in a directory. I am pretty new to WPF in C#.
so.. I am having problems to Print all files in directory that has ".xml" format
Here is my code to print the files in a directory (I am not talking about Recursive dirs and files print):
private void Load_ToolboxItems(string dirPath, string os, string version)
{
try
{
foreach (string command in Directory.GetFiles(dirPath, "*.xml"))
{
//load commands by OS compatibility
MessageBox.Show(command);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
This is my window load event:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
MessageBox.Show("Combined " + System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName), @"\data\Windows\xp\"));
MessageBox.Show(System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName));
Load_ToolboxItems(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName), @"\data\Windows\xp\"), "Windows", "XP");
}
Those are the outputs i get when running the program:
1st messagebox- "Combined \data\Windows\xp\"
2nd messagebox-
C:\Users\Din\Din\Programming\Webs\Ended Projects\LogicalArm\Products\Visual Command Line\Visual_Command_L开发者_运维百科ine-wpf_net3.5c_vs2010\Visual_Command_Line\bin\Release
3rd messagebox- "could not find part of the path 'C:\data\Windows\xp'."
This is where the exe starts from:
C:\Users\Din\Din\Programming\Webs\Ended Projects\LogicalArm\Products\Visual Command Line\Visual_Command_Line-wpf_net3.5c_vs2010\Visual_Command_Line\bin\Release
foreach (String file in Directory.GetFiles(dirPath))
{
if (Path.GetExtension(file) == ".xml")
MessageBox.Show(file);
}
Not sure if your underlying issues is you are not getting the exact path you want, however the above should give you what you want from a listing of XML files stance.
Remove the \ from \data\windows\xp (the first \ that is). Also be careful because your path is getting long. There is a 260 character limit.
Path.Combine() know the directory separator character to use, so when you use it, the second parameter should not start with a .
huh,
it always happens to me..
five minutes after i ask a question and after a long search i some-how find the problem myself..
I had problem with the path -_-
thanks for trying to help by the way
精彩评论