c# – 我可以复制.OFT文件并更改其主题
发布时间:2020-12-15 07:41:26 所属栏目:百科 来源:网络整理
导读:我在sharepoint事件接收器中有以下代码,用于将.oft文件复制到文档库中并将其粘贴到新目标(另一个文档库)中: – SPDocumentLibrary template = (SPDocumentLibrary)properties.Web.GetList(properties.Web.ServerRelativeUrl + "/Templates/");SPListItem te
我在sharepoint事件接收器中有以下代码,用于将.oft文件复制到文档库中并将其粘贴到新目标(另一个文档库)中: –
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文件,并修改其主题(按主题我的意思是我的电子邮件主题)? 解决方法
您可以使用Interop.
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的其他用户,请添加参考. 参考文献>添加参考> COM> Microsoft Outlook 15.0对象库 更新 由于我没有SharePoint(或曾经使用过它),我无法测试它.但也许像这样的东西可以工作吗?使用SPListItem的Url来获取正确的文件.您还可以尝试在this post中看到的绝对URL.使用该字符串加载文件以进行编辑. 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; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails – 未定义的局部变量或方法`root_path’
- c – 在OpenCv中计算cv :: Mat的外(张量)乘积
- dojo(四):ajax请求
- ruby – <<和=有什么区别?
- appcompat_v7/res/values-v21/themes_base.xml No resource
- 将XML从URL解析为python对象
- ruby-on-rails – 在rails中改变一周的第一天
- xml – 有没有办法阻止Eclipse(3.7)搞乱标签内容?
- c – LINUX下AIX上的’what’命令是什么
- Postgresql 9.1 配置文件,多了好多东西耶,一起学习一下