Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 44261
  • Last Modified:

How to open a file dialog box (open, save as, new) in asp.net?

How to open a file dialog box (open, save as, new) in asp.net?  I know that it is possible in Windows Application. I want to incorporate into web application.
0
tgatif
Asked:
tgatif
1 Solution
 
NetPointerCommented:
<input id="myFile" type="file" runat="server">

Put above line in your html code..it will generate file and button to browse.
0
 
adomsgCommented:
the point given by NetPointer is for file upload...that is upload the file to server..
U also need to add this encType="multipart/form-data" under ur <form> tab in the html.
0
 
arvindb1Commented:
and for downloading from server to client , to open dialog you can do something like this


                        Response.Clear()
                        Response.ContentType = "application/octet-stream"
                        Response.AddHeader("Content-Disposition", _
                          "attachment; filename=""" & filename & """")
                        Response.Flush()
                        Response.WriteFile(filepath)

Arvind
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
tgatifAuthor Commented:
I want the file browser dialog in Web Application which is equivalent to file browser dialog in Windows Application.
0
 
Priya25Commented:
Sub DisplayDownloadDialog(ByVal PathVirtual As String)
        Dim strPhysicalPath
        Dim objFileInfo As System.IO.FileInfo
        Dim strFileName As String = "C:\Inetpub\wwwroot\Mercator\" + FileNameCSV
        Try
            strPhysicalPath = Server.MapPath(FileNameCSV)
            'exit if file does not exist
            If Not System.IO.File.Exists(strPhysicalPath) _
                 Then Exit Sub
            objFileInfo = New System.IO.FileInfo(strPhysicalPath)
            Response.Clear()
            'Add Headers to enable dialog display
            Response.AddHeader("Content-Disposition", "attachment; filename=" & _
                objFileInfo.Name)
            Response.AddHeader("Content-Length", objFileInfo.Length.ToString())
            Response.ContentType = "application/octet-stream"
            Response.WriteFile(objFileInfo.FullName)
        Catch
        Finally
            Response.End()
        End Try
    End Sub


Call the above procedure and give the full path name of the file to be saved when calling it as shown below and make sure the path given exists on your machine. In my example I have a folder Billing in C:\Inetpub\wwwroot\Mercator


Dim FileNameCSV As String = "C:\Inetpub\wwwroot\Mercator\Billing\Billing-" &  ".csv"
DisplayDownloadDialog(FileNameCSV)

This should be working.
0
 
sheeladonaldCommented:
how do i open a save dialog box with filters as (*,jpeg, *.csv) in asp.net
0
 
DavidTanisCommented:
After I click save, a blank page displayed. How do I get rid of it?  
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now