Just wanted to share one of the usage of AssetUploader.aspx in SharePoint. The scenario is pretty simple, we have a picture library, and the list items are displayed in a SPGridView with thumbnail as one of the column.
<Columns>
<asp:TemplateField HeaderText="Type" ItemStyle-Width="30px">
<ItemTemplate>
<%# Eval("ContentType").ToString() == "Folder" ? "<img src='/_layouts/images/folder.gif' alt='' />" : "<img src='/_layouts/images/" + Microsoft.SharePoint.Utilities.SPUtility.MapToIcon(Microsoft.SharePoint.SPContext.Current.Web, Eval("DocIcon").ToString(), "")+ "' alt='' />" %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Thumbnail" ItemStyle-Width="100px">
<ItemTemplate>
<%# Eval("ContentType").ToString() == "Folder" ? "<span> </span>" : "<img src='/_layouts/AssetUploader.aspx?Size=Small&ImageUrl=" + HttpUtility.HtmlEncode(Eval("FileRef").ToString()) + "' alt='' style='cursor: pointer;' />"%>
</ItemTemplate>
</asp:TemplateField>
<sp:SPBoundField DataField="LinkFilenameNoMenu" HeaderText="Name" />
</Columns>
The above will render the grid like below,
Here the file type image is rendered based on the Field property DocIcon and SPUtility.MapToIcon function.
The thumbnail is generated using AssetUpload.aspx
And the name column just bound to the LinkFileNameNoMenu
Usage of AssetUploader.aspx in detail
This can be used anywhere with <img> tag to display thumbnail of size normal or small.
<img src=”/_layouts/AssetUploader.aspx?Size=Small&ImageUrl=/IMAGES/fileName.fileextension&Size=Small” alt=”” />
- IMAGES –> Is the Images library name
- fileName –> the name of the image (myPhoto in myPhoto.jpg)
- fileextension –> the file extension of the image (jpg in myPhoto.jpg)
- Size –> If not provided then medium size thumbnail will be generated, pass Small for smaller thumbnail.
So the effort to generate crisper and smaller thumbnail is made easier with the AssetUploader.aspx
Issue
Recently I ran across an issue in Sharepoint with AssetUploader.aspx (The page can be used to generate thumbnail images for images which are located in a Sharepoint library, the usage I have mentioned at the bottom of the post). The issue which we faced was that the AssetUploader.aspx failed to generate thumbnail when the request was secured that is when the request was made across https://. So I tried to investigate using refactoring the dll using .Net reflector, but unfortunately the code was obfuscated. But as a savior I found Mr.Bob Moore’s Blog while googling on the issue. The post is located at http://blogs.pointbridge.com/Blogs/moore_bob/Pages/Post.aspx?_ID=14 the title of post is Pain in the AssetUploader.aspx . Thanks a lot Bob :)
No comments:
Post a Comment