Привет, я читал об областях формы за последнюю неделю. Мне наконец-то удалось создать новую интерактивную форму, используя элементы управления Windows (я не рекомендовал формы с vbscript). В конце концов, мне нужно связать новую отдельную форму с определеннойкалендарь из кода c # ...
но давайте перейдем к коду ... Вот как я это сделал, используя формы outlook-vbscript. ( с использованием ofts ):
private bool CreateCustomCalendar(string registryname, string newCalendarName, string outlookformpathandfilename)
{
app = this.Application;
Outlook.MAPIFolder primaryCalendar = (Outlook.MAPIFolder)
this.Application.ActiveExplorer().Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderCalendar);
bool needFolder = true;
if (debugmode) writer.WriteToLog("RootCalendar :" + primaryCalendar.Name + " found");
Outlook.MAPIFolder personalCalendar = primaryCalendar
.Folders.Add(newCalendarName,
Outlook.OlDefaultFolders.olFolderCalendar);
personalCalendar.Name = newCalendarName;
if (debugmode) writer.WriteToLog("Creating Calendar stage1 complete");
//Access new calendar by its name that has the habit to append this computer only
bool notfound1 = true; bool notfound2 = true;
try
{
string mName = primaryCalendar.Folders[newCalendarName].Name;
if (debugmode) writer.WriteToLog("calendar accesible by name:" + mName);
notfound1 = false;
}
catch (SystemException sex)
{
throw;
}
Outlook.MAPIFolder setcalendar = primaryCalendar.Folders[newCalendarName];
if (debugmode) writer.WriteToLog("calendar is set");
PublishFormToPersonalFormsLibrary(setcalendar, outlookformpathandfilename, registryname, registryname, registryname, registryname + "version 1.0.0.1", "1.0.0.1", Application);
if (debugmode) writer.WriteToLog("Creating Calendar stage2 complete");
SetFolderDefaultForm_forappointments(setcalendar, "IPM.Appointment." + registryname, newCalendarName);
if (debugmode) writer.WriteToLog("Creating Calendar stage3 complete");
return needFolder;
}
void SetFolderDefaultForm_forappointments(Outlook.MAPIFolder fld, string msgClass, string displayname)
{
Outlook.PropertyAccessor objPA = fld.PropertyAccessor;
string strBaseType;
string strMsg;
int intLoc;
bool blnBadForm;
int i;
string PR_DEF_POST_MSGCLASS =
"http://schemas.microsoft.com/mapi/proptag/0x36E5001E";
string PR_DEF_POST_DISPLAYNAME =
"http://schemas.microsoft.com/mapi/proptag/0x36E6001E";
string[] arrSchema = { PR_DEF_POST_MSGCLASS, PR_DEF_POST_DISPLAYNAME };
string[] arrValues = { msgClass, displayname };
string[] arrErrors;
if (debugmode) writer.WriteToLog("prepared for setting default item");
try
{
objPA = fld.PropertyAccessor;
objPA.SetProperty(PR_DEF_POST_MSGCLASS, msgClass);
objPA.SetProperty(PR_DEF_POST_DISPLAYNAME, displayname);
if (debugmode) writer.WriteToLog("default folder set");
// arrErrors = objPA.SetProperties(arrSchema, arrValues);
}
catch (SystemException sex)
{
Console.WriteLine("This is catch with system exception : {0}", sex.ToString());
}
}
public void PublishFormToPersonalFormsLibrary(Outlook.MAPIFolder calendarfolder, string oftFilePath, string messageClass, string name, string displayName, string description, string version, Outlook.Application application)
{
object missing = System.Reflection.Missing.Value;
string existingVersion = "";
// try to create an existing Instance of the Form to check the current installed Version
try
{
// create atemplatefolder object
Outlook.MAPIFolder templateFolder = application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderDrafts);
if (debugmode) writer.WriteToLog("templateFolder is set");
// we add our new object here
object existingItem = templateFolder.Items.Add(messageClass);
if (debugmode) writer.WriteToLog("added form " + messageClass + " as templates");
// did we installed the form
if (existingItem != null)
{
// yes, we did it before
// get the formdescription with latebinding
Type existingItemType = existingItem.GetType();
Outlook.FormDescription existingFormDescription = (Outlook.FormDescription)existingItemType.InvokeMember("FormDescription", System.Reflection.BindingFlags.GetProperty, null, existingItem, null);
if (debugmode) writer.WriteToLog("formdescription allocated to existingformdescription");
// get the installed version
existingVersion = existingFormDescription.Version;
// discard the temporary item
object[] args = { Outlook.OlInspectorClose.olDiscard };
existingItemType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, existingItem, args);
if (debugmode) writer.WriteToLog("GarbageCollection");
}
}
catch (System.Exception ex)
{
}
// if the existing Version is equal, no need for publishing the form
// if (version == existingVersion) return;
// check, if the templatefile exists
if (!System.IO.File.Exists(oftFilePath)) throw new System.IO.FileNotFoundException("Form template could not be found!", oftFilePath);
// create the item from TemplateFile
object item = application.CreateItemFromTemplate(oftFilePath, missing);
if (debugmode) writer.WriteToLog("created item from template");
// get the FormDescription Property using LateBinding
Type itemType = item.GetType();
Outlook.FormDescription formDescription = (Outlook.FormDescription)itemType.InvokeMember("FormDescription", System.Reflection.BindingFlags.GetProperty, null, item, null);
// Apply some Parameters to the Formdescription
formDescription.Name = name;
formDescription.DisplayName = displayName;
formDescription.Category = "uncategorized";
formDescription.Comment = description;
formDescription.Version = version;
if (debugmode) writer.WriteToLog("Set custom form and its properties");
// Publish Form to Personal Froms Library
//formDescription.PublishForm(Microsoft.Office.Interop.Outlook.OlFormRegistry.olPersonalRegistry );
formDescription.PublishForm(Microsoft.Office.Interop.Outlook.OlFormRegistry.olFolderRegistry, calendarfolder);
if (debugmode) writer.WriteToLog("associating complete");
}
вопрос в том, как это сделать с областями форм ( с использованием .ofs )
любые решения \ документация приветствуются.Огромное спасибо создателям переполнения стека за этот замечательный ресурс и всем разработчикам, которые альтруистически способствуют нашим проблемам