Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am a new ASP.NET developer and I am trying to develop a page called Useful Library that will contain many things such as useful presentations and pdf documents. I have a folder in the Server called (Useful Resources) and I put all those useful presentations and documents in it. I have the following table in my database:

SQL
UsefulResources Table: ID, Category, Title, URL, Uploaded Date, Hits


The reason of designing this table is to organize the resources and count the hits on the link of the document. I implemented it and it shows well in the page. However, when I click on one of the links, I got the following error and I don't know why:
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.


The clicked link will be like this:
http://www.pmvt.com/msa/pssp/UsefulResourcesCountHits.asp?ID=1&link=Useful%20Resources/Electrical%20safety.ppt[^]

**Could you please help me in this?**

My ASP.NET Code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        DataSourceID="Sql_Categories" ShowHeader="False" Width="100%"
        BorderStyle="None" GridLines="None">
        <Columns>
            <asp:TemplateField HeaderText="Category" SortExpression="Category">
                <ItemTemplate>
                <a id='<%# (Eval("Category").ToString()) %>'</a>
                <br />
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Category") %>'
                        style="font-weight: bold; font-size: 14px"></asp:Label>
                <br />
                    <asp:SqlDataSource ID="Sql_Reports" runat="server"
                        ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                        SelectCommand="SELECT [ID], [Title], [URL], [UploadedDate] FROM [UsefulResources] WHERE ([Category] = @Category) ORDER BY [UploadedDate] DESC">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="Label1" Name="Category" PropertyName="Text"
                                Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
                        CellPadding="4" DataSourceID="Sql_Reports" ForeColor="#333333" GridLines="None"
                        Width="100%">
                        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#E3EAEB" />
                        <Columns>
                            <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title">
                                <ItemStyle HorizontalAlign="Center" Wrap="False" Width="100px" />
                            </asp:BoundField>
                            <asp:HyperLinkField DataNavigateUrlFields="ID,URL"
                                DataNavigateUrlFormatString="Useful Resources/UsefulResourcesCountHits.asp?ID={0}&link=Useful Resources/{1}"
                                DataTextField="Title" HeaderText="Title" />
                            <asp:BoundField DataField="UploadedDate" DataFormatString="{0:MMM yyy}" HeaderText="UploadedDate"
                                SortExpression="UploadedDate">
                                <ItemStyle HorizontalAlign="Center" Wrap="False" Width="100px" />
                            </asp:BoundField>
                        </Columns>
                        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                        <EditRowStyle BackColor="#7C6F57" />
                        <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
                <div align="right"><a href='#Top'>Back to Categories</a></div>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="Sql_Categories" runat="server"
        ConnectionString="<%$ ConnectionStrings:testConnectionString %>"

                SelectCommand="SELECT DISTINCT [Category] FROM [UsefulResources]">
    </asp:SqlDataSource>
Posted

1 solution

For someone who is new to ASP.NET, you're trying to do something quite complex. If you're new, surely no-one is using this, and you could choose a simpler task ?

The error means what it says. If you want a hit count, you need to go to a page that serves the bytes of the file, and stores that someone requested it. A direct link will not allow you to run code when it's requested. Either way, if you get that error, the file is not on your site in that location, or your IIS is not configured to serve it.
 
Share this answer
 

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