代码片段如下:
方法一(文档库):
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 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 + "'/>";
}
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 + "'/>";
}