博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

sharepoint获取文件的ICON

Posted on 2012-11-14 11:40  木头人Ricky  阅读(191)  评论(0编辑  收藏  举报

代码片段如下:

 方法一(文档库):

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 + "'/>";
        }