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?
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 ???)
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".
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.
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.
Member
188 Points
352 Posts
Emulate opening file by clicking filename in windows
Jul 15, 2019 03:42 AM|Bulldog248|LINK
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!
All-Star
194428 Points
28073 Posts
Moderator
Re: Emulate opening file by clicking filename in windows
Jul 15, 2019 06:58 AM|Mikesdotnetting|LINK
Is this in an ASP.NET application? When you say "open", do you mean download?
All-Star
48490 Points
18068 Posts
Re: Emulate opening file by clicking filename in windows
Jul 15, 2019 07:02 AM|PatriceSc|LINK
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 ???)
Member
188 Points
352 Posts
Re: Emulate opening file by clicking filename in windows
Jul 15, 2019 06:16 PM|Bulldog248|LINK
Hi PatriceSc,
Below is a code sample where I open the pdf viewer to a specific file:
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!
All-Star
194428 Points
28073 Posts
Moderator
Re: Emulate opening file by clicking filename in windows
Jul 15, 2019 08:32 PM|Mikesdotnetting|LINK
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.
All-Star
48490 Points
18068 Posts
Re: Emulate opening file by clicking filename in windows
Jul 16, 2019 11:55 AM|PatriceSc|LINK
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.