本文介绍了我必须使用功能上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<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>
推荐答案
这篇关于我必须使用功能上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!