Results 1 to 7 of 7

Thread: Opening file in application that created it

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Opening file in application that created it

    I am working on a web application project to be deployed on an intranet. I need to provide users with the ability to allocate documents to projects so that I can show them a page that lists the documents for a project. When they click on the document I need it to open in the application that created it. Generally, just Word and Excel documents.

    So, I've done all the 'Add a Document' stuff and I have a Gridview on the screen that displays the document name (test.doc) and the path (C:\Users\Fred\Test.doc).

    I have tried passing the Document Name and Document Path to this function:

    Code:
    protected void ShowFile(string DocumentName, string DocumentPath)
            {
                Response.Clear();
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("content-disposition", "attachment;filename=\"" + DocumentName + "\"");
                Response.TransmitFile(DocumentPath);
                Response.End();
            }
    and, for example, for my Word document it opens - but not before a 'Do you want to Open or Save this file dialog is presented' (unwanted, but not the end of the world) but, when the file opens you can't save it. (Even on my development box).

    Is there a simple way of simply opening an Office document from within a .net web application project that just actually opens the document - so it can be edited and saved etc.

    Thanks for any help.

    Edit: When the word file opens - if I click to save it it shows this as the path to the file:

    C:\Users\Fred\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\7T5D07IA\Test[4].doc

    So, it's not opening the original file at all - it's creating a copy of it. I want users to simply be able to click on a file and open it. If I use 'C:\Users\Fred\Test.doc' as a desktop shortcut - click on it and the file opens - the actual file - you can edit and save it. Why is it so hard to get a Word document to open from within a .net Web Application?
    Last edited by Webskater; Feb 20th, 2012 at 03:58 PM.

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Opening file in application that created it

    When you download a file does it opens at once?Does an exe with a lovely virus opens at once(there is some "simulation" ways but you won't get answers on this forum)?So there are 2 things here.
    First you would have to force a file to open and that is not allowed.
    Second you need the actual file on the user PC to get opened.
    So you can either just let the user download the word file and open it by it's choice or have the word file in your server so the user can make changes there and after that it can choose to download it or not.
    Another way that i have personally never tried is to have an activex component installed on the users that will do what you want.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Opening file in application that created it

    Quote Originally Posted by Webskater View Post
    Edit: When the word file opens - if I click to save it it shows this as the path to the file:

    C:\Users\Fred\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\7T5D07IA\Test[4].doc

    So, it's not opening the original file at all - it's creating a copy of it. I want users to simply be able to click on a file and open it. If I use 'C:\Users\Fred\Test.doc' as a desktop shortcut - click on it and the file opens - the actual file - you can edit and save it. Why is it so hard to get a Word document to open from within a .net Web Application?
    This is very much be design.

    The user of your web application does not have rights to edit the file which is stored on the web server, and you wouldn't want them to. The technique that you are using is sending an entire copy of the document to the client browser, which is then saving a local copy to the temporary internet folder for their machine.

    If you are looking to provide a link to the actual document, then assuming you are in a local intranet environment, you could place all the files onto a shared network resource, and simply provide a link to the file, which would allow the user to open them and edit them.

    This brings into question other concerns like two people editing the same document at the same time though, and conflicts when things are saved. There are several Content Management Systems out there that already take care of this for you. Have you considered something that is already available, such as SharePoint?

    Gary

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: Opening file in application that created it

    Quote Originally Posted by gep13 View Post
    If you are looking to provide a link to the actual document, then assuming you are in a local intranet environment, you could place all the files onto a shared network resource, and simply provide a link to the file, which would allow the user to open them and edit them.

    Gary
    In fact all the documents will be on a shared network resource at \\someserver\$Projects\

    But, how do I provide a link to the file which will allow them to open them and edit them? Won't any link, as you describe, download a copy to their local machine?

    Thanks for your reply.

  5. #5
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Opening file in application that created it

    Hello,

    Depending on which browser you are using, you can provide either a UNC path or or file:\\ path to the file, which will enable the default application on the client machine to open the file directly from there, rather than download a copy.

    However, going down this route is certainly not advised, and I would strongly recommend that you look to a system that has already solved all the associated problems for you.

    Gary

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: Opening file in application that created it

    Quote Originally Posted by gep13 View Post
    Hello,

    Depending on which browser you are using, you can provide either a UNC path or or file:\\ path to the file, which will enable the default application on the client machine to open the file directly from there, rather than download a copy.

    However, going down this route is certainly not advised, and I would strongly recommend that you look to a system that has already solved all the associated problems for you.

    Gary
    Hi Gary

    When you say 'this route is certainly not advised' - what do you mean? This is on an intranet and the only people that will have access to the application are permissioned.

    When you say a 'system that has already solved all the associated problems' - are you thinking of Sharepoint?

  7. #7
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Opening file in application that created it

    Quote Originally Posted by Webskater View Post
    When you say 'this route is certainly not advised' - what do you mean? This is on an intranet and the only people that will have access to the application are permissioned.
    What I mean is, if you create a site, that is used by many users, all of whom can edit files at the same time, and overwrite changes that each other are making, then that technique is not advised.

    When you say a 'system that has already solved all the associated problems' - are you thinking of Sharepoint?
    Yes, this is one of the many CMS systems out there that have already dealt with these problems, and do a good job at it.

    Gary

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