Solved

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

Posted on 2003-12-03
7
44,123 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

21 Experts available now in Live!

Get 1:1 Help Now