如何使用Pdf文件的“打开/保存/取消"对话框? [英] How to use Open/Save/Cancel Dialog for a Pdf file?

查看:186
本文介绍了如何使用Pdf文件的“打开/保存/取消"对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我已经在WebService层上呈现了一个报告,并将其作为字节数组发送到WinForm Application层.在将阵列放在应用程序层上之后,我想显示一个打开/保存/取消"对话框,就像许多网站使用并允许用户打开或保存此报告一样.当我想在WebService层上创建报表时,我认为我不容易使用ReportViewver.可以吗因此,如何显示一个打开/保存/取消"对话框以使用户能够选择此选项?
BR

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();
    }
}

推荐答案

该代码如何:

How about this code:

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



Alex



Alex


没有可使用的组合打开/保存"对话框.只需查看所使用的库的帮助MSDN页面(已标记Windows.Forms),即可看到每个库中都有两个单独的类:SaveDialogOpenDialog.永远都不需要合并行为,因此使用两个单独的类就可以了.

此外,文件对话框与文件I/O无关.它们仅提供要存储或加载的文件的文件名.因此,您无需询问特定于PDF或任何其他类型的文件的任何内容;这无关紧要.您只能设置FileMask以在浏览时正确过滤文件.

就这样.

查看全部六个班级:
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
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


要添加到SA所说的内容,最终,创建您自己的对话框很简单,听起来您想创建一个对话框,询问用户是否要打开或保存文件.浏览器对话框首先执行此操作,然后根据需要显示一个保存对话框.
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.


这篇关于如何使用Pdf文件的“打开/保存/取消"对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆