Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I have render a report on WebService layer and send it to WinForm Application layer as an byte array. After getting the array on the Application Layer, I want to show a Open/Save/Cancel dialog like lots of web sites use and enable the users open or save this report. As I want to create my reports on the WebService layer, I think I do not use ReportViewver easily. Do I? So, how can I show an Open/Save/Cancel dialog for enabling the users to choose this options?
BR

//On the Application Layer (Windows Form) :
private void GetFileFromArray()
{
    try
    {
        // call web method and store the result
        byte[] GenItineraryResult = myService.CreateReport(); //returns created report as an byte array
        using (FileStream fs = new FileStream(@"c:\Report.pdf", FileMode.Create))
        {
            fs.Write(GenItineraryResult, 0, GenItineraryResult.Length);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        fs.Close();
    }
}
Posted
Updated 7-Jul-11 8:40am
v4

How about this code:

C#
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    var file = ofd.FileName;
    // Write your file using the filename provided
}


Alex
 
Share this answer
 
Comments
H.Johnson 7-Jul-11 15:15pm    
Thanks for reply Alex, but it is only Open dialog. Instead of this, I need a Open/Save/Cancel dialog as we can see most of the websites when clicking a pdf file that enable us to Open or to Save the pdf file and Cancel also if we want.
Alexandru Ghiondea 7-Jul-11 15:26pm    
I am not sure if there is such a dialog built in. I belive the open/save/cancel is a dialog built into the browser.
Sergey Alexandrovich Kryukov 7-Jul-11 19:56pm    
What browser?! The question is tagger: WinForms.
Please see my answer.
--SA
Alexandru Ghiondea 7-Jul-11 20:02pm    
The OP was describing the situation when the user is presented with that choice on many web sites - which means browsers.

As I have already said, there is no built-in dialog window that the OP can use. You have to build your own.

Please don't lash out at people if you did not read the full question or reply.
There is not a ready-to-use combine Open/Save Dialog. It's enough look at the help MSDN pages for the library you use (Windows.Forms tagged) to see that there are two separate classes in each: SaveDialog and OpenDialog. There is never no a need for combined behavior, so using two separate classes is just fine.

Also, the file dialogs have nothing to do with file I/O. They merely provide a file name for the file to be stored or loaded. So, you had no need to ask anything specific to PDF or any other type of file; this is irrelevant. You only can set a FileMask to filter file properly while browsing.

That's all.

See all six classes:
http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.openfiledialog(v=vs.95).aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.openfiledialog.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.savefiledialog(v=vs.95).aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.savefiledialog.aspx[^].

—SA
 
Share this answer
 
v2
Comments
H.Johnson 8-Jul-11 3:31am    
Thanks for reply SAKryukov and Christian Graus, but OpenFileDialog is not suitable for my situation. I meant just like on web browser's little Open/Save/Cancel dialog when you see after clicking a pdf file link on web. So, I think it is impossible for web forms. So, what about using reportviewer on Form side. In this case, do I need to return byte array or reportviewer from ServiceLayer (normally I return byte array but if I have to, is it ok to return q ReportViewer fromk Service Layer to Application Layer (WinForm)?
BR
Sergey Alexandrovich Kryukov 12-Jul-11 15:03pm    
Are you talking about file system of server's side? You can create your own navigator in this case, but this is very serious from the security stand point.
--SA
H.Johnson 13-Jul-11 17:42pm    
I meant that I have a click once application and the User Interface is a Winform. On the other hand, there ia a Web Service used for to accept request from winform side. The Web Service is on our server at local intranet.
To add to what SA said, ultimately, it's trivial to create your own dialog, and it sounds like you want to create a dialog, asking the user if they want to open or save the file. The browser dialog does this first, then shows a save dialog if needed.
 
Share this answer
 
Comments
Alexandru Ghiondea 7-Jul-11 21:07pm    
I would add that you have to save the file to disk anyway before you open it.

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