How to set a One-Time only event using DDay iCal - c#

I am trying to setup a One-Time only event using the DDay iCal library.
The FrequencyType lists the following:
public enum FrequencyType
{
None = 0,
Secondly = 1,
Minutely = 2,
Hourly = 3,
Daily = 4,
Weekly = 5,
Monthly = 6,
Yearly = 7,
}
Currently in my application the user is given options for creating a One-Time or Daily events.
For Daily this does the job:
FrequencyType.Daily
and this code:
Event evt = iCal.Create<Event>();
RecurrencePattern rp = new RecurrencePattern(frequencyType);
evt.RecurrenceRules.Add(rp);
I have removed other details for brevity.
How do I go about setting a One-Time only event?

Related

ICAL .NET Remove or Delete Event

I am using https://github.com/rianjs/ical.net with .Net 6 API. I am able to create an event like below.
var calendar = new Calendar();
calendar.AddTimeZone(new VTimeZone("America/Chicago"));
var icalEvent = new CalendarEvent
{
Summary = "David's vacation days",
Description = "Description for event",
Start = new CalDateTime(2022, 12, 12, 15, 0, 0),
End = new CalDateTime(2022, 12, 12, 16, 0, 0)
};
calendar.Events.Add(icalEvent);
var iCalSerializer = new CalendarSerializer();
result = iCalSerializer.SerializeToString(calendar);
This creates a .ics file, opening which creates an event in the calendar.
BEGIN:VCALENDAR PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN VERSION:2.0 BEGIN:VTIMEZONE TZID:America/Chicago X-LIC-LOCATION:America/Chicago END:VTIMEZONE BEGIN:VEVENT DESCRIPTION:Description for event DTEND:20221212T160000 DTSTAMP:20221213T184639Z DTSTART:20221212T150000 SEQUENCE:0 SUMMARY:David's vacation days UID:4aca19e6-a7a8-426c-a488-c2abf789c395 END:VEVENT END:VCALENDAR
I see that if I edit the file and add METHOD:CANCEL, SEQUENCE:1, it opens in outlook with 'Remove from calendar'.
Now, how to do this remove event programmatically? I am hoping iCAL has something instead of me serializing the event to string and add the method etc. to that string manually.

iCal client support for multiple event requests

When a user signs up on our website, I'd like to send them an email that allows them to automatically update their calendar with the classes they have enrolled in. In most cases this will be multiple days/events.
As a test I'm using DDay.ical to create a multi-event request. However, it doesn't seem like either Outlook or the iPhone mail app notices the second event in the ical attachment.
I know that multiple events are supported in the iCal standard. How that doesn't mean that all clients support that scenarios. Do other clients support multi-event ical requests?
I don't think I'm doing anything wrong in code, but I'll post my code fragment to be sure:
// Create event part.
iCalendar iCal1 = new iCalendar();
iCal1.AddLocalTimeZone();
iCal1.Method = "REQUEST";
Event evt1 = iCal1.Create<Event>();
evt1.Start = new iCalDateTime(new DateTime(2014, 8, 4, 12, 30, 00, DateTimeKind.Local));
evt1.End = evt1.Start.AddMinutes(30);
evt1.IsAllDay = false;
evt1.Summary = string.Format("Lesson - {0}", evt1.Start.ToString("MM/dd"));
evt1.Location = "Anytown";
// Add recipients for appointment.
Attendee att1 = new Attendee("mailto:" + "me#MyDomain.com");
att1.RSVP = false;
att1.CommonName = "Me Jones";
evt1.Attendees.Add(att1);
Event evt2 = iCal1.Create<Event>();
evt2.Start = new iCalDateTime(new DateTime(2014, 8, 11, 12, 30, 00, DateTimeKind.Local));
evt2.End = evt1.Start.AddMinutes(30);
evt2.IsAllDay = false;
evt2.Summary = string.Format("Lesson - {0}", evt2.Start.ToString("MM/dd"));
evt2.Location = "AnyTown";
// Add recipients for appointment.
Attendee att2 = new Attendee("mailto:" + "me#MyDomain.com");
att2.RSVP = false;
att2.CommonName = "Me Jones";
evt2.Attendees.Add(att2);
iCalendarSerializer serializer1 = new iCalendarSerializer();
string t = serializer1.SerializeToString(iCal1);
Byte[] bytes = System.Text.Encoding.ASCII.GetBytes(t);
using (var ms = new System.IO.MemoryStream(bytes))
{
using (var a = new System.Net.Mail.Attachment(ms, "meeting.ics", "text/calendar")) //Either load from disk or use a MemoryStream bound to the bytes of a String
{
a.ContentDisposition.Inline = true; //Mark as inline
msg.Attachments.Add(a); //Add it to the message
Mailer.Send(msg);
}
}
Unfortunately, you're completely dependent on the implementation of Icalendar in the various email clients, and these are generally very protective of their users' calendars. They generally all support multi-event Icalendars, but invitations that "go straight in" to a users calendar have to be sent one event at a time. I'm not aware of any exceptions to this.
To process an Icalendar attachment containing more than one event, in Outlook for example, you need to save the attachment to disk, navigate to it and open it. It then opens as a separate calendar, and you need to drag the events one by one into your calendar. Nightmare. This will rarely be worth the trouble to develop.
Another option of course is to host the Icalendar on your website and get your users to subscribe by entering the calendar URL in their client. This has the advantage that changes propagate automatically, but email clients will still treat the events as external (no automatic reminders, in outlook the default is to display them in a separate pane, Gmail at least displays events from different calendars on the same grid.)

(p4 api .NET) Setting multiple ClientOption members

Currently when viewing my client settings, the Options field is "noallwrite noclobber nocompress unlocked nomodtime normdir." I would like to check the compress and rmdir fields using the p4 api. There is code to do each individually:
client.Options = ClientOption.Compress;
client.Options = ClientOption.RmDir;
However, after looking at the api and online, I cannot find a way to do both at the same time. I can easily go into P4V and check both of these boxes, but I am trying to do it using the p4 api to make setup easier for future workspaces/clients. Any ideas?
Since the options in p4 options are flags
[Flags]
public enum ClientOption
{
None = 0,
AllWrite = 1,
Clobber = 2,
Compress = 4,
Locked = 8,
ModTime = 16,
RmDir = 32,
}
You can pile them them up to get the expected result like this
P4.Client client = this.Repository.GetClient(clientname, null);
string options= "noallwrite clobber nocompress unlocked nomodtime rmdir";
client.Options = new P4.ClientOption();
if (!options.Contains("noallwrite"))
{
client.Options |= P4.ClientOption.AllWrite;
}
if (!options.Contains("noclobber"))
{
client.Options |= P4.ClientOption.Clobber;
}
.....
Hope this helps!.

How to use Shell32 within a C# application?

What should I include within a C# application in order to make Shell32 work?
Edit:
My application can't recognize shell32. What references or lib should I include? What I'm trying to do is:
Shell32.Shell shell = new Shell32.Shell();
What I'm getting as an error:
Error 1 The type or namespace name 'Shell32' could not be found (are you missing a using directive or an assembly reference?)
Just add a reference to Shell32.dll from the Windows\System32 folder and use it:
Shell32.Shell shell = new Shell32.Shell();
shell.MinimizeAll();
maybe this can help:
Right click project
Click Add reference
Click .COM tab in Add reference dialogue
Select Microsoft Shell Controls and Automation
Click OK
your shell32 is ready to use...
I know this thread is old, but I post this for anyone having the same problem as I did. The solution above does not compile under windows 8
Shell32.Shell shell = new Shell32.Shell(); <= this doesn't work with windows 8
Use the work around below if you want your apps to run under windows 8.
using Shell32;
private Shell32.Folder GetShell32Folder(string folderPath)
{
Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
Object shell = Activator.CreateInstance(shellAppType);
return (Shell32.Folder)shellAppType.InvokeMember("NameSpace",
System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { folderPath });
}
Right click your project in the solution explorer.
Choose "Add Reference..." from the drop-down menu.
Click the "Browse" tab.
Navigate to the C:\Windows\System32 directory.
Choose the shell32.dll file. and press the "OK" button.
You now have the appropriate reference for using Shell32.Shell.
Add to your project a reference to the COM library Microsoft Shell Controls and Automation. Additionally, ensure that the code using Shell32.Shell is running in a single threaded apartment, e.g. by adding the [STAThread] attribute to Main.
I'm guessing that you're having trouble getting any calls recognized, so I'd refer you to this general article: http://www.codeproject.com/KB/shell/csdoesshell1.aspx
Beyond that, you'll need to provide specifics of what isn't working for you.
The class shown below should help with some of the methods of shell32 in C# .
you should add the reference of "Microsoft Shell command and automation" with the reference window by righting clicking the project .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MusicMuttPrototype
{
public class clsShellFileInfo
{
public Exception errorException;
public enum FileDetailInfo
{
Name = 0,
Year = 15,
Size = 1,
Track_Number = 19,
Type = 2,
Genre = 20,
Date_Modified = 3,
Duration = 27,
Date_Created = 4,
Bit_Rate = 28,
Date_Accessed = 5,
Protected = 23,
Attributes = 6,
Camera_Model = 24,
Status = 7,
Date_Picture_Taken = 25,
Owner = 8,
Dimensions = 26,
Author = 9,
Not_used = 27,
Title = 10,
Not_used_file = 28,
Subject = 11,
//Not_used = 29,
Category = 12,
Company = 30,
Pages = 13,
Description = 31,
Comments = 14,
File_Version = 32,
Copyright = 15,
Product_Name_Chapter = 33,
//Scripting Quicktest Profess11ional Page 63
Artist = 16,
Product_Version = 34,
Album_Title = 17,
Retrieves_the_info_tip_inf = -1
}
public string getFileDetails(string fileFolder, string filePath, FileDetailInfo infotype)
{
string strReturnval = "";
try
{
Shell32.Shell fileshell = new Shell32.Shell();
Shell32.Folder fileshellfolder = fileshell.NameSpace(fileFolder);
Shell32.FolderItem Item = fileshellfolder.ParseName(filePath);
strReturnval = fileshellfolder.GetDetailsOf(Item, (int)infotype);
}
catch (Exception ex)
{
errorException = ex;
}
return strReturnval;
}
}
}
If you don't need the full set of API calls, you maybe better off creating a COM import stub class. See how Mike Ward who wrote Desk Drive did it.
Link 1
Link 2
C# .Net
I do not understand the full question but this is working for me.
[DllImport("Shell32.dll")]
public static extern int ShellExecuteA(int hwnd, string lpOperation, string lpFile, int lpParameters, int lpDirecotry, int nShowCmd);
private void pictureBox1_Click(object sender, EventArgs e)
{
int open;
open = ShellExecuteA(0, "open", "https://google.com", 0, 0, 1);
}
Using a picturebox to open a link.

can not save application settings in .net 3.5

I am creating a application that store basic database connection info like host,user, password and default database name in application settings using User Scope.
I am using .net 3.5 with Visual Studio 2008
I put 4 text boxes in a user control and bound their text property to the application settings individual properties.
//
// textBox_database
//
this.textBox_database.Location = new System.Drawing.Point(103, 101);
this.textBox_database.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBox_database.Name = "textBox_database";
this.textBox_database.Size = new System.Drawing.Size(255, 27);
this.textBox_database.TabIndex = 5;
this.textBox_database.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_database;
//
// textBox_password
//
this.textBox_password.Location = new System.Drawing.Point(103, 69);
this.textBox_password.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBox_password.Name = "textBox_password";
this.textBox_password.Size = new System.Drawing.Size(255, 27);
this.textBox_password.TabIndex = 4;
this.textBox_password.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_password;
this.textBox_password.UseSystemPasswordChar = true;
//
// textBox_user
//
this.textBox_user.Location = new System.Drawing.Point(103, 37);
this.textBox_user.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBox_user.Name = "textBox_user";
this.textBox_user.Size = new System.Drawing.Size(255, 27);
this.textBox_user.TabIndex = 7;
this.textBox_user.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_user;
//
// textBox_server
//
this.textBox_server.Location = new System.Drawing.Point(103, 5);
this.textBox_server.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBox_server.Name = "textBox_server";
this.textBox_server.Size = new System.Drawing.Size(255, 27);
this.textBox_server.TabIndex = 6;
this.textBox_server.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_server;
these text boxes will get user data from users to set their own database info. i have a button that saves the modified info back to the settings file
private void button_save_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Save();
}
but the design is not being saved. any help anyone?
regards,
Anjan
To Cyril: Yes i had the code to assign modified value in properties, but then even the scope was set to "User" it said readonly. So i removed the property assignment codes.
now i brought the code back and restarted VS, it works perfect now :D silly me, i should have try this old procedure before.
Thank you Cyril.
Hmm... I remember having the same problem a few months ago in one of my projects. Unfortunately I don't recall how I solved it.
Some checks...
Try setting the property scope to User in the Project Properties.
In the code you've listed I don't see where you set the property (only see you retrieving the property). Where have you set it?

Categories