locked
Emulate opening file by clicking filename in windows RRS feed

  • Question

  • User615288127 posted

    I'm using Visual Studio 2017 and SQL Server 2014, VB.

    Is there a way to emulate the way you can double click on a filename in Windows Explorer to open a file using Windows file associations?  What I would like is to have a button that when I click it it will act like windows and open the attached to the button file automatically.  Any ideas or suggestions?

    Thanks!

    Monday, July 15, 2019 3:42 AM

Answers

  • User753101303 posted

    According to https://www.drupal.org/project/fileframework/issues/414690 see what happens when using the "application/sldworks" mime type (and of course use the .SLDPRT extension instead of .PDF).

    The mime type is to telll which kind of content you are sending back so that the browser can known (through the OS) which app could handle this content.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 16, 2019 11:55 AM

All replies

  • User-821857111 posted

    Is this in an ASP.NET application? When you say "open", do you mean download?

    Monday, July 15, 2019 6:58 AM
  • User753101303 posted

    Hi,

    Keep in mind that from a browser, for safety reason, the user must give his consent to whatever could be harmful. So for downloaded files you can't bypass this dialog (unless the user changed browser settings on which you have no control).

    Edit: if you need further help, tell rather what is your final goal (it is processed by a custom app ???)

    Monday, July 15, 2019 7:02 AM
  • User615288127 posted

    Hi PatriceSc,

    Below is a code sample where I open the pdf viewer to a specific file:

        Protected Sub Button16_Click(sender As Object, e As System.EventArgs)
            Dim SCH1 As String = String.Empty
            If FormView1.CurrentMode = FormViewMode.ReadOnly Then
                Dim SName As Label = TryCast(FormView1.FindControl("Schematic_PartLabel"), Label)
                Dim SNameDD As DropDownList = TryCast(FormView1.FindControl("DropDownList5"), DropDownList)
                If SNameDD.Visible = True Then
                    SCH1 = SCHpdf & SNameDD.SelectedItem.Text & ".pdf"
                Else
                    SCH1 = SCHpdf & SName.Text & ".pdf"
                End If
                Response.Clear()
                Response.ContentType = "application/pdf"
                Context.Response.AddHeader("Content-Disposition", "inline; filename=" + SCH1)
                Response.WriteFile(SCH1)
                Response.End()
            End If
        End Sub

    The problem is that I have a different type of file I would like to open with a different viewer.  In Windows explorer I can double click on the filename and it automatically associates with the correct viewer.  How can I adapt the above code for a different viewer?  Filename extension = ".sldprt"; associated application = "EModelViewer.exe".

    Thanks!

    Monday, July 15, 2019 6:16 PM
  • User-821857111 posted

    You can't associate file types with viewers on the client machine. Only the user can do that - if they even have a appropriate viewer installed. All you can do is to ensure that the correct content type is specified.

    Monday, July 15, 2019 8:32 PM
  • User753101303 posted

    According to https://www.drupal.org/project/fileframework/issues/414690 see what happens when using the "application/sldworks" mime type (and of course use the .SLDPRT extension instead of .PDF).

    The mime type is to telll which kind of content you are sending back so that the browser can known (through the OS) which app could handle this content.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 16, 2019 11:55 AM