且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以复制.OFT文件并更改其主题吗

更新时间:2023-12-05 14:35:04

您可以为此使用Interop.

You can use Interop for that.

using Microsoft.Office.Interop.Outlook;

Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();    
MailItem mail = application.CreateItemFromTemplate("oldfile.oft") as MailItem;

mail.BodyFormat = OlBodyFormat.olFormatHTML;
mail.Subject = "New Subject";
mail.HTMLBody = "<p>This is a new <strong>OFT</strong> file with a changed subject line.</p>";
mail.SaveAs("newfile.oft");

对于在Visual Studio中找不到Interop的其他用户,请添加参考.

For other users who cannot find Interop in Visual Studio, add a Reference.

引用> 添加引用> COM > Microsoft Outlook 15.0对象库

更新

由于我没有SharePoint(或从未使用过SharePoint),因此无法对此进行测试.但是也许这样的事情可以工作吗?使用 SPListItem Url 获取正确的文件.您也可以尝试使用

Since I do not have SharePoint (or ever worked with it), I cannot test this. But maybe something like this can work? Use the Url of the SPListItem to get the correct file. You could also try the absolute url as seen in this post. Use that string to load the file for editing.

foreach (SPListItem i in template.Items)
{
    if (i.Name.ToLower().Contains("project"))
    {
        string url = i.Url;
        string absoluteUrl = (string)i[SPBuiltInFieldId.EncodedAbsUrl];

        MailItem mail = application.CreateItemFromTemplate(url) as MailItem;

        //or

        MailItem mail = application.CreateItemFromTemplate(absoluteUrl) as MailItem;
    }
}