Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm developing a web application,

I did a crystal report using visual stadio 2008 which can generate pdf file, when open that report in pdf it is open in the same window as my asp pages, i want that when click on report it can open saveorOpenFile window so that i can open or save that report.

please helps if you know how to do SaveOrOpenFileDialog in c#
I tried this it don't work:
C#
string str = @"~/Reports/ReportViewing.aspx?report=rptReservationByOffice&StartDate=" + txtStartDate.Text + "&EndDate=" + txtEndDate.Text;

           String FileName = "FileName.txt";
           String FilePath =str; //Replace this
           System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
           response.ClearContent();
           response.Clear();
           response.ContentType = "text/plain";
           response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
           response.TransmitFile(FilePath);
           response.Flush();
           response.End();
Posted
Updated 24-Jun-11 10:11am
v2

C#
private static MemoryStream downloadData(string url)
            {
                try
                {
                    progress.Value = 0;
                    Application.DoEvents();
                    //Get a data stream from the url
                    WebRequest req = WebRequest.Create(url);
                    WebResponse response = req.GetResponse();
                    Stream stream = response.GetResponseStream();

                    //Download in chuncks
                    Byte[] buffer = new Byte[1024];

                    //Get Total Size
                    Int32 dataLength = (Int32)response.ContentLength;

                    //With the total data we can set up our progress indicators
                    progress.Maximum = dataLength;
                    Application.DoEvents();
                    //Download to memory
                    //Note: adjust the streams here to download directly to the hard drive
                    MemoryStream memStream = new MemoryStream();
                    while (true)
                    {
                        //Try to read the data
                        Int32 bytesRead = stream.Read(buffer, 0, buffer.Length);

                        if (bytesRead == 0)
                        {
                            progress.Value = progress.Maximum;
                            Application.DoEvents();
                            break;
                        }
                        else
                        {
                            //Write the downloaded data
                            memStream.Write(buffer, 0, bytesRead);
                            if (progress.Value + bytesRead <= progress.Maximum)
                            {
                                progress.Value += bytesRead;
                                progress.Refresh();
                                Application.DoEvents();
                            }
                        }
                    }

                    stream.Close();
                    return memStream;
                }
                catch 
                {
                    //May not be connected to the internet
                    //Or the URL might not exist
                    throw new Exception("There was an error accessing the URL.");
                }
            }


now to use this

C#
string str = @"~/Reports/ReportViewing.aspx?report=rptReservationByOffice&StartDate=" + txtStartDate.Text + "&EndDate=" + txtEndDate.Text;
byte[] DownloadedData = DownloadData(str);
            if (DownloadedData == null || DownloadedData.Length == 0)
                return;
using (Stream Writer = File.Create(FilePath))
            {               
                Writer.Write(DownloadedData, 0, DownloadedData.Length);
            }         
 
Share this answer
 
v2
hi,
you can use

C#
var str = "../Reports/ReportViewing.aspx?report=rptReservationByOffice&StartDate=" + document.getElementById("txtStartDate").value + "&EndDate=" + document.getElementById("txtEndDate").value;

window.open(str);


you may take help for window.open from here Using the window.open method[^]

Thanks,
Imdadhusen
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900