|
It's when fileNamepath is @"" that the problem with using Path.GetDirectoryName happens. Maybe I'll catch the exception and if it happened, have them choose the directory or use my default dir.
|
|
|
|
|
You are doing things a little backwards.
Try this instead
if( Directory.Exists( fileNamePath ) )
{
DirectoryInfo di1 = new DirectoryInfo(fileNamePath);
}
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
I did that and didn't have to catch the extra exception! Much cleaner that way.
|
|
|
|
|
Glad I could help.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
MichCl wrote: Any ideas what the problem could be?
The short answer is poor documentation, i.e. not mentioned on MSDN.
The constructor will reject bad paths and if there is the potential for a problem I think the only solution is to do some validation on the argument. Directory.Exists must be the method of choice here as it seems to be quite resilient and returns false for paths which would cause DirectoryInfo to throw.
Bad paths may result from:
Illegal characters (this one is documented)
new DirectoryInfo(@"*");
Path format not supported. This has it's own undocumented exception which caught me out, once! Why this isn't reported as an ArgumentException is beyond me.
di = new DirectoryInfo(@"\c:\");
and the one you've found
di = new DirectoryInfo(@"");
Alan.
|
|
|
|
|
Maybe I'll just catch the exception and use the default dir in that case or bring up the Directory Browser.
|
|
|
|
|
Yes that would be the most practical solution.
I've just been looking at the FileInfo constructor documentation and to be honest MS could do themselves a favour if they copied some of the info over to the DirectoryInfo page as it mentions empty paths and the NotSupportedException for embedded ':'.
Alan.
|
|
|
|
|
get any API for get count number of hits occurred for a particular keyword date wise from Gnews,facebook and twitter.
|
|
|
|
|
..there's not a unified api available that allows you to search all these sites in a single call. You'll have to make an interface to each site, using the SDK or API's provided by them.
Facebook[^]
Twitter[^]
Google News doesn't provide an API (it's not required). but there are feeds available for non commercial use.
Bastard Programmer from Hell
|
|
|
|
|
I am making a media player. so I need tool bar and seek bar. how I get these. thanks.
|
|
|
|
|
Are you using Win Forms? Just add a toolbar and add buttons to them. What issues are you having?
|
|
|
|
|
thanks.I need seek bar and volume bar as like in new vlc player.
|
|
|
|
|
|
|
|
that is a nice link ...all code and steps are given...
|
|
|
|
|
|
|
I'm trying to create a ListBox on the fly without using any XAML code. I got it working - almost. What I have is an array of TextBoxes of 'Zone Descriptions'. I can put those into the ListBox as ListBoxItems, and it works great - no problem.
I want to add at the front of the TextBox a TextBlock or header that says 'Zone 1' or whatever the zone is along with the TextBox, which is user changeable. I have an array of TextBlocks (I probably could have had strings just as well). But, I can't (or don't know how to) adjust the ListBoxItem.Content to hold both the TextBlock and TextBox combo. LBI[i].Content = TBlkZoneDesc[i] + TBxZoneDesc[i] is what I want to do, but that syntax is not allowed. Doing either one separately works fine, but not both.
Do anyone have a suggestion on how to do that?
ListBox LBZoneDesc = new ListBox();
LBZoneDesc.Width = 300;
LBZoneDesc.Height = 240;
Grid.SetColumn(LBZoneDesc,0);
Grid.SetRow(LBZoneDesc,2);
ListBoxItem[] LBI = new ListBoxItem[64];
for (byte i = 0; i < 5; i++)
{
LBI[i] = new ListBoxItem();
LBI[i].Padding = new Thickness(2);
// LBI[i].Content = TBlkZoneDesc[i];
LBI[i].Content = TBxZoneDesc[i];
LBZoneDesc.Items.Add(LBI[i]);
}
C0Grid.Children.Add(LBZoneDesc);
|
|
|
|
|
Hello,
I have an issue in regular expression matching...
string x = "user = 'sa' password='eX65dere' server = 'localhost'";
Regex rx = new Regex("password=\'([a-zA-Z0-9]\\_+)\'");
var r = rx.Match(x);
if (r.Groups.Count > 0)
{
var g1 = r.Groups[0];
MessageBox.Show(g1.ToString());
}
while executing this, I have got the following error message. parsing "password='([a-zA-Z0-9]\_+)'" - Unrecognized escape sequence \_.
the following will work fine, when i try to add _ to the expression the exception occurs.
Regex rx = new Regex("password=\'([a-zA-Z0-9]+)\'");
Can anyone help me on this?
|
|
|
|
|
I have solved this by changing the expression as follows...
Regex rx = new Regex(@"password='([a-zA-Z0-9\\%^&_*]+)\'");
Regards
Sebastian
|
|
|
|
|
Why are you escaping the underscore character? it is a normal character as far as Regex is concerned, just like + and -
|
|
|
|
|
Snap!
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Simple. Underscore is not a metacharacter, so it doesn't need escaping (preceding with backslash).
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Got the idea, Thanks...
again i have another question... Here is my updated expression...
string x = "user = 'sa' password='e X65dere!@#$%^&*()' server = 'localhost'";
Regex rx = new Regex(@"password=\'([a-zA-Z0-9\\!@#$%^&*|() _'""*-+{}<>,.;/?:~`\[\]\\\\]+)\'");
var r = rx.Match(x);
if (r.Groups.Count > 0)
{
var g1 = r.Groups[0];
MessageBox.Show(g1.ToString());
}
In this case it will match for every small & large cap letters, numbers and special characters except = . If the password contains = the expression fails... can you please help?
modified 23-Mar-12 8:00am.
|
|
|
|