我可以复制.OFT文件并更改其主题
我在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 = "This is a new OFT file with a changed subject line.
"; mail.SaveAs("newfile.oft");
对于在Visual Studio中找不到Interop的其他用户,请添加参考。
References
> Add Reference
> COM
> Microsoft Outlook 15.0 Object Library
更新
由于我没有SharePoint(或曾经使用过它),我无法测试它。 但也许像这样的东西可以工作吗? 使用SPListItem
的Url
来获取正确的文件。 你也可以试试这篇文章中的绝对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; } }
如果您想避免安装/使用outlook,可以查看Aspose.Email 。
Aspose.Email for .NET是一套完整的电子邮件处理API,可与.NET Framework,.NET Core和Xamarin平台一起使用,使您能够构建跨平台应用程序,无需创建,操作,转换和传输电子邮件使用Microsoft Outlook
它也支持OFT文件
- 在HTTPS请求中,Request.IsSecureConnection返回false
- 名为response的scriptreference不再有效
- entity framework:如何表达包含的LIKE语句
- .NET Bean +请求范围 – 是否可能?
- 如何将条形码扫描器集成到ASP.NET Web应用程序中?
- 无法从GridView中的行/单元格中获取值
- 如何在Visual Studio中添加SQL Server数据库文件(.mdf)而不安装SQL Server Express Edition?
- sql语法问题和/或代码问题? “指数数组的边界之外。”
- 从1页模板生成iTextSharp高效批量Pdf