Results 1 to 13 of 13

Thread: [2008][.NET 3.5] view/open/save files

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    56

    Unhappy [2008][.NET 3.5] view/open/save files

    I have a web app that needs to allow users to view files that are placed on the webserver where my program will be located. What I'm not sure how to do is to have the dialog box come up that allows the user to choose to either open or save the file for them to view. How do I do this?

    The page the users are on for this to happen, they search for certain criteria and in a database table it compares the criteria to and it shows all the files that match what they've asked for. (This grid can have the path for the file if necessary.) I need to have a button or link or something in the grid that they can click that will open the file or show the dialog box. I know that a regular hyperlink can do this, but I can't dynamically create a hyper link and an click_event function for it. So if anyone can help me at all on how to open files, I'd really appreciate it!!! Please let me know if any other information or code is needed. Thanks!

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008][.NET 3.5] view/open/save files

    in the click event, why don't you just do a

    Code:
    response.redirect(URLToFileOnWebServerHere)
    in the code behind? This will act like they clicked a direct hyperlink and will give them the standard "run/save/cancel" dialog they get when downloading any file (Some Windows OS say "open" instead of "run" at this prompt).

    I don't know the details of your app, but also, there is likely a way that you could just dynamically create hyperlinks when you present the data to the user in the first place, so there would be no need for codebehind to navigate to the files.

    I am moving this to the ASP.NET forum.

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    56

    Re: [2008][.NET 3.5] view/open/save files

    where were you saying I should put that click event?
    and I've tried doing it where I have the grid with the filename, filepath, and a button in each row of the grid. When I click the button, I can grab the filepath and do a response.redirect(filepath). But that tries to open the file in the same web browser. It doesn't even work, it says the page cannot be displayed. so, I thought maybe it was a permissions thing so I hard coded a hyperlink into the page and when clicked, it opened the file just fine, like it should with the dialog box and everything. So that response.redirect() didn't act just like a hyperlink like I thought it should've...

    So I need to find a different way to click on a row in the (Rad) grid to open the file.

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

    Re: [2008][.NET 3.5] view/open/save files

    Quote Originally Posted by Big Red
    I have a web app that needs to allow users to view files that are placed on the webserver where my program will be located. What I'm not sure how to do is to have the dialog box come up that allows the user to choose to either open or save the file for them to view. How do I do this?

    The page the users are on for this to happen, they search for certain criteria and in a database table it compares the criteria to and it shows all the files that match what they've asked for. (This grid can have the path for the file if necessary.) I need to have a button or link or something in the grid that they can click that will open the file or show the dialog box. I know that a regular hyperlink can do this, but I can't dynamically create a hyper link and an click_event function for it. So if anyone can help me at all on how to open files, I'd really appreciate it!!! Please let me know if any other information or code is needed. Thanks!
    Of course you can dynamically create a hyperlink. You know the data you're getting back, you have a gridview or a repeater. All you need to do then is take each row's field (the filename) and since you know the location of the file, you generate a hyperlink URL to that file. Then you set the hyperlink's NavigateUrl in your grid/repeater to be that generated URL.

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008][.NET 3.5] view/open/save files

    I guess it also depends on the file types as to how they will open. Some files are registered on a system to simply display in the browser and not prompt for downloading. So in addition to htm, asp, etc... files that end it txt, pdf, or even xls and doc will often load directly in the browser versus being considered a file download in the sense of getting a download prompt. This should be configurable at the browser level.

    If you wanted the links (that will open their contents directly in the browser) to open in new windows and not navigate away from the current page, then just add target="_blank" to your hyperlink markup.

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    56

    Re: [2008][.NET 3.5] view/open/save files

    mendhak,
    Yes, I had first figured that I could dynamically create a hyperlink once the grid is clicked (it's a Rad grid btw) and then I can grab the file path from the chosen line in the grid and then set the NavigateURL to that filepath. Which, I can do. But, I don't want the users to have to click on the page twice. When I dynamically create a hyperlink, I can't create a click event (addhandler) because a hyperlink's click event is client side, not on the server side. So i can't do it in my code-behind vb.net coding. That's where I'm running into my problem. do you know of how to get around that?

    kleinma,
    All my file types will be in pdf format and when I have a hyperlink on my webpage (hardcoded), the dialog box does come up and it opens in a new window. But, I need to have this happen once the grid is clicked, not a hyperlink on the page.

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

    Re: [2008][.NET 3.5] view/open/save files

    Why do you need a click handler for a hyperlink? You either set the hyperlink's URL to the file directly (which gives them the save/open dialog box or just opens it) or you set the URL to a 'handler' page such as downloadfile.ashx?filename=abc.pdf which in turn performs the Response.WriteFile.

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    56

    Re: [2008][.NET 3.5] view/open/save files

    okay, i understand what you're saying... i think. but my hyperlink or click button is in the RadGrid and I'm not sure how to make that link dynamic to the path and still have the page go to open up the file. it's gotta be done in the code behind, right? I'm not sure how to do that either way.

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

    Re: [2008][.NET 3.5] view/open/save files

    I've never used the RadGrid but surely it has a RowDataBound event?

  10. #10

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    56

    Re: [2008][.NET 3.5] view/open/save files

    so you're saying that instead of binding it to a sqldatasource, I should bind it to a datatable or something like that?

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

    Re: [2008][.NET 3.5] view/open/save files

    You can still bind it to a SqlDataSource, but the OnRowDataBound will always be raised (at least for the GridView) which in turn lets you play with and manipulate the controls inside the grid and how they are rendered.

  12. #12
    New Member
    Join Date
    Nov 2008
    Posts
    1

    Re: [2008][.NET 3.5] view/open/save files

    mendhak "I've never used the RadGrid but surely it has a RowDataBound event? "

    Hi mendhak

    I've checked and it doesn't.

    Anyone know what the equivalent is?

    Thanks
    P

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

    Re: [2008][.NET 3.5] view/open/save files

    Alternative approach - use the GridView. Is there something special the RadGrid offers that the GridView doesn't?

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