C# windows 应用程序中的文件上传

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13377932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:22:04  来源:igfitidea点击:

File Upload in C# windows Application

c#winforms

提问by Arianule

In my C# Windows application I want to upload a pdf file but in my toolbox I cannot find a FileUpload control.

在我的 C# Windows 应用程序中,我想上传一个 pdf 文件,但在我的工具箱中我找不到 FileUpload 控件。

How can I go about and uploading a pdf file in a C# windows application.?

如何在 C# windows 应用程序中上传 pdf 文件。?

regards

问候

采纳答案by Sylca

After you put a OpenFileDialog control on your form, let's say that you click a button and:

在窗体上放置 OpenFileDialog 控件后,假设您单击一个按钮并:

    private void button1_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK) // Test result.
            {
            //Do whatever you want
            //openFileDialog1.FileName .....
            }
        }

it goes something like this :-)

它是这样的:-)

回答by Legoless

You can use OpenFileDialogto get the filename of the file you need and then .NET Fileobject to read data from the file. You might need a control being able to display a PDF file. Please read the following:

您可以使用OpenFileDialog获取所需文件的文件名,然后使用 .NET File对象从文件中读取数据。您可能需要一个能够显示 PDF 文件的控件。请阅读以下内容:

Viewing PDF in Windows forms using C#

使用 C# 在 Windows 表单中查看 PDF