我必须使用功能上传文件 [英] I have to upload a file using function

查看:43
本文介绍了我必须使用功能上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<pre lang="cs">using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.IO;<br />
public partial class _Default : System.Web.UI.Page<br />
{<br />
    protected void Page_Load(object sender, EventArgs e)<br />
    {<br />
<br />
    }<br />
    protected void btnsubmit_Click(object sender, EventArgs e)<br />
    {<br />
<br />
        string FilePath = "";<br />
        string[] a = new string[1];<br />
        string FileName = "";<br />
<br />
        if (filupload1.FileName.Length > 0)<br />
        {<br />
            FileName = filupload1.FileName;<br />
            FilePath = Server.MapPath(@"~\Files");<br />
            try<br />
            {<br />
                filupload1.SaveAs(FilePath + @"\" + FileName);<br />
            }<br />
            catch { File.Delete(FilePath + @"\" + FileName);<br />
            filupload1.SaveAs(FilePath + @"\" + FileName);<br />
            }<br />
<br />
            lbldisplay.Text = "Uploaded successfully";<br />
         }</pre><br />

<pre lang="xml"><%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td><asp:Label id="lblselectfile" Text="Select File" runat="server"></asp:Label></td>
                <td><asp:FileUpload ID="filupload1"  runat="server" /></td>
            </tr>
            <tr>
                <td><asp:Button ID="btnsubmit" Text="Submit" runat="server"
                        onclick="btnsubmit_Click" /></td>
                        <td><asp:Label ID="lbldisplay" runat="server"></asp:Label></td>
            </tr>
            <tr>
                           </tr>
        </table>
    </div>
    </form>
</body>
</html>


推荐答案

是什么问题?我的编码风格不同.我制作了一个用于处理文件的类文件.通常,我实例化该类的对象并调用方法.如果您需要该课程,我可以提供课程代码.
Ya what''s the problem? My coding style is different. I made a class file for file handling. Normally I instantiate object of that class and call methods. If you need that class, I can put the class''s code.


这篇关于我必须使用功能上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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