Hi All,

Hi All, I'm in a bit of a pickle here. I'm Binding the name of file to a LinkButton and intending to open that file on the LinkButton' click. I have the LinkButton in the TemplateField of a GridView control. Below is the code I'm using :

<asp:TemplateField HeaderText="Article Name">
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" ForeColor="LightYellow" Text='<%# Eval("caption") %>'
                                Width="494px" CommandName="goto" CommandArgument='<%# Eval("file_name") %>'></asp:LinkButton>
                        </ItemTemplate>
                        <HeaderStyle ForeColor="White" />
                        <ItemStyle ForeColor="LightYellow" />
                    </asp:TemplateField>

And the Event Handler goes like :

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("goto"))
        {
            fileToOpen = e.CommandArgument.ToString();
            Response.Redirect(path + fileToOpen);
        }
    }

On clicking i get the above mentioned error 'Forbidden' from ASP Development Server 8.0.0.0

Recommended Answers

All 7 Replies

Hi All,

Hi All, I'm in a bit of a pickle here. I'm Binding the name of file to a LinkButton and intending to open that file on the LinkButton' click. I have the LinkButton in the TemplateField of a GridView control. Below is the code I'm using :

<asp:TemplateField HeaderText="Article Name">
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" ForeColor="LightYellow" Text='<%# Eval("caption") %>'
                                Width="494px" CommandName="goto" CommandArgument='<%# Eval("file_name") %>'></asp:LinkButton>
                        </ItemTemplate>
                        <HeaderStyle ForeColor="White" />
                        <ItemStyle ForeColor="LightYellow" />
                    </asp:TemplateField>

And the Event Handler goes like :

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("goto"))
        {
            fileToOpen = e.CommandArgument.ToString();
            Response.Redirect(path + fileToOpen);
        }
    }

On clicking i get the above mentioned error 'Forbidden' from ASP Development Server 8.0.0.0

Hi give the server username and password on Virtual directory of IIS. It will solve this issue. otherwise try to use inpersonation.

Hi murugavel84,
I tried impersonation its still not working..its giving the same error when i run it on my machine...but i put on my server and acces the link from browser it sayz page not found..what do i do....pls help..

Hi murugavel84,
I tried impersonation its still not working..its giving the same error when i run it on my machine...but i put on my server and acces the link from browser it sayz page not found..what do i do....pls help..

Can u please attach the error screenshot?

Here is the screenshot, sir..

Instead of using Response.Redirect("Some file Name") using Response.WriteFile() method which writes the contents of the specified file directly to an HTTP response output stream as a file block. For example,

Response.WriteFile(@"D:\Temp\Test1.docx") ;
 //Response.WriteFile(path + fileToOpen);

Here is the screenshot, sir..

-> Open IIS (Run->inetmgr)
-> Right click on your projects virtual directory and select Properties.
-> Select the Documents tab.
-> Click on the 'Add...' button.
-> Enter 'default.aspx' (without quotes) and click OK, then click OK back on the Properties dialog.

If u want to do it globally. Just set the same on website(Ex:DefaultWebsite).

This will solve this error. Otherwise let me know.

Thnx Murugavel sir, that worked perfectly...thnx a lot..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.