Results 1 to 8 of 8

Thread: Open Word Document File from link on Datagridview

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Open Word Document File from link on Datagridview

    I have a database that hold some files, which can be Word, Excel or PDF files. I use a Datagridview to show these files and now I want to put a link on my gridview so that when the user clicks on the Hyperlink(?) button the file will open. So far I am not having any luck wiring it all up.

    My select query looks like this
    VB Code:
    1. SELECT  DocID
    2.         , DocumentName
    3.         , DocumentPath+DocumentName AS FilePath
    4. FROM Documents

    This gives me results like this
    DocID: 1
    DocumentName: Scanning range.doc
    FilePath: C:\Docs\Scanning range.doc

    My datagridview is showing all the fields correctly and all I need to do is to add the Hyperlink field to do the download but no matter how I try it I am not able to get it to work.

    VB Code:
    1. <Columns>
    2.     <asp:HyperLinkField
    3.                DataNavigateUrlFields="FilePath"
    4.                 DataNavigateUrlFormatString="DocID={0}"
    5.                 Text="Open"
    6.                 HeaderText="Document" />
    7. </Columns>
    What am I doing wrong?

  2. #2
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Open Word Document File from link on Datagridview

    what is happening when you click the link?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Re: Open Word Document File from link on Datagridview

    Well I never make it to the link. The designer fails with this error Error Creating Control - dgvDocumentsDatabinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.HyperLinkField does not have a DataBinding event.

    I have tried the link a couple of different ways and got variations on the error but they all say basically the same thing.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Re: Open Word Document File from link on Datagridview

    Ok I finally got past the error and the page opens now with this.
    vb Code:
    1. <asp:HyperLinkField
    2.         DataTextField="FilePath"
    3.         DataNavigateUrlFields="DocID"
    4.         DataNavigateUrlFormatString="{0}" />
    When I hover over the link I am getting the DocID now. So I think I am on the right track but I just can't get it to work all the way.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Re: Open Word Document File from link on Datagridview

    I am close now
    vb Code:
    1. <asp:HyperLinkField
    2.         HeaderText="Action"
    3.         DataTextField="DocID"
    4.         DataNavigateUrlFields="DocumentName"
    5.         DataNavigateUrlFormatString="{0}" />
    This is looking for the file at the root level and I need to go one directory down to a sub directory. Can I use a Server Map Path with this?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Re: Open Word Document File from link on Datagridview

    A ha! DataNavigateUrlFormatString="/documents/{0}" />

  7. #7
    Hyperactive Member koolprasad2003's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    443

    Re: Open Word Document File from link on Datagridview

    if it is asp.net
    directly u can use window.open(//Word file path)
    MCP, MCTS, Microsoft MVP [Asp.Net/IIS]

    For more .NET development tips visit .NET Tips

    If the post is useful then please Rate it

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: Open Word Document File from link on Datagridview

    Assuming the DOC files are on the server, in C:\docs\etc then the user won't be able to see it at all. You'll need to link them to a handler page which in turn does a Response.WriteFile() from the local server location so that the user gets the save/open/cancel dialog prompt.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width