Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7010527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:00:09+00:00 2026-05-27T22:00:09+00:00

I have a GridView which has following template field that holds the filename, when

  • 0

I have a GridView which has following template field that holds the filename, when the user clicks the filename, I call window.open() to open the file. My question is I can only pass relative path to window.open(). I got an error if I use full path. Is there any way I can use full path to open a file? Thanks.

<asp:TemplateField HeaderText="FileName">
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkFile" runat="server"
                        Text='<%# Eval("FileName")%>' OnClick="lnkFile_Click">
                        </asp:LinkButton>
                    </ItemTemplate>
</asp:TemplateField>

Added: The actual location of the file is defined in web.config.

I have wrote following lnkFile_Click(). The old part will open a new window for the file, but I cannot pass fullpath of the file. The new part will let you have a choice to open or save the file. My question is, will this cause security issue?

protected void lnkFile_Click(object sender, System.EventArgs e)
{
    string fileName = ConfigurationSettings.AppSettings["SPRAttachmentLocation"] + "\\SPR" + sprID + "\\" + ((LinkButton)sender).Text;
    if (!File.Exists(fileName))
    {
        Exception ex = new Exception("Could not find the file, please contact your administrator.");
        Response.Write("<p align=\"center\"><br /><br /><br /><br />There has been an Error: <strong>" + ex.Message + "</strong></p>\n");

        return;
    }

New:

byte[] bts = System.IO.File.ReadAllBytes(fileName);
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Content-Type", "");
Response.AddHeader("Content-Length", bts.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(bts);
Response.Flush();
Response.End();

Old:

   string newWindowUrl = "/SPR_Upload/SPR" + sprID + "/" + ((LinkButton)sender).Text;

            string javaScript =
             "<script type='text/javascript'>\n" +
             "<!--\n" +
             "window.open('" + newWindowUrl + "');\n" +
             "// -->\n" +
             "</script>\n";

   Page.ClientScript.RegisterStartupScript(GetType(), "", javaScript);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:00:10+00:00Added an answer on May 27, 2026 at 10:00 pm

    Your question gives the impression that you think that you can open a file from the user’s local computer. If that’s the case, this is not possible.

    Window.open expects a URL because the file is located on the server side, not the client side.

    With that said, if you are trying to open a file located on the server side and you know the full path to the file; what you need to do is generate the virtual path within your application where the file can be found. You do this by creating a Virtual Directory in your APP from the IIS Admin Manager (Control Panel–>Admin Tools –>IIS Mgmt) and mapping this directory to the actual physical directory.

    EDIT:

    Say for example your whole website is physically located on the server on c:\inetpub\wwwroot\your_app. Let’s assume your app can be accessed via http://example.com and the files you want to serve are physically located on d:\files. Assume further that you created a virtual directory for your app (as I explained above) and that you called this virtual folder public_files. If one knows the file name it should be possible to access the file by simply going to http://example.com/public_files/filename.ext. Since you in your app already know the file name, all you need to pass as parameter to window.open is this url (http://example.com/public_files/filename.txt)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView which has EditButton and DeleteButton enabled. When the user clicks
For example, Lets say that I have a gridview column which has important controls,
I have one GridView gvDetail which has 30 columns(include both Template and BoundField). In
I have a gridview on which Item template has few textbox, due to business
I have the following GridView , which has as DataSource a List<T> : <asp:GridView
I have a gridview which has rows of 'tickets'. A user has the ability
I Have a gridview which has a row that contains LinkButtons that were added
In a gridview I have the following Template Field containing a textbox <asp:TemplateField ShowHeader=true
I have a gridview which has 13 columns. All the columns are bound field.
I have a GridView in which each row has a custom view. The grid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.