I want to set MaxPasswordAge Property of a DirectoryEntry object. I believe it is of type IADSLargeInteger. Now i want to set it to some value programatically. How do i convert a timespan to IADSLargeInteger. Eg. If i want to set it as 10 days how do i do it. Setting it Directly doesnt work.
DirectoryEntry child = new DirectoryEntry("LDAP://" + domain);
child.Properties["minPwdAge"].Value = ...
How do i set that value to n days? Any help is appreciated.
I don't believe you can actually write to this property. In any case, you want to get this in FileTime format which a DateTime object will give you as a property off of it.
Related
I am trying to search for appointment on a shared calendar. The first step is I am saving the appointment in shared calendar with a custom property twMeetingId. This is working fine:
Outlook.AppointmentItem nurseAppointment = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetSharedDefaultFolder(recepient, Outlook.OlDefaultFolders.olFolderCalendar).Items.Add();
nurseAppointment.UserProperties.Add("twMeetingId", Outlook.OlUserPropertyType.olText, false, 1);
nurseAppointment.UserProperties["twMeetingId"].Value = appointmentData.meetingId;
nurseAppointment.Save();
Then I am trying to find any appointments in the same shared calendar based on the custom property twMeetingId
var filter = $"#SQL =\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/twMeetingId/0000001f\" = '{appointmentData.meetingId}'";
Outlook.Items items = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetSharedDefaultFolder(recepient, Outlook.OlDefaultFolders.olFolderCalendar).Items.Restrict(filter);
At this point I am receiving an error "Condition not valid". I have checked the meetingId value is correct in the filter. I have also tried to use Jet query as below but it also does not work:
nurseAppointment = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetSharedDefaultFolder(recepient, Outlook.OlDefaultFolders.olFolderCalendar).Items.Find(String.Format("[twMeetingId] = '{0}'", appointmentData.meetingId));
What am I missing here?
You have an erroneous space between #SQL and =. The following condition worked without error for me:
#SQL="http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/twMeetingId/0000001f" = 'test'
Also make sure appointmentData.meetingId does not contain any characters that need to be encoded.
Looks like you have got a wrongly composed search string in the code:
var filter = $"#SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/twMeetingId\" = '{appointmentData.meetingId}'";
First, as you can see you need to use a single curly braces in the search string.
Second, you need to remove the property type in the end of DASL property name.
If you want to use the property name without DASL namespaces like that:
"[twMeetingId] = '{0}'"
You need to make sure the property is added to the folder fields when you call UserProperties.Add method. The AddToFolderFields parameter is true if the property will be added as a custom field to the folder that the item is in. This field can be displayed in the folder's view. alse if the property will be added as a custom field to the item but not to the folder. The default value is True.
You may find the Filtering Items Using Query Keywords article helpful.
I'm building a C# object to add more strongly typed properties to a web app that accepts all of its parameters as strings. This web app displays all of a record's current values on the left, with blank fields on the right. If you leave a text input field blank, it leaves the corresponding value in the database unchanged. If you enter a new value, on submit it changes the corresponding value to the new value you entered.
In the app, date fields are entered in MM/dd/yyyy formatted strings. I have created DateTime equivilents in my C# object and use .ToString("MM/dd/yyyy") when sending them to the web app.
public DateTime NewHireDate
{
get
{
return (DateTime.TryParse(NewValue11, out dateValue) ? dateValue : DateTime.MinValue);
}
set
{
NewValue11 = value.ToString("MM/dd/yyyy");
}
}
One wrinkle is that the web app allows a user to enter "*BLANK" to essentially null out the value that's in the date field. I would like to extend that exact ability to my object by allowing the string "*BLANK" to be assigned as a value to my date property.
How would I redefine the NewHireDate property as a String so I could use myObject.NewHireDate = "*BLANK"?
As people said on the comments, u could use the type
Datetime?
instead of Datetime.
This allows you to set an Datetime property the NULL value.
You can complete this by creating methods on the class to convert these strings into DateTime format.
Reference: https://msdn.microsoft.com/en-us/library/2cf62fcy(v=vs.140).aspx
I'm trying to add a renewal system where the user can request for extra days. I've tried to layout a a method which will take the value from a combobox and then add that value in days to the current expiry date.
As can be seen in the screen shot below, I'm having an error when trying to add days onto an existing date. I tried various SqlDbTypes including datetime with no success, maybe this isn't the best way to convert the value to days in terms of SQL?
Any ideas?
DATEADD function takes int as a second parameter. But you try to add your #days parameter with SqlDbType.VarChar type.
Add this parameter value as an SqlDbType.Int and parse your cboDays.Text to integer. For example;
com.Parameters.Add("#days", SqlDbType.Int).Value = Int32.Parse(cboDays.Text);
Also your UserID seems like a numeric column typed since it ends with ID. In this case, VarChar type does not fit for this column.
I'm new to date timepickers. I was wondering if someone could explain them to me properly. I have a booking system that you must be able to book a date and specific time in the future and reserve that time frame in a sql database. Can I do it with date timepickers? It has a nice interface when its on my form but I cant see a way for the user to set the time? it always just gives me the default time. Any help? thanks
http://imgur.com/arZPxA5
The DateTimePicker-Control has a Format-Property, which will set the format of the date and time displayed in the control.
AS stated in this answer you can use following format to show Date and time:
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MM.dd.yyyy hh:mm:ss";
Here you can get a list of all format string and their descriptions:
List of CustomFormat-String
The result will look like this:
.NET also has a structure called DateTime to save your selected value.
You can save it with following code
DateTime yourSelectedDateTime = dateTimePicker1.Value;
textBox1.Text = yourSelectedDateTime.ToString();
Date Time pickers are pretty useful to use when you want people to be able to visually select a date/time. once the user selects a datetime, you can access it like this
int mymonth = this.datetimepicker1.Value.Month
int myday = this.datetimepicker1.Value.day
etc...
Furthermore, you can use events to trigger when stuff happens with them. So for instance, they select a date, you can use the ValueChanged event to make other fun stuff happen too.
How can I set a DateTimePicker control to a specific date (yesterday's date) in C# .NET 2.0?
Just need to set the value property in a convenient place (such as InitializeComponent()):
dateTimePicker1.Value = DateTime.Today.AddDays(-1);
If you want to set a date, DateTimePicker.Value is a DateTime object.
DateTimePicker.Value = new DateTime(2012,05,28);
This is the constructor of DateTime:
new DateTime(int year,int month,int date);
My Visual is 2012
You can set the "value" property
dateTimePicker1.Value = DateTime.Today;
Can't figure out why, but in some circumstances if you have bound DataTimePicker and BindingSource contol is postioned to a new record, setting to Value property doesn't affect to bound field, so when you try to commit changes via EndEdit() method of BindingSource, you receive Null value doesn't allowed error.
I managed this problem setting direct DataRow field.
This oughta do it.
DateTimePicker1.Value = DateTime.Now.AddDays(-1).Date;
Use the Value property.
MyDateTimePicker.Value = DateTime.Today.AddDays(-1);
DateTime.Today holds today's date, from which you can subtract 1 day (add -1 days) to become yesterday.
DateTime.Now, on the other hand, contains time information as well. DateTime.Now.AddDays(-1) will return this time one day ago.
Also, we can assign the Value to the Control in Designer Class (i.e. FormName.Designer.cs).
DateTimePicker1.Value = DateTime.Now;
This way you always get Current Date...
dateTimePicker1.Value = DateTime.Today();
FYI: If you are setting the value, and not seeing anything - you might check to see if you have a 'CustomFormat' set - I just hit this and it was set to ' ' for the 1/1/1900 value (our 'not set' value) and set to MM/dd/yyyy if not.