Skinned Sample
Select files to upload:
|
Uploading ,
(calculating).
|
|
Currently uploading:
,
file
of
.
|
|
Speed:
(calculating).
|
|
About
(calculating) remaining.
|
|
|
Cancel
NOTE: the maximum allowed request size for this sample is 1000 MB. If you attempt to upload files larger than this,
you will recieve a oversized upload error which SlickUpload will handle gracefully. This is controlled by the maxRequestLength attribute of the
httpRuntime key in the web.config file.
Description
The SlickUpload control is fully templatable, giving detailed control over how it looks and acts. This example demonstrates two simple templates –
templating the file list and using an image for the progress bar. You can manipulate any other part of the control by modifying the default template HTML and/or adding CSS.
Templating the file list
The file list item is controlled by the <FileTemplate> template. In this example, we do a couple things to spiff up the
layout from the standard layout:
Create a border around each item
<div style="border:solid 1px #ccc;margin:1em;padding:1em">
Float the remove link to the top right and add an image
<kw:FileListRemoveLink runat="server" Title="Remove" style="float:right;margin-top:-.5em;margin-right:-.5em">
<img width="20" height="20" style="vertical-align:middle" src="<%=ResolveUrl("~/Common/delete.png") %>" /> remove
</kw:FileListRemoveLink>
Add a file extension icon
<img id="extImage" width="32" height="32" style="vertical-align:middle;" />
This last feature, a file extension icon, takes a little more to hook up than just the HTML. The HTML provides a placeholder for
the image. We then hook up an event that fires after each file is added:
<kw:SlickUpload ... OnClientFileAdded="fileAdded" ... />
The event handler gets a reference to the img tag and sets the image source URL based on the file extension:
function fileAdded(file)
{
var extImage = file.getElementById("extImage");
extImage.src = "FileIconCS.ashx?ext=" + file.extension;
}
This sets the source to a simple handler which pulls the proper icon. For this example, there is a folder of icons located at ~/Common/icons.
The handler selects the proper icon based on file extension and returns it to the client:
public void ProcessRequest(HttpContext context)
{
string ext = context.Request.QueryString["ext"] ?? "xxx";
string fileName = context.Server.MapPath("~/Common/icons/" + ext + ".gif");
if (!File.Exists(fileName))
fileName = context.Server.MapPath("~/Common/icons/xxx.gif");
context.Response.ContentType = "image/gif";
context.Response.TransmitFile(fileName);
}
Progress bar image
To add a progress bar image is as simple as adding a background image to the <kw:UploadProgressBarElement>. This element renders into a div with a width based on the progress complete.
To specify a progress image, simply add CSS that references your desired image:
<kw:UploadProgressBarElement ... style="background-image: url('xp.gif')..." ... />
|