Display DOC ICON in SharePoint custom page

InfoPath alternatives for form designing SharePoint

Hi Friends,

I m going to explain about how to take DOC icons from files in sharepoint library .Display the Doc icons in custom page when you bind the listitems in the page as grid or table.

Here is the steps to fetch and display DOC icom from files in sharepoint library from files in sharepoint library .

Display DOC ICON in SharePoint custom page

1. Get folder of the file

2. Loadfiles into client object.

3. Load Properties like -> DOC Icon, FileURL,File ID

Folder request = currentWeb.Lists.GetById(new Guid(listID)).GetItemById(requestID).Folder;

clientContext.Load(request, x => x.Files, x => x.Files.Include(p => p.ListItemAllFields[“DocIcon”]), x => x.Files.Include(p => p.ListItemAllFields[“EncodedAbsUrl”]), x => x.Files.Include(p => p.ListItemAllFields.Id));

clientContext.ExecuteQuery();

Get all files from folder location .

foreach (File file in request.Files)

{

//Add file Icon

Image dociconImage = new Image();

var imageUrl = clientContext.Web.MapToIcon(f.Name, String.Empty, Microsoft.SharePoint.Client.Utilities.IconSize.Size16);

clientContext.ExecuteQuery();

dociconImage.ImageUrl = string.Format(“{1}/_layouts/images/{0}”, imageUrl.Value, SecurityHelper.getQueryString(Request, “SPHostUrl”, “AuthorizedSPFarm”, true));

//Add file name with hyperlink

HyperLink docLink = new HyperLink();

docLink.Text = String.Format(“{0}”, f.Name);

docLink.NavigateUrl = f.ListItemAllFields[“EncodedAbsUrl”].ToString();

}

Display DOC ICON in SharePoint custom page

1. Get folder of the file

2. Loadfiles into client object.

3. Load Properties like -> DOC Icon, FileURL,File ID

Folder request = currentWeb.Lists.GetById(new Guid(listID)).GetItemById(requestID).Folder;

clientContext.Load(request, x => x.Files, x => x.Files.Include(p => p.ListItemAllFields[“DocIcon”]), x => x.Files.Include(p => p.ListItemAllFields[“EncodedAbsUrl”]), x => x.Files.Include(p => p.ListItemAllFields.Id));

clientContext.ExecuteQuery();

Get all files from folder location .

foreach (File file in request.Files)

{

//Add file Icon

Image dociconImage = new Image();

var imageUrl = clientContext.Web.MapToIcon(f.Name, String.Empty, Microsoft.SharePoint.Client.Utilities.IconSize.Size16);

clientContext.ExecuteQuery();

dociconImage.ImageUrl = string.Format(“{1}/_layouts/images/{0}”, imageUrl.Value, SecurityHelper.getQueryString(Request, “SPHostUrl”, “AuthorizedSPFarm”, true));

//Add file name with hyperlink

HyperLink docLink = new HyperLink();

docLink.Text = String.Format(“{0}”, f.Name);

docLink.NavigateUrl = f.ListItemAllFields[“EncodedAbsUrl”].ToString();

}

Hope this code will help you.

Thanks&Regards,

Jayabharathi

Similar SharePoint 2013 Tutorials


About jayabharathi

The turning point in the process of growing up is when you discover the core of strength within you that survives all hurt.

View all posts by jayabharathi →

Leave a Reply