C# で .vcs ファイルを作成しようとしています。基本的に Outlook でカレンダーの予定を追加すると、Outlook では次のようなファイルが作成されます。
実際にこのファイルをエクスポートし、右クリックしてお気に入りのテキスト エディターで開くことができます。次のようになります。
BEGIN:VCALENDAR
PRODID:-//Flo Inc.//FloSoft//EN
BEGIN:VEVENT
DTSTART:6/12/2012 12:00:00 PM
DTEND:6/12/2012 1:00:00 PM
LOCATION:Meeting room 1
DESCRIPTION;ENCODING=QUOTED-PRINTABLE:Learn about assets.
SUMMARY:asset management training.
X-MICROSOFT-CDO-BUSYSTATUS:OOF
PRIORITY:5
END:VEVENT
END:VCALENDAR
だから私が問題を抱えているのは、上からの DTSTART と DTEND の実際の時間です。Outlook ファイルを開くと午前 11 時 (スクリーン ショットが示すように) と表示されていますが、テキスト ファイルでは午後 12 時と表示されています。
したがって、これらの vcs ファイルの 1 つを動的に作成するアプリケーション (トレーニング アプリケーション) があります。C# を使用して、次のように件名、場所、説明、日付 (時間付き) を収集します。
protected void btnOutlook_Click(object sender, EventArgs e)
{
string location;
string description;
string subject;
string fromTime;
string toTime;
location = txtLocation.Text;
description = txtDescription.Text;
subject = lblTitle.Text;
fromTime = ddlFromTimeHH.SelectedItem.Text + ":" + ddlFromTimeMM.SelectedItem.Text + ddlFromTimeAMPM.SelectedItem.Text;
toTime = ddlToTimeHH.SelectedItem.Text + ":" + ddlToTimeMM.SelectedItem.Text + ddlToTimeAMPM.SelectedItem.Text;
string begin = lblDate.Text + " " + fromTime;
string end = lblDate.Text + " " + toTime;
string format = "dd/MM/yyyy h:mmtt";
DateTime trainingDateBegin;
DateTime trainingDateEnd;
if (DateTime.TryParseExact(begin, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out trainingDateBegin))
{
//good date
}
if (DateTime.TryParseExact(end, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out trainingDateEnd))
{
//good date
}
OpenVCSFile("vcsFile.aspx?TrainingDateBegin=" + trainingDateBegin + "&TrainingDateEnd=" + trainingDateEnd + "&Location=" + location + "&Subject=" + subject + "&Description=" + description, "Utilities", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=500,left=10,top=20");
}
したがって、上記のコードでは、fromTime はたとえば午前 7:00 になり、toTime は午前 8:00 のようになります。次に、DateTime.TryParseExact を使用して日付を時刻とマージし、たとえば for インスタンスになり、 for インスタンス06/01/2012 7:00 am
にbeginDate
なりendDate
ます06/01/2012 8:00 am
。
これまでのところ、うまくいきました...次に、渡されたURLを開くためのJavaScriptであるOpenVCSFile関数を呼び出すだけです。
protected void OpenVCSFile(string url, string name, string att)
{
Response.Write("<script language='JavaScript'>");
Response.Write("x=window.open('" + url + "', '" + name + "','" + att + "');");
Response.Write("x.focus();");
Response.Write("</script>");
}
vcsFile.aspx
これにより、Outlook の値を入力できるページが呼び出されます...
protected void Page_Load(object sender, EventArgs e)
{
DateTime beginDate;
DateTime endDate;
string location;
string description;
string subject;
beginDate = Convert.ToDateTime(Request.QueryString["TrainingDateBegin"]);
endDate = Convert.ToDateTime(Request.QueryString["TrainingDateEnd"]);
location = Request.QueryString["Location"];
description = Request.QueryString["Description"];
subject = Request.QueryString["Subject"];
MemoryStream mStream = new MemoryStream();
StreamWriter writer = new StreamWriter(mStream);
writer.AutoFlush = true;
//header
writer.WriteLine("BEGIN:VCALENDAR");
writer.WriteLine("PRODID:-//Flo Inc.//FloSoft//EN");
writer.WriteLine("BEGIN:VEVENT");
//BODY
writer.WriteLine("DTSTART:" + beginDate); //why dont the times come out right...
writer.WriteLine("DTEND:" + endDate); //same here
writer.WriteLine("LOCATION:" + location);
writer.WriteLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + description);
writer.WriteLine("SUMMARY:" + subject);
writer.WriteLine("X-MICROSOFT-CDO-BUSYSTATUS:OOF");
//FOOTER
writer.WriteLine("PRIORITY:5");
writer.WriteLine("END:VEVENT");
writer.WriteLine("END:VCALENDAR");
//MAKE IT DOWNLOADABLE
Response.Clear(); //clears the current output content from the buffer
Response.AppendHeader("Content-Disposition", "attachment; filename=AddToOutlookCalendar.vcs");
Response.AppendHeader("Content-Length", mStream.Length.ToString());
Response.ContentType = "application/download";
Response.BinaryWrite(mStream.ToArray());
Response.End();
}
最も重要な部分、私がこれを行うセクションを除いて、すべてが機能しているように見えます。
writer.WriteLine("DTSTART:" + beginDate); //why dont the times come out right...
writer.WriteLine("DTEND:" + endDate); //same here
Outlookのスクリーンショットにあるように、日付は正しく表示されますが、時刻は常に間違っています... 通常、Outlookは午前10時から午前11時まで開きます。しかし、私が与える時間は決してかかりません。たとえば、私の C# コードでは、ウォッチ画面は次のようになります。
trainingDateBegin {12/6/2012 12:00:00 PM}
trainingDateEnd {12/6/2012 1:00:00 PM}
したがって、私のアプリは、2012 年 12 月 6 日から 12:00:00 pm まで、2012 年 12 月 6 日 1:00:00 pm の日付で渡されます。しかし、vcs ファイルがここで生成されると、結果は次のようになります。
(画像が表示されない場合、基本的に Outlook はすべて正しい情報を持っています: 件名、場所、開始日、終了日、しかし時間が間違っています。午前 11 時から午後 12 時までと表示されます。システム クロック EST を使用しているようなものです)...
私が間違っているかもしれないことを誰かが知っていますか?長文すみません(.