I have a script that shows some files from a folder.
code behind
Sub fileinfo()
Dim objDI As New System.IO.DirectoryInfo(Server.MapPath("upload/files/"))
Dim allFile As New ArrayList()
allFile.AddRange(objDI.GetFiles("*.png"))
allFile.AddRange(objDI.GetFiles("*.jpg"))
allFile.AddRange(objDI.GetFiles("*.bmp"))
allFile.AddRange(objDI.GetFiles("*.gif"))
allFile.AddRange(objDI.GetFiles("*.pdf"))
allFile.AddRange(objDI.GetFiles("*.doc"))
allFile.AddRange(objDI.GetFiles("*.docx"))
Me.showfiles.DataSource = allFile
Me.showfiles.DataBind()
End Sub
main code
<ul class="thumbnails">
<asp:DataList ID="showfiles" runat="server" RepeatColumns="6" CellPadding="10" RepeatLayout="flow">
<ItemTemplate>
<li class="span2"><a class="thumbnail" href="#"><asp:ImageButton ID="folderfiles" runat="server" ImageUrl='<%# string.Format("upload/files/{0}", DataBinder.Eval(Container.DataItem,"Name")) %>' ToolTip='<%# Bind("Name") %>' height="82" width="119" /></a></li>
</ItemTemplate>
</asp:DataList>
works fine with images, but if i add a document like a pdf file i get this.
https://i.stack.imgur.com/g9bT4.png
then it add the textbox, how can i add an if statsment or something that can add:
pdficon.jpg for .pdf files
docicon.jpg for .doc files
zipicon.jpg for .zip files
so if the file is an image then it works like now, and when the file is an pdf or doc file, then it use the icon image and display that !?
…..EDIT…..EDIT……EDIT……..EDIT………EDIT………EDIT
Thx its works
https://i.stack.imgur.com/SKL55.png
but when i click one of the files i get and error page, with no error number, but a text with.
………. <%@ Page EnableEventValidation=”true” %> ClientScriptManager.RegisterForEventValidation …..
I cant download/See the image/pdf file.
You can implement a method returning your image url like this:
and use it in your markup:
…
ImageUrl='<%# getImageUrl(DataBinder.Eval(Container.DataItem,"Name")) %>'…