[c#]获取exchange中的图片
发布时间:2020-12-15 04:38:18 所属栏目:百科 来源:网络整理
导读:摘要 解决办法 CidPattern = span style="color: #0000ff;"private span style="color: #0000ff;"static HashSetspan style="color: #0000ff;"int BuildCidIndex(span style="color: #0000ff;"string span style="color: #000000;" html) { span style="colo
摘要
解决办法
CidPattern = <span style="color: #0000ff;">private <span style="color: #0000ff;">static HashSet<<span style="color: #0000ff;">int> BuildCidIndex(<span style="color: #0000ff;">string<span style="color: #000000;"> html)
{ <span style="color: #0000ff;">var index = <span style="color: #0000ff;">new HashSet<<span style="color: #0000ff;">int><span style="color: #000000;">(); <span style="color: #0000ff;">var pos = html.IndexOf(CidPattern,<span style="color: #800080;">0<span style="color: #000000;">); <span style="color: #0000ff;">while (pos > <span style="color: #800080;">0<span style="color: #000000;">) { <span style="color: #0000ff;">var start = pos +<span style="color: #000000;"> CidPattern.Length; index.Add(start); pos =<span style="color: #000000;"> html.IndexOf(CidPattern,start); } <span style="color: #0000ff;">return<span style="color: #000000;"> index; }
AdjustIndex(HashSet<> index, oldPos, oldIndex = List<> ( pos (pos <+<span style="color: #0000ff;">private <span style="color: #0000ff;">static <span style="color: #0000ff;">bool ReplaceCid(HashSet<<span style="color: #0000ff;">int> index,<span style="color: #0000ff;">ref <span style="color: #0000ff;">string html,<span style="color: #0000ff;">string cid,<span style="color: #0000ff;">string<span style="color: #000000;"> path)
{ <span style="color: #0000ff;">var posToRemove = -<span style="color: #800080;">1<span style="color: #000000;">; <span style="color: #0000ff;">foreach (<span style="color: #0000ff;">var pos <span style="color: #0000ff;">in<span style="color: #000000;"> index) { <span style="color: #0000ff;">if (pos + cid.Length < html.Length && html.Substring(pos,cid.Length) ==<span style="color: #000000;"> cid) { <span style="color: #0000ff;">var sb = <span style="color: #0000ff;">new<span style="color: #000000;"> StringBuilder(); sb.Append(html.Substring(<span style="color: #800080;">0,pos-<span style="color: #000000;">CidPattern.Length)); sb.Append(path); sb.Append(html.Substring(pos +<span style="color: #000000;"> cid.Length)); html =<span style="color: #000000;"> sb.ToString();
}
FileAttachment[] attachments = index = (index.Count > && item.Attachments.Count > basePath = attachments </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> FileAttachment[item.Attachments.Count];
</span><span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> i = <span style="color: #800080;">0</span>; i < item.Attachments.Count; ++<span style="color: #000000;">i)
{
</span><span style="color: #0000ff;">var</span> type =<span style="color: #000000;"> item.Attachments[i].ContentType.ToLower();
</span><span style="color: #0000ff;">if</span> (!type.StartsWith(<span style="color: #800000;">"</span><span style="color: #800000;">image/</span><span style="color: #800000;">"</span>)) <span style="color: #0000ff;">continue</span><span style="color: #000000;">;
type </span>= type.Replace(<span style="color: #800000;">"</span><span style="color: #800000;">image/</span><span style="color: #800000;">"</span>,<span style="color: #800000;">""</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">var</span> attachment =<span style="color: #000000;"> (FileAttachment)item.Attachments[i];
</span><span style="color: #0000ff;">var</span> cid =<span style="color: #000000;"> attachment.ContentId;
</span><span style="color: #0000ff;">var</span> filename = cid + <span style="color: #800000;">"</span><span style="color: #800000;">.</span><span style="color: #800000;">"</span> +<span style="color: #000000;"> type;
</span><span style="color: #0000ff;">var</span> path =<span style="color: #000000;"> Path.Combine(basePath,filename);
</span><span style="color: #0000ff;">if</span>(ReplaceCid(index,<span style="color: #0000ff;">ref</span><span style="color: #000000;"> sHTMLCOntent,cid,path))
{
</span><span style="color: #008000;">//</span><span style="color: #008000;"> only load images when they have been found </span>
<span style="color: #000000;"> attachment.Load(path); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |