|
GetFiles only works with one wildcard pattern. If you want to return varying patterns, like "*.jpg" and "*.bmp" you'll have to make seperate calls to GetFiles, one for each pattern you want to use.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
Here's something I coded up a few weeks ago:
public IEnumerable<string> GetFilesInDirectory(string directory, SearchOption searchOptions, params string[] filters)
{
foreach (string matchingFile in Directory.GetFiles(directory, "*.*", searchOptions))
{
if(EndsWithAny(matchingFile, filters))
{
yield return matchingFile;
}
}
}
bool EndsWithAny(string text, string[] endings)
{
foreach(string ending in endings)
{
if(text.EndsWith(ending))
{
return true;
}
}
return false;
}</string>
You can use it like this:
foreach(string jpgOrHtmFile in GetFilesInDirectory("c:\\myDir", SearchOption.AllDirectories, ".jpg", ".htm"))
{
Console.WriteLine(jpgOrHtmFile);
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Dumbest. Movie. Title. Evaaar.
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
many thx Judah
it works good
|
|
|
|
|
Hi
I have an SQL query which can be run in the Microsoft Visual C# 2005 Express Edition. But when I put that query in my program, it doesn't get run and it throws an exception saying "No given value for one or more required parameters".
Anybody knows how it could happen?
Thanks
|
|
|
|
|
printscreen12345 wrote: "No given value for one or more required parameters". Anybody knows how it could happen?
Just a guess, but I'd say you have parameters in your SQL statement that are not being set.
only two letters away from being an asset
|
|
|
|
|
it would be useful to:
- know the query
- know what you mean when talking about "my program"
did you ever read this "how to ask questions the smart way"-guide? :P
|
|
|
|
|
did you try to debug your application and then take the generated SQL query to execute directly on SQL Server or "Server Connections" in VS, for instance?
|
|
|
|
|
I was doing this
dt.Rows.Add(ds.Tables[0].Rows[1]);
Where dt is one table and ds.Tables[0] is another table. Now the
above statement throws up an error stating that "the row already
belongs to one table"
if i define an ArrayList
ArrayList al = new ArrayList()
and do
al.Add(ds.Tables[0].Rows[1])
this one works. Does any one know why the first one doesn't work
Probably the round about way is creating a new datarow and getting
the values from the ds.Tables[0] for that row and rebuilding the new row
for the dt table. But dont you guys think it make sense to directly copy the whole row from one datatable to another.
How do i do it.
Thanks
kal
|
|
|
|
|
The first one doesn't work because a DataRow may only belong to ONE and only one DataTable.
The second one works because an ArrayList is not a DataTable hence nobody cares about it.
It would make a lot of sense to copy the row from one table to another but what would happen if you change the values of the row in table A. the values would also be changed in table B because they're sharing a row. Maybe you want it to act like this but i wouldn't recommend trying it like this.
Instead you should do it as you've already mentioned and copy the important data from the row of table A to a NEW row of table B.
Good luck,
mik
|
|
|
|
|
I have a socket app. I have an event that is fired when the connection is closed. This event is caught stops my other two timers, and enables a 3rd timer, sets the timer interval and starts it. But it never happens, it never drops in to the tick event method. I have two other timers that are started from an event...like when the connection is up, they work fine. But it does not work when the connection is closed.
Not sure what code to post to help out as the event is in once class, the socket in another class, etc.
Why would a timer not fire on the tick event?
Thanks
Tom Wright
tawright915@gmail.com
|
|
|
|
|
you should try to get more information.
do you use an ide? if yes, which one and does it support breakpoints?! if so, use them.
make sure you see the line, where the timer is started, being executed.
also print out the values of the timer before it get started. compare the code of the other two timers and so on. before starting any timer, you should print its values to make sure its set up correctly. try to debug it because, as you already said, noone will know where to start searching.
|
|
|
|
|
yes I'm stepping thru my code (VS2003) and the interval is getting set. The timer is getting started. It's just never fired.
The last statement that is stepped thru is:
this.autoEvent.Set();
this is in the socket class. It is reseting my events when the socket is closed.
Then control is back at the interface...waiting for the timer to fire.
Tom Wright
tawright915@gmail.com
|
|
|
|
|
Question: can I make my timers avaliable in other classes...so that when the connection is closed, that class can start the timer, instead of me having to fire an event?
thanks
Tom Wright
tawright915@gmail.com
|
|
|
|
|
Sure you can, depending on how you've designed your classes
If you want to make this timer available in other classes you have to have an instance of the class where the timer is in and provide a public interface (e.g. a property) for the other classes.
Also check if your events are bound correctly and let them being fired by some function which definitely works (100%), to make sure that its a problem related with the timer or other code.
You should try to fire the event at least once, to make sure that the timer itself works...
|
|
|
|
|
Are you using the System.Windows.Forms.Timer or the System.Threading.Timer? If you're using the tick event it looks like you're using the windows forms timer. If so, make sure you're using it in a class that inherits from Form , otherwise it won't work. The Threading.Timer is a better option in that case, you can set the interval and a callback function in its constructor.
|
|
|
|
|
It's a forms timer. The timers are setup in my form class. My other timers are working fine.. They start and stop okay.....and they too are being started when the connection event is fired. Then the close event is fired I stop the first two timers and start a thrid timer. This will allow the connection to restart after a certain elasped time. However this third timer is never started. Even though I'm enabling, setting the time interval, and calling the start method.
Thanks
Tom Wright
tawright915@gmail.com
|
|
|
|
|
If you're stopping another timer, why not just change its interval to the interval you had in mind for the third timer and hook up the right event listener to it?
|
|
|
|
|
I have a console application, that shows messages using Console.WriteLine. I have a WinForms application, that runs the console application, and redirects the console output to a TextBox (using ProcessInfo.StartInfo.RedirectStandardOutput ).
When the console output contains the character 'ë' (or '\x00EB'), the TextBox shows it as '‰' (the per mille sign). In the debugger's Locals window, I see the '‰' instead of the 'ë' in the string that has to be displayed, so the error is not in the TextBox.
Why is the 'ë' changed into a '‰'? How can I get it to display correctly? I want to get rid of my current workaround, doing a Replace('‰', 'ë') , because there are other characters (like ï or é) that could cause the same kind of problem.
|
|
|
|
|
Using CharacterMap, take a look at the font that your TextBox is using and the font that the Output window is using. You'll probably see a difference right away.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I don't think so, because I already set the console and the textbox to the same font (Lucida Console). The 'ë' is character '\x00EB', the '‰' is '\x2030', and both show up correctly in the Lucida Console font (as they do in Courier New).
When I searched the string for a character '\x00EB' it just wasn't there. So it is most likely not a matter of font difference, but more a character encoding problem.
|
|
|
|
|
Correct. it has to be an encoding problem.I have never really played a lot with encodings to the console and when I did it was years back. But you might get some hints from "Console.InputEncoding" and "Console.OutputEncoding".
|
|
|
|
|
I created the following function, to try to convert console output to a string that can be displayed in a textbox.
private string ConsoleOutputToUnicode(string consoleOutput)<br />
{<br />
byte[] bConsole = Console.OutputEncoding.GetBytes(consoleOutput);<br />
byte[] bUnicode = UnicodeEncoding.Convert(Console.OutputEncoding, UnicodeEncoding.Unicode, bConsole);<br />
return UnicodeEncoding.Unicode.GetString(bUnicode);<br />
}
I tried other encodings (Default, UTF7, UTF8, UTF32) with the same result, and ASCII resulting in a '?'. Same results with ASCIIEncoding instead of UnicodeEncoding .
The byte[] bConsole is filled with the proper ASCII values ('ë' translates into a byte with the value 137). In a console (or in a message reply box in this thread) type alt-137, and you will see an 'ë'.
In bUnicode I would expect two corresponding bytes with the values 235 and zero (for \x00EB), but I get the values 48 and 32 (so \x2030, which is the per mille sign). Why is that?
One thing I discovered is that typing alt-0137 in a console also gives a '‰'. It is almost like somewhere in the conversion process the leading zero is added.
|
|
|
|
|
It was a thought. I've seen a couple noobie dev's change the font's in the IDE to some really weird ones (Star Trek types) and they wondered why something similar happened to them.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi all,
I was wondering if there is anyway that you could use Math.Round or some other method/class to round numbers off.
Basically if I have the number 19 or 256 etc I would like to round it off to the nearest ten,
ie
19 rounded to 20
256 rounded to 260
I've tried using Math.Round but that only works for decimals.
Any idea's?
TIA
Gav
|
|
|
|