sharepoint获取文件的ICON

代码片段如下:

 方法一(文档库):

string strProgId = "SharePoint.OpenDocuments";
string icon = SPUtility.MapToIcon(listItem.Web, listItem.File.Name, strProgId, IconSize.Size16);
string iconUrl = string.Format("{0}/_layouts/images/{1}", listItem.Web.ServerRelativeUrl, icon);

方法二(列表附件):

 string strs = "";

 SPAttachmentCollection attach = item.Attachments;
  for (int i = 0; i < attach.Count; i++)
        {
         string url = attach.UrlPrefix + attach[i];
                SPFile file = web.GetFile(url);
                string iconUrl = file.IconUrl;
                strs = "<img src='/_layouts/images/" + iconUrl + "'/>";
        }
原文地址:https://www.cnblogs.com/ricky_li/p/2769634.html