加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

[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();

        posToRemove </span>=<span style="color: #000000;"&gt; pos;
        </span><span style="color: #0000ff;"&gt;break</span><span style="color: #000000;"&gt;;
    }
}

</span><span style="color: #0000ff;"&gt;if</span> (posToRemove < <span style="color: #800080;"&gt;0</span><span style="color: #000000;"&gt;)
    </span><span style="color: #0000ff;"&gt;return</span> <span style="color: #0000ff;"&gt;false</span><span style="color: #000000;"&gt;;

index.Remove(posToRemove);
AdjustIndex(index,posToRemove,path.Length </span>- (CidPattern.Length +<span style="color: #000000;"&gt; cid.Length));

</span><span style="color: #0000ff;"&gt;return</span> <span style="color: #0000ff;"&gt;true</span><span style="color: #000000;"&gt;;

}

FileAttachment[] attachments = index = (index.Count > && item.Attachments.Count > basePath =attachments </span>= <span style="color: #0000ff;"&gt;new</span><span style="color: #000000;"&gt; FileAttachment[item.Attachments.Count]; </span><span style="color: #0000ff;"&gt;for</span> (<span style="color: #0000ff;"&gt;var</span> i = <span style="color: #800080;"&gt;0</span>; i < item.Attachments.Count; ++<span style="color: #000000;"&gt;i) { </span><span style="color: #0000ff;"&gt;var</span> type =<span style="color: #000000;"&gt; item.Attachments[i].ContentType.ToLower(); </span><span style="color: #0000ff;"&gt;if</span> (!type.StartsWith(<span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;image/</span><span style="color: #800000;"&gt;"</span>)) <span style="color: #0000ff;"&gt;continue</span><span style="color: #000000;"&gt;; type </span>= type.Replace(<span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;image/</span><span style="color: #800000;"&gt;"</span>,<span style="color: #800000;"&gt;""</span><span style="color: #000000;"&gt;); </span><span style="color: #0000ff;"&gt;var</span> attachment =<span style="color: #000000;"&gt; (FileAttachment)item.Attachments[i]; </span><span style="color: #0000ff;"&gt;var</span> cid =<span style="color: #000000;"&gt; attachment.ContentId; </span><span style="color: #0000ff;"&gt;var</span> filename = cid + <span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;.</span><span style="color: #800000;"&gt;"</span> +<span style="color: #000000;"&gt; type; </span><span style="color: #0000ff;"&gt;var</span> path =<span style="color: #000000;"&gt; Path.Combine(basePath,filename); </span><span style="color: #0000ff;"&gt;if</span>(ReplaceCid(index,<span style="color: #0000ff;"&gt;ref</span><span style="color: #000000;"&gt; sHTMLCOntent,cid,path)) { </span><span style="color: #008000;"&gt;//</span><span style="color: #008000;"&gt; only load images when they have been found </span>

<span style="color: #000000;"> attachment.Load(path);
attachments[i] =<span style="color: #000000;"> attachment;
}
}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读