我可以复制.OFT文件并更改其主题吗 [英] Can i copy a .OFT file and change its Subject

查看:99
本文介绍了我可以复制.OFT文件并更改其主题吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的sharepoint事件接收者中有以下代码,可以将.oft文件复制到文档库中,然后将其粘贴到新的目标位置(另一个文档库)中:-

I have the following code inside my sharepoint event reciever to copy a .oft file inside a document library and paste it inside a new destination (another document library):-

SPDocumentLibrary template = (SPDocumentLibrary)properties.Web.GetList(properties.Web.ServerRelativeUrl + "/Templates/");
SPListItem templetefile = null;

foreach (SPListItem i in template.Items)
{
    if (i.Name.ToLower().Contains("project"))
    {
         templetefile = i;    
    }
}

byte[] fileBytes = templetefile.File.OpenBinary();
string destUrl = properties.Web.ServerRelativeUrl + "/" + projectid.RootFolder.Url +".oft";
SPFile destFile = projectid.RootFolder.Files.Add(destUrl, fileBytes, false);

现在我的代码运行良好.但是我不确定在复制.OFT文件后是否可以访问它并修改其主题(按主题我是指我通过电子邮件发送主题)??

now my code is working well. but i am not sure if i can access the .OFT file after its being copied, and modify its subject (by subject i mean i email subject) ??

推荐答案

您可以为此使用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;
    }
}

这篇关于我可以复制.OFT文件并更改其主题吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆