[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Show thumbnail in gridvew if file system file is an image

Asked by jmestep in Programming for ASP.NET, C# Programming Language

I have  a gridview control that lists the files in a certain directory on the server as hyperlinks. I would also like for it to show the thumbnail if it is an image file and not show anything or show an alternate image if it's not an image file. I can pick up the file name and create a hyperlink fine. I just need help with the image- I've worked at it all day! I also can't figure out a way to use a variable for the directory part of the URL (di in the code).
It's taken me a long time to get this far so please give me an answer that will work with the existing code if possible.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
Code behind:
protected void Page_Load(object sender, System.EventArgs e)
    {
        // Grab all the files from a directory for orders
        string di = "~/Assets/OrderUploads";
        
        List<MyFileItem> fileItems = new List<MyFileItem>();
        //GET FILES
        FileInfo[] files = new DirectoryInfo(Server.MapPath(di)).GetFiles();
        Array.Sort(files, new LastWriteTimeDescComparer());
        string[] checkForExtensions = { ".jpg", ".jpeg", ".gif", ".png", ".bmp" };
        Boolean fileOK=false;
        foreach (FileInfo file in files)
        
        {
             string ext = System.IO.Path.GetExtension(di+file.Name);
 
            for (int i = 0; i < checkForExtensions.Length; i++)
                    {
                        if (ext == checkForExtensions[i])
                        {
                            fileOK = true;
                            //the above found the images fine
                            //Response.Write(ext);
                        }
 
            }
            fileItems.Add(new MyFileItem(file.Name));
         
        }
        GridView1.DataSource = files;
        GridView1.DataBind();
    }
 
The gridview:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            AllowPaging="True" PageSize="50" 
            OnPageIndexChanging="GridView1_PageIndexChanging" CellPadding="5">
            <PagerSettings Position="TopAndBottom" />
        <Columns>
        <asp:TemplateField HeaderText = "Image">
        <ItemTemplate>
         <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#string.Format("~/Assets/OrderUploads/"+ Eval("Name")) %>'
              Target="_blank">
          <asp:Image ID="Image1" width="50px" runat="server" ImageUrl='<%#string.Format("~/Assets/OrderUploads/"+ Eval("Name")) %>'/>
           </asp:HyperLink>
       </ItemTemplate>
        </asp:TemplateField>
         <asp:TemplateField HeaderText = "File URL">
         <ItemTemplate>         
         <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%#string.Format("~/Assets/OrderUploads/"+ Eval("Name")) %>'
               Text='<%#Eval("Name") %>' ></asp:HyperLink>
        </ItemTemplate>
        </asp:TemplateField>
        </Columns>
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
[+][-]12/20/08 04:36 PM, ID: 23220321Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/20/08 06:06 PM, ID: 23220511Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/20/08 07:17 PM, ID: 23220644Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/21/08 11:36 AM, ID: 23222861Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/21/08 11:41 AM, ID: 23222887Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/21/08 12:08 PM, ID: 23222975Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/21/08 12:14 PM, ID: 23222995Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/21/08 12:24 PM, ID: 23223023Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/21/08 12:27 PM, ID: 23223037Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/21/08 01:34 PM, ID: 23223287Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/21/08 08:59 PM, ID: 23224803Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/22/08 05:35 AM, ID: 23226260Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/22/08 07:06 AM, ID: 23226822Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/22/08 07:29 AM, ID: 23226993Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/22/08 07:33 AM, ID: 23227021Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/22/08 08:15 AM, ID: 23227334Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Programming for ASP.NET, C# Programming Language
Sign Up Now!
Solution Provided By: giedmer
Participating Experts: 1
Solution Grade: A
 
[+][-]12/22/08 09:06 AM, ID: 23227720Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/23/08 08:24 AM, ID: 23234594Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625