Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have files uploaded on the server. the file can be of any type(.doc,docx,xls,xlsx,jpeg,.. any type)

Now, I want to display those files with relevant icon according to file type and the file name also

e.g.
file is doc - a word Icon is displayed and the file name which on clicking I can download it.

Tell me how it can be done
Posted

1 solution

Simplest Way is to save the images icon of all the possible file types in some folder like "icons" and based on the extension you can use the particular image on the particular file. You can get icon images anywhere on Google.

e.g
ASP.NET
<img id="imgIcon" runat="server"></img>

C#
string myFilePath = @"C:\MyFile.txt";
string ext = Path.GetExtension(myFilePath);

if(ext=="txt")
{
   imgIcon.Src="icon/txtIcon.jpg"; //the name of the file used for naming the image
}
else if(ext=="doc" || ext=="docx")
{
   imgIcon.Src="icon/wordIcon.jpg"; //the name of the file used for naming the image
}
 
Share this answer
 
Comments
maverick12131 2-Jul-13 7:41am    
I want it to be displayed a Image followed by the file name
aspx page:
<asp:LinkButton ID="LinkButton1" runat="server">
<img runat="server" id="Image2"/>


.cs page

if (fi.Extension == ".txt")
{
Image2.Src = @"~\Upload\x_icon.png";
LinkButton1.Text = fi.Name;
LinkButton1.Visible = true;
}
else if (fi.Extension == ".docx")
{
Image2.Src = @"~\Upload\Add.jpg";
LinkButton1.Text = fi.Name;
LinkButton1.Visible = true;
}

but in this case i only get text in hyperlink and not the image
PRAKASH9 2-Jul-13 7:53am    
add one imagebutton and one linkbutton so that your problem solved
Siddhesh Patankar 2-Jul-13 7:44am    
try this <asp:LinkButton ID="Linkbutton1" runat="server"><img runat="server" ID="Image2"></asp:LinkButton>

Means Put the Image Tag inside link button tag
maverick12131 3-Jul-13 1:48am    
This will do, but what if I have more than 1 file to be displayed.
how to show multiple files using a link button and image.
Can u guide me how to use repeater control for this purpose

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900