Solved

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

Posted on 2003-12-03
7
44,149 Views
Last Modified: 2011-10-03
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
Comment
Question by:tgatif
7 Comments
 
LVL 4

Expert Comment

by:NetPointer
ID: 9871469
<input id="myFile" type="file" runat="server">

Put above line in your html code..it will generate file and button to browse.
0
 
LVL 2

Expert Comment

by:adomsg
ID: 9872395
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
 
LVL 5

Expert Comment

by:arvindb1
ID: 9872582
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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

Author Comment

by:tgatif
ID: 9885662
I want the file browser dialog in Web Application which is equivalent to file browser dialog in Windows Application.
0
 

Accepted Solution

by:
Priya25 earned 250 total points
ID: 9902403
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
 

Expert Comment

by:sheeladonald
ID: 10712709
how do i open a save dialog box with filters as (*,jpeg, *.csv) in asp.net
0
 

Expert Comment

by:DavidTanis
ID: 13790090
After I click save, a blank page displayed. How do I get rid of it?  
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with preventing downloading a zip file 10 45
VB.NET 2008 Winforms Signing 13 32
Finding Events logs for IIS website that restarts 2 14
Visual Studio npm 1 12
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question