Solved

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

Posted on 2003-12-03
7
44,113 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
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)…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now