【问题标题】:how to write an code for upload a file in .net using C# and SQL for windows application如何使用 Windows 应用程序的 C# 和 SQL 编写用于在 .net 中上传文件的代码
【发布时间】:2015-10-12 05:08:20
【问题描述】:

在Windows应用程序中上传文件后如何访问它

【问题讨论】:

    标签: sql c#-4.0


    【解决方案1】:

    用户界面:

    <form id="form1" runat="server">
    <asp:FileUpload id="FileUploadControl" runat="server" />
    <asp:Button runat="server" id="UploadButton" text="Upload" onclick="UploadButton_Click" />
    <br /><br />
    <asp:Label runat="server" id="StatusLabel" text="Upload status: " />
    

    后面的代码:

      protected void UploadButton_Click(object sender, EventArgs e)
     {
    if(FileUploadControl.HasFile)
    {
        try
        {
            string filename = Path.GetFileName(FileUploadControl.FileName);
            FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
            StatusLabel.Text = "Upload status: File uploaded!";
        }
        catch(Exception ex)
        {
            StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
        }
    }
    

    }

    你可以点击下面的链接

    http://asp.net-tutorials.com/controls/file-upload-control/

    【讨论】:

    • OP 提到了 windows 应用程序而不是 web。
    猜你喜欢
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-27
    相关资源
    最近更新 更多