|
Well, you can't interrogate a single server without permissions to do so, and you're usually not going to have those.
Like Pete showed, if the machine your code is running on is part of the domain, you can just ask the domain for it's list of available domain controllers within reach of your machine.
But, it's even simpler than that. The fact that your machine is joined to a domain means there's at least one domain controller, and hence, Active Directory exists, or at least existed when the machine was joined to the domain.
If GetCurrentDomain doesn't return anything, well, there's no domain and hence, no Active Directory.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Excellent, thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I suppose one way would be to interrogate the domain controllers. Something like this might work:
public bool IsDomainEnabled()
{
return Domain.GetCurrentDomain()?.DomainControllers.Any() ?? false;
} Note, I just typed this off the top of my head so there may be a syntax error or two in there.
This space for rent
|
|
|
|
|
Hi,
I am creating a simple application for drag & drop. I am using Windows 10 OS, Visual Studio 2015 & creating windows application using c#.
I have added pannel on the form. AllowDrop is true for the panel.
I have added 3 events from event windows for Panel : private void panel1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void panel1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
}
But it is not allowing me to drop files here. Please let me know what is wrong with the code.
Gaurav Goyal
|
|
|
|
|
I just duplicated what you did, and it works fine for me - a breakpoint on the panel DragDrop event handler gets hit, and I appear to have data.
Check what you are dragging, and where you are dragging it from, as well as checking that the events are hooked to the handlers.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I am just dragging a text file & dropping here.
Gaurav Goyal
|
|
|
|
|
And what happened?
What code did you use to get the file that was dropped, and what happened when you tried - remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OK, what did you expect to happen?
That code works perfectly fine, but since your DragDrop event handler is empty, nothing is going to happen when you release the mouse. YOU have to supply the code to process whatever data is being dropped on the control. The Panel control has no clue what you want to happen with these files being dropped.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
I put some sample code there. but still not working. I am just dragging a text file from windows explorer & dropping here.
Gaurav Goyal
|
|
|
|
|
And that still doesn't explain what you think was going to happen or want to happen.
We also can't see the code you put in the Drop event handler.
Without being able to see the code, it's IMPOSSIBLE to tell you what you're doing wrong and/or how your expectations need to change.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Are you running the application in admin mode? Windows 10 blocks drag&drop for security reasons under circumstances.
|
|
|
|
|
Hallo,
I got external PHP webservice link, and need to consume that webservice in my C# application.
PHP webservice takes fromDate field, type of DateTime in format
"yyyy-MM-dd HH:mm:ss"
But when I send it from my C# app it sends in format
"yyyy-MM-ddTHH:mm:ss"
This "T" cause an error: Fromdate must be date or datetime.
I have tried to convert date in another format, but it still sends the same.
Did anyone had problems with this?
|
|
|
|
|
You did not showed your code to create the timestamp string.
Use
DateTime.ToString("yyyy-MM-dd' 'HH:mm:ss", CultureInfo.InvariantCulture); to create a string in the required format with a space instead of the 'T'.
|
|
|
|
|
Hallo,
Thank you for your reply.
This is fine to convert it to string, but however I need to convert it back to DateTime to send it in the webservice request.
I have tried this code
DateTime myDate = DateTime.ParseExact(date, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
To convert it back to DateTime but it contains "T" again after converting:
"yyyy-MM-ddTHH:mm:ss"
|
|
|
|
|
A DateTime is a binary object containing a time stamp. It does not know anything about a specific date format. Therefore, it is recommended to use such whenever possible.
If you parse a datetime string without error, you have a valid binary representation.
So
Quote: To convert it back to DateTime but it contains "T" again after converting: makes no sense. After converting a string representation to a DateTime it does not contain a 'T' because it is a binary value.
If you have an output of the form "yyyy-MM-ddTHH:mm:ss" somewhere, the DateTime binary value has been converted to a string again. If you don't want the 'T', you have to replace it with a space in the format string used to convert the value.
Similar applies to floating point values for example. You have a binary value. That can be converted to a string using different precisions (digits after the decimal point), scientific format (with exponent), and different (locale dependant) decimal points. These strings might be different but the binary value is still the same.
So don't care about the string representation if you can pass such values in a binary format. If you have to pass them as strings, you have to ensure that the receiver (parse string) uses the same format as used by the the sender to create the string.
|
|
|
|
|
Hi everybody,
I would like to dynamically create a user control which consists in a dialog box whose content depends on the next step to be executed.
That user control will dynamically be loaded (with the relevant parameters) at runtime into a dock panel in the application WPF user interface.
Has somebody an idea on how to proceed?
Xaml code:
<dockpanel margin="5" grid.row="2" grid.column="0" grid.columnspan="2"
="" name="SequencePopUpWindow">
Xaml.cs code:
public SeqPopUpWindow(string sequenceName, string messageToDisplay)
{
UserControl dynamicUserControl = new UserControl();
dynamicUserControl.Width = 200;
dynamicUserControl.Height = 200;
dynamicUserControl.Background = new SolidColorBrush(Colors.WhiteSmoke);
dynamicUserControl.Name = sequenceName;
TextBox textBox = new TextBox();
textBox.Text = messageToDisplay;
textBox.IsReadOnly = true;
WrapPanel wrapPanel = new WrapPanel();
wrapPanel.MinWidth = 60;
Thickness margin = wrapPanel.Margin;
margin.Left = 0;
margin.Top = 0;
margin.Right = 10;
margin.Bottom = 0;
wrapPanel.Margin = margin;
Button btnDialogOk = new Button();
btnDialogOk.MinWidth = 60;
btnDialogOk.Content = "Ok";
Button btnDialogCancel = new Button();
btnDialogOk.MinWidth = 60;
btnDialogOk.Content = "Ok";
wrapPanel.Children.Add(btnDialogOk);
wrapPanel.Children.Add(btnDialogCancel);
wrapPanel.Children.Add(textBox);
dynamicUserControl.Content = wrapPanel;
}
But when I call this method using the lines displayed below:
SeqPopUpWindow uc = new SeqPopUpWindow("Hot Boxes","Proceed to speed restriction?");
SequencePopUpWindow.Children.Add(uc);
the built control is not displayed in the user interface at run time.
RV
modified 4-Dec-17 6:23am.
|
|
|
|
|
|
Why can't you design the user control (ostensibly in the designer), and then instantiate/display it where it's needed?
Also, if you want it to be a window, I would start with a window instead of a user control. A window can be reduced to no border or title bar if that's what you want.
If you want it in a panel that is only displayed under certain conditions, simply place the usercontrol in the parent container, and collapse the parent container when you don't want it to be displayed.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Here is another idea, change the collection serving a single combobox. Data is quicker than UI!
I would have a collection of an ID/Display class and just reload it in the VM according to the parameters.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
When you add controls on-the-fly, the Visibility can default to hidden; "panels" may not expand; and / or you need to "redo the layout". There's also the question of how you defined / added content to the "window"; which you did not show. Lots of potential failure points.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
The EditorFor method in MVC allows you to pass route parameters without specifying the type that contains the parameters, like so:
@Html.EditorFor(action, controller, new { id=1, otherparam="testing" })
I don't know what the technique is actually called, so I my google searches were fruitless. How does the method know how to deal with the random properties?
The best I could come up with was a strongly typed dictionary class that is best used to handle intrinsic types, like so:
@Html.EditorFor(action, controller, new Properties(){ {"id",1}, {"otherparam","testing"} })
I use the properties by calling the Property object's GetValue method like so:
int id = property.GetValue("id", -1);
-1 is a default value that is returned if the specified key does not exist, or if its value can't be cast to the type represented by the left side of the expression.
I tried looking at ExpandoObject, anonymous types, and that kind of thing, but coldn't really find a way to do what they are doing .
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 3-Dec-17 15:35pm.
|
|
|
|
|
Hi JSOP,
they keep adding sugar coating to C#, what you have seems to be an example of Anonymous Types[^]
Not my cup of < T >.
If you want to know the internal techniques I would suggest you use ILDASM, ILspy or some similar tool, or start wading through the .NET source code itself.
modified 3-Dec-17 17:42pm.
|
|
|
|
|
Luc Pattyn wrote: Not my cup of < T >.
I love a good pun, but this might have caused a small organ rupture on viewing.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
You probably found it out by now, but you could build your own function that can receive it as well:
c# - How to pass anonymous types as parameters? - Stack Overflow[^]
the code from the link:
var query = from employee in employees select new { Name = employee.Name, Id = employee.Id };
LogEmployees(query); and the function:
public void LogEmployees (IEnumerable<dynamic> list)
{
foreach (dynamic item in list)
{
string name = item.Name;
int id = item.Id;
}
}
|
|
|
|
|
I'm trying to do this:
SomeRandomMethod(blah, blah, new { id=1,mystring="text"})
and when I get here:
public void SomeRandomMethod(dynamic obj)
{
int id = obj.id;
string text = obj.mystring;
}
the code throws exceptions because the properties don't exist.
Some might say, create a class with the same properties and cast it in the method, but then what's the point? If it's gotta be strongly typed, then it should be strongly typed where you're creating the instance (IMHO).
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|