|
The GetDirectories() function returns an array of DirectoryInfo's, not strings. Besides, your code won't work either, since you have the foreach statement outside of the try block. It is on the foreach that it gets the exception. I just decided to pull the code out of the foreach statement so I could better figure out where it was getting the exception. So, I have this:
static void FindFile(DirectoryInfo dirInfo, string fileName, out FileInfo fileFound)<br />
{<br />
try<br />
{<br />
DirectoryInfo[] dirs = dirInfo.GetDirectories("*.*", SearchOption.AllDirectories);<br />
foreach (DirectoryInfo di in dirs)<br />
{<br />
if ((di.Attributes & FileAttributes.System) == 0)<br />
{<br />
FileInfo fileI = SearchDirectory(di, fileName);<br />
if (fileI != null)<br />
{<br />
fileFound = fileI;<br />
return;<br />
}<br />
}<br />
}<br />
}<br />
catch (System.UnauthorizedAccessException ex)<br />
{<br />
Console.WriteLine("Security EXCEPTION: {0}", ex.Message);<br />
fileFound = null;<br />
return;<br />
}<br />
<br />
catch (Exception ex)<br />
{<br />
Console.WriteLine("EXCEPTION: {0}", ex.ToString());<br />
fileFound = null;<br />
return;<br />
}<br />
fileFound = null;<br />
}
It bombs on the first instruction (GetDirectories). Thkx
|
|
|
|
|
Some points to note:
1) Directory.GetDirectories() returns an array of strings. Argue with the documentation & the code if you want but that's what it returns.
2) The code works just fine, I can copy and paste the results if you want but you may not understand them
3) Of course the code fails on the first line, you're still trying to recurse the directories, why my snippet did was demonstrate (perhaps too simply) that you needed to handle the recursion yourself so that you could continue searching rather than stopping when the exception occurred.
So in summary what you'll have to do is write a recursive routine which searches through a directory (not including the sub-directories), if it finds a file return it, if it can't read a directory then skip over it. And continue all the way through the loop.
sshhessh
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
Oooooh. You are using Directory instead of DirectoryInfo!!! I see it now. Thanks. I will give it a go.
With my method I could not see how to handle that exception using the OOP design of .NET.
TY
|
|
|
|
|
i ned to enter urdu text in th text box wen i use multi line textbox it displays some characters as a box i.e. dsnt identify it... where as wen i use a single line text box it displays every character correctly how can i handle this
|
|
|
|
|
If the characters being displayed are near the line breaks maybe it has something to do with the line break characters you are using in the text box.
Maybe the problem has something to do with the string you are using to store the string. If you are using C++ .Net you might need to qualify strings you wanted to treat as unicode:
sampleText = S"some text";
When I worked on a project using Korean text we would sometimes find that certain character combinations were shown inaccurately. We were not storing our character strings as unicode.
|
|
|
|
|
i m using C#.. plus there are som specefic characters that it dsnt diplay correctly and a box instead of it i real don know wat may b the reason.. will u plz kindly explain this line break thing more...
Regards RAbia
|
|
|
|
|
Hi,
I am new to windows forms.I would like to know about creating a Datagrid and connecting it to database.I have a GUI interface in which I will have to take input values from user in a matrix form. Could you please let me know how to perform this operation.It would be of great help if you can help me! Thank you.
Haritha.
|
|
|
|
|
haritha22 wrote: Could you please let me know how to perform this operation.
Get it from the toolbox, if you haven't already done so...
If you try to write that in English, I might be able to understand more than a fraction of it. - Guffa
|
|
|
|
|
I need to alter behavior of calling some classes,
extending it
to call some intermediate function.
for this I must create dynamic proxy
and supply some alternate handlers with calls,
are some articles or sample which do something like that ?
service calls may by interthread call to data bound objects,
or call to else app-domain of marshal by value objects,
not serializing them or some applied servicing.
thanks you
|
|
|
|
|
|
Yeah it is a WTF! OTOH you could say that this applies to any application. I've yet to use any application that does not crash unexepectedly under some circumstances!
Kevin
|
|
|
|
|
Hi all
when i start my project i am getting this message.
"The server returned an invalid or unrecognized response".
can anybody help me?
|
|
|
|
|
radixpune wrote: can anybody help me?
Be a bit more discriptive of your problem
"I'd like to help but I don't feel like Googling it for you."
|
|
|
|
|
Hi,
I am developing a smart device application in VS 2005 .I would like to know that if VS 2005 supports multilanguage programming in the same project like Web Application or not.
Thanks in advance,
Irshad Ahmad
Irshad Ahmad
|
|
|
|
|
hi all
i have an issue not resolves since last two months ;;
i wanted to plpay flas file and for this i got axfalshobject every thing goes ok for the first time when i give it the path of swf file to play but it does not go into loop ,, what if i want to play it again and again , though this object has play , stop property but none of it works,, means flahs file just plays for once ,,, any idea? or is there any other better solution , i am tired of research plz help me
thanks in advance
hello
|
|
|
|
|
I assume you dont have access to the fla, right?
because you can then remove the 'stop()' from the last frame.
I think there is a way to get the the _currentframe property. You have to poll the flash and when it reach the last frame you issue a play() or riwind()/play() command.
|
|
|
|
|
Hi guys,
How can I extract icon from DLL or EXE file ?
Plase help me.
Thanks in advance.
Glen
|
|
|
|
|
|
|
I'm not sure but I thought I saw this somewhere on the web. Thanks.
-- modified at 18:21 Monday 20th November, 2006
M.E. Guzman
|
|
|
|
|
mitchellguzman wrote: I thought I saw this somewhere on the web
I assure you it was not in the Lounge.
|
|
|
|
|
*grin* you just beat me.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
The only way to call .NET with COM is if the .NET component is also a COM component, or if the COM component is written in a .NET language.
Christian Graus - C++ MVP
|
|
|
|
|
Hello,
This is my first message here, so my Hello to you all again!!
This question is not quite related to coding, not directly atleast. I am just curious to know how DataReader class in .Net works??
Scenario is:
We do not call the constructor of DataReader class, this means that its constructor is marked "Private". Rather we use a Method, "ExecuteReader" of another Class "Command" while creating DataReader's object.
I am trying to mimic this thing. I can do this easily if ExecuteReader method belongs to the same class i.e. DataReader, but I have no idea how to implement the same technique using 2 seperate classes.
Command.ExecuteReader method returns a DataReader object, but does it also calls its constructor?
Inheriting DataReader Class is not possible because it is also marked "Sealed", so how can I implement the same thing??
Thank you.
Hope I have put the question well!!
---
HARSH GUPTA
|
|
|
|
|
You can make the constructor internal , that means that any class in the same assembly can use it.
---
b { font-weight: normal; }
|
|
|
|